Skip to content

Commit 4233901

Browse files
authored
examples: Add the jets and booktest examples (#237)
Move the end-to-end test into its own package: internal/endtoend Add a new package for creating temporary PostgreSQL schemas: internal/sqltest
1 parent 4ea3e27 commit 4233901

File tree

22 files changed

+1278
-165
lines changed

22 files changed

+1278
-165
lines changed

examples/booktest/mysql/db.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/booktest/mysql/models.go

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/booktest/mysql/query.sql

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* name: GetAuthor :one */
2+
SELECT * FROM authors
3+
WHERE author_id = ?;
4+
5+
/* name: GetBook :one */
6+
SELECT * FROM books
7+
WHERE book_id = ?;
8+
9+
/* name: DeleteBook :exec */
10+
DELETE FROM books
11+
WHERE book_id = ?;
12+
13+
/* name: BooksByTitleYear :many */
14+
SELECT * FROM books
15+
WHERE title = ? AND yr = ?;
16+
17+
/* name: CreateAuthor :exec */
18+
INSERT INTO authors (name) VALUES (?);
19+
20+
/* name: CreateBook :exec */
21+
INSERT INTO books (
22+
author_id,
23+
isbn,
24+
booktype,
25+
title,
26+
yr,
27+
available,
28+
tags
29+
) VALUES (
30+
?,
31+
?,
32+
?,
33+
?,
34+
?,
35+
?,
36+
?
37+
);
38+
39+
/* name: UpdateBook :exec */
40+
UPDATE books
41+
SET title = ?, tags = ?
42+
WHERE book_id = ?;
43+
44+
/* name: UpdateBookISBN :exec */
45+
UPDATE books
46+
SET title = ?, tags = ?, isbn = ?
47+
WHERE book_id = ?;
48+

examples/booktest/mysql/query.sql.go

Lines changed: 189 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/booktest/mysql/schema.sql

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
SET FOREIGN_KEY_CHECKS=0;
2+
DROP TABLE IF EXISTS authors;
3+
DROP TABLE IF EXISTS books;
4+
-- DROP FUNCTION IF EXISTS say_hello;
5+
SET FOREIGN_KEY_CHECKS=1;
6+
7+
CREATE TABLE authors (
8+
author_id integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
9+
name text NOT NULL DEFAULT ''
10+
) ENGINE=InnoDB;
11+
12+
CREATE INDEX authors_name_idx ON authors(name(255));
13+
14+
CREATE TABLE books (
15+
book_id integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
16+
author_id integer NOT NULL,
17+
isbn varchar(255) NOT NULL DEFAULT '' UNIQUE,
18+
book_type ENUM('FICTION', 'NONFICTION') NOT NULL DEFAULT 'FICTION',
19+
title text NOT NULL DEFAULT '',
20+
yr integer NOT NULL DEFAULT 2000,
21+
available datetime NOT NULL DEFAULT NOW(),
22+
tags text NOT NULL DEFAULT ''
23+
-- CONSTRAINT FOREIGN KEY (author_id) REFERENCES authors(author_id)
24+
) ENGINE=InnoDB;
25+
26+
CREATE INDEX books_title_idx ON books(title(255), yr);
27+
28+
/*
29+
CREATE FUNCTION say_hello(s text) RETURNS text
30+
DETERMINISTIC
31+
RETURN CONCAT('hello ', s);
32+
*/

examples/booktest/postgresql/db.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)