Skip to content

Commit 8aec1d2

Browse files
Rewrite with Appender API.
1 parent ccebd1c commit 8aec1d2

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

src/duckdb_data.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,13 @@ impl<T: DeferredDataSource> DataSourceDuckDBWriter<T> {
129129
let description = self.data_source.fetch_description();
130130
let description_str = description.source_locator.join(", ");
131131

132-
conn.execute(
133-
"INSERT INTO data_source_info (interval_start_ns, interval_stop_ns, warning_message, description)
134-
VALUES (?1, ?2, ?3, ?4)",
135-
params![
136-
info.interval.start.0,
137-
info.interval.stop.0,
138-
info.warning_message,
139-
description_str
140-
],
141-
)?;
132+
let mut app = conn.appender("data_source_info")?;
133+
app.append_row(params![
134+
info.interval.start.0,
135+
info.interval.stop.0,
136+
info.warning_message,
137+
description_str
138+
])?;
142139

143140
Ok(())
144141
}
@@ -149,10 +146,7 @@ impl<T: DeferredDataSource> DataSourceDuckDBWriter<T> {
149146
info: &EntryInfo,
150147
entry_rows: &[EntryRow],
151148
) -> duckdb::Result<()> {
152-
let mut stmt = conn.prepare(
153-
"INSERT INTO entry_info (entry_slug, short_name, long_name, parent_slug, type)
154-
VALUES (?1, ?2, ?3, ?4, ?5)",
155-
)?;
149+
let mut app = conn.appender("entry_info")?;
156150

157151
for EntryRow {
158152
entry_id,
@@ -177,7 +171,7 @@ impl<T: DeferredDataSource> DataSourceDuckDBWriter<T> {
177171
long_name,
178172
..
179173
} => {
180-
stmt.execute(params![
174+
app.append_row(params![
181175
entry_id_slug,
182176
short_name,
183177
long_name,
@@ -287,14 +281,8 @@ impl<T: DeferredDataSource> DataSourceDuckDBWriter<T> {
287281
slots.insert(field_id, (columns.len(), field_type));
288282
columns.push(field_name);
289283
}
290-
let placeholders: Vec<_> = (1..=columns.len()).map(|i| format!("?{}", i)).collect();
291284

292-
let mut stmt = conn.prepare(&format!(
293-
"INSERT INTO {} ({}) VALUES ({})",
294-
entry_id_slug,
295-
columns.join(", "),
296-
placeholders.join(", "),
297-
))?;
285+
let mut app = conn.appender(entry_id_slug)?;
298286

299287
// Important: not all items will have all fields; everything else should be NULL
300288
fn null() -> Box<dyn duckdb::ToSql> {
@@ -314,7 +302,7 @@ impl<T: DeferredDataSource> DataSourceDuckDBWriter<T> {
314302
let (slot, field_type) = slots.get(field_id).unwrap();
315303
values[*slot] = field_type.sql_value(&field);
316304
}
317-
stmt.execute(duckdb::params_from_iter(&values))?;
305+
app.append_row(duckdb::appender_params_from_iter(&values))?;
318306
}
319307
}
320308

0 commit comments

Comments
 (0)