Skip to content

Commit b58efd1

Browse files
authored
More examples and auto ID (#187)
* More examples and auto id * Fix test * woops
1 parent 8e566f1 commit b58efd1

File tree

18 files changed

+492
-3
lines changed

18 files changed

+492
-3
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22

3-
members = [
3+
members = [ "examples/demo",
44
"examples/routing-plugin", "integration/rust",
55
"pgdog",
66
"pgdog-plugin",

examples/demo/1_setup.sql

Whitespace-only changes.

examples/demo/2_schema.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE kv (
2+
id BIGINT PRIMARY KEY,
3+
data JSONB,
4+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW ()
5+
);

examples/demo/3_ids.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* pgdog_shard: 0 */
2+
SELECT
3+
pgdog.install_next_id ('public', 'kv', 'id', 3, 0);
4+
5+
/* pgdog_shard: 1 */
6+
SELECT
7+
pgdog.install_next_id ('public', 'kv', 'id', 3, 1);
8+
9+
/* pgdog_shard: 2 */
10+
SELECT
11+
pgdog.install_next_id ('public', 'kv', 'id', 3, 2);

examples/demo/3_kv.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE kv (
2+
id BIGINT PRIMARY KEY,
3+
data JSONB,
4+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW ()
5+
);

examples/demo/4_kv_ops.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
INSERT INTO
2+
kv (data)
3+
VALUES
4+
'{"fruit": "orange"}' RETURNING *;
5+
6+
7+
SELECT * FROM kv WHERE id = 1;
8+
9+
SELECT * FROM kv;
10+
11+
SELECT * FROM kv ORDER BY id;
12+
13+
SELECT data->>'fruit', count(*) FROM kv GROUP BY 1 ORDER BY 2 DESC;

examples/demo/5_joins.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CREATE TABLE kv_meta (
2+
kv_id BIGINT NOT NULL REFERENCES kv(id),
3+
created_by VARCHAR NOT NULL,
4+
admin BOOL NOT NULL DEFAULT false
5+
);
6+
7+
INSERT INTO kv_meta (data_id, created_by) VALUES (1, 'lev') RETURNING *;
8+
INSERT INTO kv_meta (data_id, created_by) VALUES (1, 'bob') RETURNING *;
9+
INSERT INTO kv_meta (data_id, created_by) VALUES (1, 'alice') RETURNING *;
10+
11+
12+
SELECT * FROM data INNER JOIN kv_meta
13+
ON data.id = kv_meta.data_id
14+
WHERE data_id = 1;
15+
16+
SELECT * FROM data INNER JOIN kv_meta
17+
ON data.id = kv_meta.data_id;

examples/demo/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "demo"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
colored = "3.0"
8+
tokio = { version = "1", features = ["full"]}
9+
which = "7"

examples/demo/docker-compose.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
db_0:
3+
image: postgres:16
4+
environment:
5+
POSTGRES_PASSWORD: postgres
6+
ports:
7+
- 6000:5432
8+
volumes:
9+
- shard_0:/var/lib/postgresql/data
10+
db_1:
11+
image: postgres:16
12+
environment:
13+
POSTGRES_PASSWORD: postgres
14+
ports:
15+
- 6001:5432
16+
volumes:
17+
- shard_1:/var/lib/postgresql/data
18+
db_2:
19+
image: postgres:16
20+
environment:
21+
POSTGRES_PASSWORD: postgres
22+
ports:
23+
- 6002:5432
24+
volumes:
25+
- shard_2:/var/lib/postgresql/data
26+
27+
volumes:
28+
shard_0:
29+
shard_1:
30+
shard_2:

examples/demo/pgbench.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
select
2+
1;

examples/demo/pgdog.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# PgDog configuration.
3+
#
4+
5+
[general]
6+
openmetrics_port = 9090
7+
8+
[[databases]]
9+
name = "postgres"
10+
host = "127.0.0.1"
11+
port = 6000
12+
shard = 0
13+
14+
[[databases]]
15+
name = "postgres"
16+
host = "127.0.0.1"
17+
port = 6001
18+
shard = 1
19+
20+
[[databases]]
21+
name = "postgres"
22+
host = "127.0.0.1"
23+
port = 6002
24+
shard = 2
25+
26+
[[sharded_tables]]
27+
name = "kv"
28+
column = "id"
29+
data_type = "bigint"
30+
database = "postgres"
31+
32+
[[sharded_tables]]
33+
column = "kv_id"
34+
data_type = "bigint"
35+
database = "postgres"

examples/demo/reset.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DROP TABLE IF EXISTS kv CASCADE;
2+
DROP TABLE IF EXISTS kv_meta CASCADE;
3+
4+
DROP SCHEMA IF EXISTS pgdog CASCADE;

0 commit comments

Comments
 (0)