Skip to content

Commit acd7863

Browse files
authored
Add missing 28 to AppenderParams array impl (#614)
And document appender alternatives for wide tables. Fixes #367
2 parents c1e45c9 + 3856e44 commit acd7863

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

crates/duckdb/src/appender/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,41 @@ use crate::{
2121
/// If you need to share an `Appender` across threads, wrap it in a `Mutex`.
2222
///
2323
/// See [DuckDB concurrency documentation](https://duckdb.org/docs/stable/connect/concurrency.html) for more details.
24+
///
25+
/// # Wide Tables (Many Columns)
26+
///
27+
/// Array literals `[value; N]` are supported for tables with up to 32 columns.
28+
///
29+
/// ```rust,ignore
30+
/// appender.append_row([0; 32])?;
31+
/// appender.append_row([1, 2, 3, 4, 5])?;
32+
/// ```
33+
///
34+
/// For tables with more than 32 columns, use one of these alternatives:
35+
///
36+
/// ## 1. Slice approach - convert values to `&dyn ToSql`
37+
///
38+
/// ```rust,ignore
39+
/// let values: Vec<i32> = vec![0; 100];
40+
/// let params: Vec<&dyn ToSql> = values.iter().map(|v| v as &dyn ToSql).collect();
41+
/// appender.append_row(params.as_slice())?;
42+
/// ```
43+
///
44+
/// ## 2. `params!` macro - write values explicitly
45+
///
46+
/// ```rust,ignore
47+
/// appender.append_row(params![v1, v2, v3, ..., v50])?;
48+
/// ```
49+
///
50+
/// ## 3. `appender_params_from_iter` - pass an iterator directly
51+
///
52+
/// ```rust,ignore
53+
/// use duckdb::appender_params_from_iter;
54+
/// let values: Vec<i32> = vec![0; 100];
55+
/// appender.append_row(appender_params_from_iter(values))?;
56+
/// ```
57+
///
58+
/// All three methods can be used interchangeably and mixed in the same appender.
2459
pub struct Appender<'conn> {
2560
conn: &'conn Connection,
2661
app: ffi::duckdb_appender,

crates/duckdb/src/appender_params.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,14 @@ macro_rules! impl_for_array_ref {
172172
// Following libstd/libcore's (old) lead, implement this for arrays up to `[_;
173173
// 32]`. Note `[_; 0]` is intentionally omitted for coherence reasons, see the
174174
// note above the impl of `[&dyn ToSql; 0]` for more information.
175+
//
176+
// For tables with more than 32 columns, users should use:
177+
// - `&[&dyn ToSql]` for dynamic parameter binding (recommended)
178+
// - `params!` macro
179+
// - `appender_params_from_iter`
175180
impl_for_array_ref!(
176181
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
177-
18 19 20 21 22 23 24 25 26 27 29 30 31 32
182+
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
178183
);
179184

180185
/// Adapter type which allows any iterator over [`ToSql`] values to implement

0 commit comments

Comments
 (0)