feat: add outbox
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
3648dce8e8
commit
e774529b04
@ -37,6 +37,6 @@ genco = {version = "0.17.6"}
|
|||||||
walkdir = {version = "2.4.0"}
|
walkdir = {version = "2.4.0"}
|
||||||
regex = {version = "1.9.5"}
|
regex = {version = "1.9.5"}
|
||||||
inquire = {version = "0.6.2"}
|
inquire = {version = "0.6.2"}
|
||||||
sqlx = {version = "0.7.2", default-features = false, features = ["migrate", "macros", "postgres", "runtime-tokio", "tls-rustls", "chrono" ]}
|
sqlx = {version = "0.7.2", default-features = false, features = ["migrate", "macros", "postgres", "runtime-tokio", "tls-rustls", "chrono", "json" ]}
|
||||||
|
|
||||||
pretty_assertions = "1.4.0"
|
pretty_assertions = "1.4.0"
|
5
crates/crunch-postgres/build.rs
Normal file
5
crates/crunch-postgres/build.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// generated by `sqlx migrate build-script`
|
||||||
|
fn main() {
|
||||||
|
// trigger recompilation when a new migration is added
|
||||||
|
println!("cargo:rerun-if-changed=migrations");
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
-- Add migration script here
|
||||||
|
CREATE TABLE outbox (
|
||||||
|
id UUID NOT NULL,
|
||||||
|
metadata JSONB NOT NULL,
|
||||||
|
content BYTEA NOT NULL,
|
||||||
|
inserted_time TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
state VARCHAR NOT NULL,
|
||||||
|
);
|
@ -1 +1,33 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
|
use crunch_traits::{errors::PersistenceError, EventInfo};
|
||||||
|
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};
|
||||||
|
|
||||||
|
pub struct PostgresPersistence {
|
||||||
|
pool: Pool<Postgres>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostgresPersistence {
|
||||||
|
pub async fn new(dsn: &str) -> anyhow::Result<Self> {
|
||||||
|
let pool = PgPoolOptions::new().max_connections(5).connect(dsn).await?;
|
||||||
|
|
||||||
|
sqlx::migrate!().run(&pool).await?;
|
||||||
|
|
||||||
|
Ok(Self { pool })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl crunch_traits::Persistence for PostgresPersistence {
|
||||||
|
async fn insert(&self, event_info: &EventInfo, content: Vec<u8>) -> anyhow::Result<()> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
async fn next(&self) -> Option<String> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
async fn get(&self, event_id: &str) -> Result<Option<(EventInfo, Vec<u8>)>, PersistenceError> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
async fn update_published(&self, event_id: &str) -> Result<(), PersistenceError> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user