···11+use diesel_async::AsyncPgConnection;
22+use diesel_async::pooled_connection::AsyncDieselConnectionManager;
33+use diesel_async::pooled_connection::deadpool::Pool;
14use tokio::sync::mpsc::Sender;
2536mod config;
···10131114 let conf = config::load_config()?;
12151616+ let db_mgr = AsyncDieselConnectionManager::<AsyncPgConnection>::new(&conf.database_url);
1717+ let pool = Pool::builder(db_mgr).build()?;
1818+1319 let (tx, rx) = tokio::sync::mpsc::channel::<firehose::FirehoseEvent>(64);
14201521 let relay_firehose = firehose::FirehoseConsumer::new_relay(&conf.relay_source, None).await?;
16221723 let firehose_handle = tokio::spawn(relay_consumer(relay_firehose, tx));
1818- let indexer_handle = tokio::spawn(indexer::relay_indexer(rx));
2424+ let indexer_handle = tokio::spawn(indexer::relay_indexer(pool.clone(), rx));
19252026 let (firehose_res, indexer_res) = tokio::try_join!{
2127 firehose_handle,
+9
diesel.toml
···11+# For documentation on how to configure this file,
22+# see https://diesel.rs/guides/configuring-diesel-cli
33+44+[print_schema]
55+file = "parakeet-db/src/schema.rs"
66+custom_type_derives = ["diesel::query_builder::QueryId"]
77+88+[migrations_directory]
99+dir = "migrations"
···11+-- This file was automatically created by Diesel to setup helper functions
22+-- and other internal bookkeeping. This file is safe to edit, any future
33+-- changes will be added to existing projects as new migrations.
44+55+DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
66+DROP FUNCTION IF EXISTS diesel_set_updated_at();
···11+-- This file was automatically created by Diesel to setup helper functions
22+-- and other internal bookkeeping. This file is safe to edit, any future
33+-- changes will be added to existing projects as new migrations.
44+55+66+77+88+-- Sets up a trigger for the given table to automatically set a column called
99+-- `updated_at` whenever the row is modified (unless `updated_at` was included
1010+-- in the modified columns)
1111+--
1212+-- # Example
1313+--
1414+-- ```sql
1515+-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
1616+--
1717+-- SELECT diesel_manage_updated_at('users');
1818+-- ```
1919+CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
2020+BEGIN
2121+ EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
2222+ FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
2323+END;
2424+$$ LANGUAGE plpgsql;
2525+2626+CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
2727+BEGIN
2828+ IF (
2929+ NEW IS DISTINCT FROM OLD AND
3030+ NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
3131+ ) THEN
3232+ NEW.updated_at := current_timestamp;
3333+ END IF;
3434+ RETURN NEW;
3535+END;
3636+$$ LANGUAGE plpgsql;
+9
parakeet-db/Cargo.toml
···11+[package]
22+name = "parakeet-db"
33+version = "0.1.0"
44+edition = "2021"
55+66+[dependencies]
77+chrono = { version = "0.4.39", features = ["serde"] }
88+diesel = { version = "2.2.6", features = ["chrono", "serde_json"] }
99+serde_json = "1.0.134"