Skip to content

Instantly share code, notes, and snippets.

@rtt
Last active February 4, 2021 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtt/5de1eaea3a779aaa0c67af119dcd1b93 to your computer and use it in GitHub Desktop.
Save rtt/5de1eaea3a779aaa0c67af119dcd1b93 to your computer and use it in GitHub Desktop.
foo bar baz
-- table a:
create table a (
uid text primary key,
title text not null
);
create table u (
uid text primary key,
name text not null,
email text not null --unique
);
create table b (
uid text primary key,
a_uid text references a(uid),
u_uid text references u(uid),
amount integer not null
);
-- make As
insert into a (uid, title) values ('a_1', 'a');
insert into a (uid, title) values ('a_2', 'a');
-- make Us
insert into u (uid, name, email) values ('u_1', 'darren');
insert into u (uid, name, email) values ('u_2', 'kim');
-- make Bs
insert into b (uid, a_uid, u_uid, amount) values ('a_1', 'u_1', 100);
insert into b (uid, a_uid, u_uid, amount) values ('a_1', 'u_2', 150);
insert into b (uid, a_uid, u_uid, amount) values ('a_1', 'u_1', 200);
insert into b (uid, a_uid, u_uid, amount) values ('a_2', 'u_1', 100);
insert into b (uid, a_uid, u_uid, amount) values ('a_2', 'u_2', 150);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment