mirror of https://github.com/rocboss/paopao-ce
parent
268350726c
commit
b7dfd7e173
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2023 ROC. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build migration
|
||||||
|
// +build migration
|
||||||
|
|
||||||
|
package ce
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed postgres/schema
|
||||||
|
var Files embed.FS
|
@ -1,56 +0,0 @@
|
|||||||
-- name: GetAuthor :one
|
|
||||||
SELECT * FROM authors
|
|
||||||
WHERE author_id = $1;
|
|
||||||
|
|
||||||
-- name: DeleteBookExecResult :execresult
|
|
||||||
DELETE FROM books
|
|
||||||
WHERE book_id = $1;
|
|
||||||
|
|
||||||
-- name: DeleteBook :batchexec
|
|
||||||
DELETE FROM books
|
|
||||||
WHERE book_id = $1;
|
|
||||||
|
|
||||||
-- name: DeleteBookNamedFunc :batchexec
|
|
||||||
DELETE FROM books
|
|
||||||
WHERE book_id = sqlc.arg(book_id);
|
|
||||||
|
|
||||||
-- name: DeleteBookNamedSign :batchexec
|
|
||||||
DELETE FROM books
|
|
||||||
WHERE book_id = @book_id;
|
|
||||||
|
|
||||||
-- name: BooksByYear :batchmany
|
|
||||||
SELECT * FROM books
|
|
||||||
WHERE year = $1;
|
|
||||||
|
|
||||||
-- name: CreateAuthor :one
|
|
||||||
INSERT INTO authors (name) VALUES ($1)
|
|
||||||
RETURNING *;
|
|
||||||
|
|
||||||
-- name: CreateBook :batchone
|
|
||||||
INSERT INTO books (
|
|
||||||
author_id,
|
|
||||||
isbn,
|
|
||||||
book_type,
|
|
||||||
title,
|
|
||||||
year,
|
|
||||||
available,
|
|
||||||
tags
|
|
||||||
) VALUES (
|
|
||||||
$1,
|
|
||||||
$2,
|
|
||||||
$3,
|
|
||||||
$4,
|
|
||||||
$5,
|
|
||||||
$6,
|
|
||||||
$7
|
|
||||||
)
|
|
||||||
RETURNING *;
|
|
||||||
|
|
||||||
-- name: UpdateBook :batchexec
|
|
||||||
UPDATE books
|
|
||||||
SET title = $1, tags = $2
|
|
||||||
WHERE book_id = $3;
|
|
||||||
|
|
||||||
-- name: GetBiography :batchone
|
|
||||||
SELECT biography FROM authors
|
|
||||||
WHERE author_id = $1;
|
|
@ -1,21 +0,0 @@
|
|||||||
CREATE TABLE authors (
|
|
||||||
author_id SERIAL PRIMARY KEY,
|
|
||||||
name text NOT NULL DEFAULT '',
|
|
||||||
biography JSONB
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TYPE book_type AS ENUM (
|
|
||||||
'FICTION',
|
|
||||||
'NONFICTION'
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE books (
|
|
||||||
book_id SERIAL PRIMARY KEY,
|
|
||||||
author_id integer NOT NULL REFERENCES authors(author_id),
|
|
||||||
isbn text NOT NULL DEFAULT '' UNIQUE,
|
|
||||||
book_type book_type NOT NULL DEFAULT 'FICTION',
|
|
||||||
title text NOT NULL DEFAULT '',
|
|
||||||
year integer NOT NULL DEFAULT 2000,
|
|
||||||
available timestamp with time zone NOT NULL DEFAULT 'NOW()',
|
|
||||||
tags varchar[] NOT NULL DEFAULT '{}'
|
|
||||||
);
|
|
Loading…
Reference in new issue