mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-11-28 22:24:49 +03:00
example PostgreSQL: switch from sh to SQL.
This commit is contained in:
parent
01acb337f1
commit
fe6da06983
@ -1,61 +0,0 @@
|
||||
#! /bin/sh
|
||||
|
||||
create_user_table='
|
||||
CREATE TABLE EXAMPLE1.user (
|
||||
id integer NOT NULL,
|
||||
name VARCHAR(128),
|
||||
|
||||
PRIMARY KEY(id)
|
||||
)
|
||||
'
|
||||
|
||||
create_group_table='
|
||||
CREATE TABLE EXAMPLE1.group (
|
||||
id integer NOT NULL,
|
||||
name VARCHAR(128),
|
||||
|
||||
PRIMARY KEY(id)
|
||||
)
|
||||
'
|
||||
|
||||
create_membership_table='
|
||||
CREATE TABLE EXAMPLE1.membership (
|
||||
user_id integer NOT NULL,
|
||||
group_id integer NOT NULL
|
||||
)
|
||||
'
|
||||
|
||||
set -x
|
||||
|
||||
psql -c "CREATE SCHEMA EXAMPLE1" testdb
|
||||
psql -c "$create_user_table" testdb
|
||||
psql -c "$create_group_table" testdb
|
||||
psql -c "$create_membership_table" testdb
|
||||
|
||||
insertUser () {
|
||||
psql -c "INSERT INTO EXAMPLE1.user (id, name) VALUES ($1, '$2')" testdb
|
||||
}
|
||||
|
||||
insertGroup () {
|
||||
psql -c "INSERT INTO EXAMPLE1.group (id, name) VALUES ($1, '$2')" testdb
|
||||
}
|
||||
|
||||
insertMembership() {
|
||||
psql -c "INSERT INTO EXAMPLE1.membership (user_id, group_id) VALUES ($1, $2)" testdb
|
||||
}
|
||||
|
||||
insertUser 1 'Kei Hibino'
|
||||
insertUser 2 'Kazu Yamamoto'
|
||||
insertUser 3 'Shouhei Murayama'
|
||||
insertUser 255 '<New-comer>'
|
||||
|
||||
insertGroup 1 'Haskell'
|
||||
insertGroup 2 'C++'
|
||||
insertGroup 3 'Java'
|
||||
|
||||
insertMembership 1 1
|
||||
insertMembership 2 1
|
||||
insertMembership 3 1
|
||||
|
||||
insertMembership 1 3
|
||||
insertMembership 3 3
|
36
examples/HDBC/PostgreSQL/example/1/create.sql
Normal file
36
examples/HDBC/PostgreSQL/example/1/create.sql
Normal file
@ -0,0 +1,36 @@
|
||||
CREATE SCHEMA EXAMPLE1;
|
||||
|
||||
CREATE TABLE EXAMPLE1.user (
|
||||
id integer NOT NULL,
|
||||
name VARCHAR(128),
|
||||
|
||||
PRIMARY KEY(id)
|
||||
);
|
||||
|
||||
CREATE TABLE EXAMPLE1.group (
|
||||
id integer NOT NULL,
|
||||
name VARCHAR(128),
|
||||
|
||||
PRIMARY KEY(id)
|
||||
);
|
||||
|
||||
CREATE TABLE EXAMPLE1.membership (
|
||||
user_id integer NOT NULL,
|
||||
group_id integer NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO EXAMPLE1.user (id, name) VALUES (1, 'Kei Hibino');
|
||||
INSERT INTO EXAMPLE1.user (id, name) VALUES (2, 'Kazu Yamamoto');
|
||||
INSERT INTO EXAMPLE1.user (id, name) VALUES (3, 'Shouhei Murayama');
|
||||
INSERT INTO EXAMPLE1.user (id, name) VALUES (255, '<New-comer>');
|
||||
|
||||
INSERT INTO EXAMPLE1.group (id, name) VALUES (1, 'Haskell');
|
||||
INSERT INTO EXAMPLE1.group (id, name) VALUES (2, 'C++');
|
||||
INSERT INTO EXAMPLE1.group (id, name) VALUES (3, 'Java');
|
||||
|
||||
INSERT INTO EXAMPLE1.membership (user_id, group_id) VALUES (1, 1);
|
||||
INSERT INTO EXAMPLE1.membership (user_id, group_id) VALUES (2, 1);
|
||||
INSERT INTO EXAMPLE1.membership (user_id, group_id) VALUES (3, 1);
|
||||
|
||||
INSERT INTO EXAMPLE1.membership (user_id, group_id) VALUES (1, 3);
|
||||
INSERT INTO EXAMPLE1.membership (user_id, group_id) VALUES (3, 3);
|
@ -1,8 +0,0 @@
|
||||
#! /bin/sh
|
||||
|
||||
set -x
|
||||
|
||||
psql -c "DROP TABLE EXAMPLE1.membership" testdb
|
||||
psql -c "DROP TABLE EXAMPLE1.group" testdb
|
||||
psql -c "DROP TABLE EXAMPLE1.user" testdb
|
||||
psql -c "DROP SCHEMA IF EXISTS EXAMPLE1" testdb
|
4
examples/HDBC/PostgreSQL/example/1/drop.sql
Normal file
4
examples/HDBC/PostgreSQL/example/1/drop.sql
Normal file
@ -0,0 +1,4 @@
|
||||
DROP TABLE EXAMPLE1.membership;
|
||||
DROP TABLE EXAMPLE1.group;
|
||||
DROP TABLE EXAMPLE1.user;
|
||||
DROP SCHEMA IF EXISTS EXAMPLE1;
|
Loading…
Reference in New Issue
Block a user