Skip to content

Commit 672264c

Browse files
committed
Remove generics on InsertIntoCrud
1 parent 1a68ed6 commit 672264c

File tree

4 files changed

+18
-31
lines changed

4 files changed

+18
-31
lines changed

crates/core/src/schema/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn register(db: *mut sqlite::sqlite3, state: Rc<DatabaseState>) -> Result<()
6666
Some(create_raw_trigger_sqlite),
6767
None,
6868
None,
69-
Some(DatabaseState::destroy_rc),
69+
None,
7070
)?;
7171
}
7272
Ok(())

crates/core/src/schema/raw_table.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,13 @@ pub fn generate_raw_table_trigger(
108108
buffer.insert_into_powersync_crud(InsertIntoCrud {
109109
op: write,
110110
table: &as_schema_table,
111-
id_expr: from_fn(|f| {
112-
if write == WriteType::Delete {
113-
f.write_str("OLD.")
114-
} else {
115-
f.write_str("NEW.")
116-
}?;
117-
f.write_str(".id")
118-
}),
111+
id_expr: if write == WriteType::Delete {
112+
"OLD.id"
113+
} else {
114+
"NEW.id"
115+
},
119116
type_name: &table.name,
120-
data: Some(from_fn(|f| {
117+
data: Some(&from_fn(|f| {
121118
match write {
122119
WriteType::Insert => {}
123120
WriteType::Update => todo!(),

crates/core/src/utils/sql_buffer.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,10 @@ impl SqlBuffer {
108108
}
109109

110110
/// Writes an `INSERT INTO powersync_crud` statement.
111-
pub fn insert_into_powersync_crud<Id, Data, Metadata>(
111+
pub fn insert_into_powersync_crud(
112112
&mut self,
113-
insert: InsertIntoCrud<Id, Data, Metadata>,
114-
) -> Result<(), PowerSyncError>
115-
where
116-
Id: Display,
117-
Data: Display,
118-
Metadata: Display,
119-
{
113+
insert: InsertIntoCrud,
114+
) -> Result<(), PowerSyncError> {
120115
let old_values = if insert.op == WriteType::Insert {
121116
// Inserts don't have previous values we'd have to track.
122117
None
@@ -306,18 +301,13 @@ impl<'a> CommaSeparated<'a> {
306301
}
307302
}
308303

309-
pub struct InsertIntoCrud<'a, Id, Data, Metadata>
310-
where
311-
Id: Display,
312-
Data: Display,
313-
Metadata: Display,
314-
{
304+
pub struct InsertIntoCrud<'a> {
315305
pub op: WriteType,
316-
pub id_expr: Id,
306+
pub id_expr: &'a str,
317307
pub type_name: &'a str,
318-
pub data: Option<Data>,
308+
pub data: Option<&'a dyn Display>,
319309
pub table: &'a SchemaTable<'a>,
320-
pub metadata: Option<Metadata>,
310+
pub metadata: Option<&'a str>,
321311
}
322312

323313
#[derive(Clone, Copy, PartialEq)]

crates/core/src/views.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn powersync_trigger_delete_sql(table_info: &Table) -> Result<String, PowerS
8585
table: &as_schema_table,
8686
id_expr: "OLD.id",
8787
type_name: name,
88-
data: None::<&'static str>,
88+
data: None,
8989
metadata: None::<&'static str>,
9090
})?;
9191

@@ -106,7 +106,7 @@ pub fn powersync_trigger_delete_sql(table_info: &Table) -> Result<String, PowerS
106106
table: &as_schema_table,
107107
id_expr: "OLD.id",
108108
type_name: name,
109-
data: None::<&'static str>,
109+
data: None,
110110
metadata: Some("NEW._metadata"),
111111
})?;
112112
}
@@ -151,7 +151,7 @@ pub fn powersync_trigger_insert_sql(table_info: &Table) -> Result<String, PowerS
151151
id_expr: "NEW.id",
152152
table: &as_schema_table,
153153
type_name: name,
154-
data: Some(from_fn(|f| {
154+
data: Some(&from_fn(|f| {
155155
write!(f, "json(powersync_diff('{{}}', {:}))", json_fragment)
156156
})),
157157
metadata: if table_info.options.flags.include_metadata() {
@@ -208,7 +208,7 @@ pub fn powersync_trigger_update_sql(table_info: &Table) -> Result<String, PowerS
208208
id_expr: "NEW.id",
209209
table: &as_schema_table,
210210
type_name: name,
211-
data: Some(from_fn(|f| {
211+
data: Some(&from_fn(|f| {
212212
write!(
213213
f,
214214
"json(powersync_diff({json_fragment_old}, {json_fragment_new}))"

0 commit comments

Comments
 (0)