Skip to content

Commit

Permalink
Added support for passing Vec<&Vector> with SQLx
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Mar 18, 2024
1 parent 33144d2 commit 53330c1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/sqlx_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ impl PgHasArrayType for Vector {
}
}

impl PgHasArrayType for &Vector {
fn array_type_info() -> PgTypeInfo {
PgTypeInfo::with_name("_vector")
}
}

#[cfg(test)]
mod tests {
use crate::Vector;
Expand Down Expand Up @@ -108,6 +114,12 @@ mod tests {
.execute(&pool)
.await?;

let vecs = vec![&vec, &vec2];
sqlx::query("INSERT INTO sqlx_items (factors) VALUES ($1)")
.bind(&vecs)
.execute(&pool)
.await?;

let vecs = vec![vec, vec2];
sqlx::query("INSERT INTO sqlx_items (factors) VALUES ($1)")
.bind(&vecs)
Expand Down

0 comments on commit 53330c1

Please sign in to comment.