-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from sine-fdn/postgres-integration
SQL Integration Example
- Loading branch information
Showing
22 changed files
with
1,181 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const ROWS_0: usize = PARTY_0::ROWS; | ||
const ROWS_1: usize = PARTY_1::ROWS; | ||
const ROWS_RESULT: usize = max(PARTY_0::ROWS, PARTY_1::ROWS); | ||
const STR_LEN: usize = max(PARTY_0::STR_LEN, PARTY_1::STR_LEN); | ||
|
||
enum InsuranceStatus { | ||
Foo, | ||
Bar, | ||
FooBar, | ||
} | ||
|
||
pub fn main( | ||
residents: [(i32, [u8; STR_LEN], i32); ROWS_0], | ||
insurance: [(i32, [u8; STR_LEN], InsuranceStatus); ROWS_1], | ||
) -> [[u8; STR_LEN]; ROWS_RESULT] { | ||
let mut result = [[0u8; STR_LEN]; ROWS_RESULT]; | ||
let mut i = 0usize; | ||
for resident in residents { | ||
for insurance in insurance { | ||
let (_, name0, age) = resident; | ||
let (_, name1, insurance_status) = insurance; | ||
if name0 == name1 && age > 65i32 { | ||
match insurance_status { | ||
InsuranceStatus::Foo => { | ||
result[i] = name0; | ||
i = i + 1usize; | ||
} | ||
InsuranceStatus::Bar => { | ||
result[i] = name0; | ||
i = i + 1usize; | ||
} | ||
_ => {} | ||
} | ||
} | ||
} | ||
} | ||
result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[package] | ||
name = "parlay-sql-integration" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
anyhow = "1.0.79" | ||
axum = "0.7.4" | ||
blake3 = "1.5.1" | ||
clap = { version = "4.4.18", features = ["derive"] } | ||
handlebars = "5.1.2" | ||
parlay = { path = "../../", version = "0.1.0" } | ||
reqwest = { version = "0.11.23", features = ["json"] } | ||
serde = "1.0.197" | ||
serde_json = "1.0.115" | ||
sqlx = { version = "0.7.4", features = [ | ||
"runtime-tokio", | ||
"any", | ||
"postgres", | ||
"mysql", | ||
"sqlite", | ||
] } | ||
tokio = { version = "1.35.1", features = ["macros", "rt", "rt-multi-thread"] } | ||
tower-http = { version = "0.5.1", features = ["fs", "trace"] } | ||
tracing = "0.1.40" | ||
tracing-subscriber = "0.3.18" | ||
url = { version = "2.5.0", features = ["serde"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
version: "3.9" | ||
services: | ||
db0: | ||
image: postgres:16.2 | ||
restart: always | ||
shm_size: 128mb | ||
volumes: | ||
- ./seeds/db0:/docker-entrypoint-initdb.d | ||
ports: | ||
- 5550:5432 | ||
environment: | ||
POSTGRES_PASSWORD: test | ||
|
||
db1: | ||
image: mysql:8.4 | ||
restart: always | ||
shm_size: 128mb | ||
volumes: | ||
- ./seeds/db1:/docker-entrypoint-initdb.d | ||
- ./seeds/db1/insurance.csv:/var/lib/mysql-files/insurance.csv | ||
ports: | ||
- 5551:3306 | ||
environment: | ||
MYSQL_ROOT_PASSWORD: test | ||
|
||
db_out: | ||
image: postgres:16.2 | ||
restart: always | ||
shm_size: 128mb | ||
volumes: | ||
- ./seeds/db_out:/docker-entrypoint-initdb.d | ||
ports: | ||
- 5555:5432 | ||
environment: | ||
POSTGRES_PASSWORD: test | ||
|
||
adminer: | ||
image: adminer | ||
restart: always | ||
ports: | ||
- 8080:8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"accepted": [ | ||
{ | ||
"participants": [ | ||
"http://localhost:8000", | ||
"http://localhost:8001", | ||
"http://localhost:8002" | ||
], | ||
"program": ".example.garble.rs", | ||
"leader": 0, | ||
"party": 0, | ||
"input": "SELECT id, name, age FROM residents", | ||
"input_db": "postgres://postgres:test@localhost:5550/postgres", | ||
"setup": "TRUNCATE results", | ||
"output": "INSERT INTO results (name) VALUES ($1)", | ||
"output_db": "postgres://postgres:test@localhost:5555/postgres", | ||
"constants": { | ||
"ROWS": { | ||
"query": "SELECT COUNT(id) FROM residents", | ||
"ty": "usize" | ||
}, | ||
"STR_LEN": { | ||
"query": "SELECT MAX(LENGTH(name)) FROM residents", | ||
"ty": "usize" | ||
} | ||
} | ||
}, | ||
{ | ||
"participants": [ | ||
"http://localhost:8000", | ||
"http://localhost:8001", | ||
"http://localhost:8002" | ||
], | ||
"program": "does_not_exist.garble.rs", | ||
"leader": 1, | ||
"party": 0, | ||
"input": "SELECT id, name, age FROM residents", | ||
"input_db": "postgres://postgres:test@localhost:5550/postgres", | ||
"max_rows": 4, | ||
"setup": "TRUNCATE results", | ||
"output": "INSERT INTO results (name) VALUES ($1)", | ||
"output_db": "postgres://postgres:test@localhost:5555/postgres", | ||
"constants": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"accepted": [ | ||
{ | ||
"participants": [ | ||
"http://localhost:8000", | ||
"http://localhost:8001", | ||
"http://localhost:8002" | ||
], | ||
"program": ".example.garble.rs", | ||
"leader": 0, | ||
"party": 1, | ||
"input": "SELECT id, name, status FROM insurance", | ||
"input_db": "mysql://root:test@localhost:5551/test", | ||
"constants": { | ||
"ROWS": { | ||
"query": "SELECT COUNT(id) FROM insurance", | ||
"ty": "usize" | ||
}, | ||
"STR_LEN": { | ||
"query": "SELECT MAX(LENGTH(name)) FROM insurance", | ||
"ty": "usize" | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"accepted": [ | ||
{ | ||
"participants": [ | ||
"http://localhost:8000", | ||
"http://localhost:8001", | ||
"http://localhost:8002", | ||
"http://localhost:8003" | ||
], | ||
"program": ".example.garble.rs", | ||
"leader": 0, | ||
"party": 2, | ||
"input": "65u32" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"accepted": [ | ||
{ | ||
"participants": [ | ||
"http://localhost:8000", | ||
"http://localhost:8001", | ||
"http://localhost:8002" | ||
], | ||
"program": "", | ||
"leader": 0, | ||
"party": 0, | ||
"input": "", | ||
"constants": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CREATE TABLE residents ( | ||
id SERIAL PRIMARY KEY, | ||
name TEXT, | ||
age INT, | ||
address TEXT | ||
); | ||
|
||
COPY residents | ||
FROM '/docker-entrypoint-initdb.d/residents.csv' | ||
DELIMITER ',' | ||
CSV HEADER; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Id,Name,Age,Address | ||
0,"John Doe",22,"Parkstraße 1, 12345 Berlin" | ||
1,"Jane Doe",33,"Schlossallee 2, 12345 Berlin" | ||
2,"Max Doe",66,"Parkstraße 1, 12345 Berlin" | ||
3,"Bob Doe",77,"Schlossallee 2, 12345 Berlin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CREATE DATABASE test; | ||
USE test; | ||
|
||
CREATE TABLE insurance ( | ||
id SERIAL PRIMARY KEY, | ||
name TEXT, | ||
status TEXT, | ||
address TEXT | ||
); | ||
|
||
LOAD DATA INFILE '/var/lib/mysql-files/insurance.csv' | ||
INTO TABLE insurance | ||
FIELDS TERMINATED BY ',' | ||
OPTIONALLY ENCLOSED BY '"' | ||
LINES TERMINATED BY '\n' | ||
IGNORE 1 ROWS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Id,Name,Status,Address | ||
1,"Max Doe","foo","Parkstraße 1, 12345 Berlin" | ||
2,"Bob Doe","bar","Schlossallee 2, 12345 Berlin" | ||
3,"Jane Doe","foobar","Schlossallee 2, 12345 Berlin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE results ( | ||
id SERIAL PRIMARY KEY, | ||
name TEXT | ||
); |
Oops, something went wrong.