Skip to content

Commit

Permalink
feat: enable PostgreSQL engine for sql sink (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Feb 4, 2024
1 parent ab9afa4 commit b0fc5cb
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ tonic = { version = "0.9.2", features = ["tls", "tls-roots"], optional = true }
futures = { version = "0.3.28", optional = true }

# sql
sqlx = { version = "0.7", features = ["runtime-tokio", "tls-native-tls", "any", "sqlite"], optional = true }
sqlx = { version = "0.7", features = ["runtime-tokio", "tls-native-tls", "any", "sqlite", "postgres"], optional = true }

# aws
aws-config = { version = "^1.1", optional = true }
Expand Down
15 changes: 15 additions & 0 deletions examples/postgresql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# PostgreSQL Sink Example

## Steps

1. initialize docker compose

```
docker-compose up
```

2. create required tables

```
psql -h localhost -p 5432 -U postgres -f init.sql
```
17 changes: 17 additions & 0 deletions examples/postgresql/daemon.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[source]
type = "N2N"
peers = ["relays-new.cardano-mainnet.iohk.io:3001"]

[intersect]
type = "Point"
value = [114220807, "01822b10afde3d09bd5e72758857b669ddadcdaad6776a3dc8ee902c3ace1d7e"]

[[filters]]
type = "SplitBlock"

[sink]
type = "SqlDb"
connection = "postgres://postgres:example@localhost:5432/postgres"
apply_template = "INSERT INTO txs (slot, cbor) VALUES ('{{point.slot}}', decode('{{record.hex}}', 'hex'));"
undo_template = "DELETE FROM txs WHERE slot = {{point.slot}}"
reset_template = "DELETE FROM txs WHERE slot > {{point.slot}}"
16 changes: 16 additions & 0 deletions examples/postgresql/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.1"

services:
db:
image: postgres
# image: mumak
restart: always
environment:
POSTGRES_PASSWORD: example
volumes:
- postgres_db:/var/lib/postgresql/data
ports:
- 5432:5432

volumes:
postgres_db:
6 changes: 6 additions & 0 deletions examples/postgresql/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE txs (
slot INTEGER NOT NULL,
cbor BYTEA
);

CREATE INDEX idx_txs_slot ON txs(slot);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b0fc5cb

Please sign in to comment.