Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.

Commit 57568a4

Browse files
author
robreid
committed
Removed sandbox and made use of fset
1 parent 303e00c commit 57568a4

File tree

5 files changed

+29
-51
lines changed

5 files changed

+29
-51
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
.PHONY: test
22

3+
cockroachdb:
4+
docker run -d -p 26257:26257 -p 8080:8080 cockroachdb/cockroach:v2.1.6 start --insecure
5+
36
example:
47
go run main.go -script ./examples/script.sql --driver postgres --conn postgres://root@localhost:26257/sandbox?sslmode=disable
5-
6-
debug:
7-
go run main.go -debug -script ./examples/sandbox.sql --driver postgres --conn postgres://root@localhost:26257/sandbox?sslmode=disable
8-
8+
99
test:
1010
go test ./... -v ;\
1111
go test ./... -cover

examples/create.sql

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
CREATE DATABASE sandbox;
1+
CREATE DATABASE "sandbox";
22

3-
CREATE TABLE sandbox.owner (
4-
id UUID NOT NULL DEFAULT gen_random_uuid(),
5-
name STRING NOT NULL,
6-
date_of_birth TIMESTAMP NOT NULL,
7-
CONSTRAINT "primary" PRIMARY KEY (id ASC)
8-
);
3+
USE "sandbox";
94

10-
CREATE TABLE sandbox.pet (
11-
pid UUID NOT NULL,
12-
id UUID NOT NULL DEFAULT gen_random_uuid(),
13-
name STRING NOT NULL,
14-
owner_name STRING NOT NULL,
15-
owner_date_of_birth TIMESTAMP NOT NULL,
16-
CONSTRAINT "primary" PRIMARY KEY (pid ASC, id ASC),
17-
CONSTRAINT fk_pid_ref_owner FOREIGN KEY (pid) REFERENCES sandbox.owner (id)
18-
) INTERLEAVE IN PARENT sandbox.owner (pid);
5+
CREATE TABLE "owner" (
6+
"id" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
7+
"email" STRING NOT NULL,
8+
"date_of_birth" TIMESTAMP NOT NULL
9+
);
1910

20-
CREATE TABLE sandbox.one (
21-
id int primary key,
22-
name STRING NOT NULL
23-
);
11+
CREATE TABLE "pet" (
12+
"id" UUID DEFAULT gen_random_uuid(),
13+
"pid" UUID NOT NULL,
14+
"name" STRING NOT NULL,
15+
"type" STRING NOT NULL,
16+
PRIMARY KEY ("pid", "id"),
17+
CONSTRAINT type_v1 CHECK ("type" IN ('cat', 'dog'))
18+
) INTERLEAVE IN PARENT "owner" ("pid");

examples/sandbox.sql

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/script.sql

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
-- REPEAT 10
1+
-- REPEAT 1
22
-- NAME owner
3-
insert into "owner" ("name", "date_of_birth") values
4-
{{range $i, $e := ntimes 10 }}
3+
insert into "owner" ("email", "date_of_birth") values
4+
{{range $i, $e := ntimes 5 }}
55
{{if $i}},{{end}}
66
(
77
'{{stringf "%s.%[email protected]" 5 5 "abcdefg" 5 5 "hijklmnop" }}',
88
'{{date "1900-01-01" "now" ""}}'
99
)
1010
{{end}}
11-
returning "id", "name", "date_of_birth";
11+
returning "id";
1212

13-
-- REPEAT 20
13+
-- REPEAT 2
1414
-- NAME pet
15-
insert into "pet" ("pid", "name", "owner_name", "owner_date_of_birth") values
16-
{{range $i, $e := ntimes 10 }}
15+
insert into "pet" ("pid", "name", "type") values
16+
{{range $i, $e := ntimes 5 }}
1717
{{if $i}},{{end}}
1818
(
1919
'{{each "owner" "id" $i}}',
2020
'{{string 10 10 "p-" "abcde"}}',
21-
'{{each "owner" "name" $i}}',
22-
'{{each "owner" "date_of_birth" $i}}'
21+
'{{fset "./examples/types.txt"}}'
2322
)
2423
{{end}};
25-
26-
-- EOF
27-

examples/types.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
type_1
2-
type_2
3-
type_3
1+
cat
2+
dog

0 commit comments

Comments
 (0)