Use BIGSERIAL for postgres keys

Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
Lee Smet 2025-07-31 10:58:38 +02:00
parent 0a8e2040ef
commit 3d66a82967
Signed by untrusted user who does not match committer: lee
GPG Key ID: 72CBFB5FDA7FE025

View File

@ -138,7 +138,7 @@ WHERE table_name = $1
tx.execute( tx.execute(
&format!( &format!(
"CREATE TABLE {} (key SERIAL PRIMARY KEY, value JSONB NOT NULL);", "CREATE TABLE {} (key BIGSERIAL PRIMARY KEY, value JSONB NOT NULL);",
Self::collection_name::<M>(), Self::collection_name::<M>(),
), ),
&[], &[],
@ -191,7 +191,7 @@ where
"SELECT (value) FROM {} WHERE key = $1;", "SELECT (value) FROM {} WHERE key = $1;",
Self::collection_name::<M>() Self::collection_name::<M>()
), ),
&[&id], &[&(id as i64)],
) )
.map_err(Error::from)? .map_err(Error::from)?
.into_iter() .into_iter()
@ -231,14 +231,12 @@ where
eprintln!("insert done"); eprintln!("insert done");
// Get the generated ID // Get the generated ID
let id = row.get::<_, i32>("key") as u32; let id = row.get::<_, i64>("key") as u32;
let mut value = row.get::<_, postgres::types::Json<M>>("value").0; let mut value = row.get::<_, postgres::types::Json<M>>("value").0;
// .map_err(Error::from)?; // .map_err(Error::from)?;
value.base_data_mut().id = id; value.base_data_mut().id = id;
// NOTE: Update the value so the id is set correctly in the value itself // NOTE: Update the value so the id is set correctly in the value itself
// let ser_val = serde_json::to_string(&value).map_err(Error::from)?;
let updated = con let updated = con
.execute( .execute(
&format!( &format!(
@ -247,7 +245,7 @@ where
), ),
&[ &[
&postgres::types::Json(value.clone()), &postgres::types::Json(value.clone()),
&(value.get_id() as i32), &(value.get_id() as i64),
], ],
) )
.map_err(Error::from)?; .map_err(Error::from)?;
@ -266,7 +264,7 @@ where
), ),
&[ &[
&postgres::types::Json(value.clone()), &postgres::types::Json(value.clone()),
&(value.get_id() as i32), &(value.get_id() as i64),
], ],
) )
.map_err(Error::from)?; .map_err(Error::from)?;
@ -307,7 +305,7 @@ where
"DELETE FROM {} WHERE key = $1;", "DELETE FROM {} WHERE key = $1;",
Self::collection_name::<M>() Self::collection_name::<M>()
), ),
&[&id], &[&(id as i64)],
) )
.map_err(Error::from)?; .map_err(Error::from)?;