Trait IntoParams

Source
pub trait IntoParams: Sealed { }
Expand description

Converts some type into parameters that can be passed to libsql.

The trait is sealed and not designed to be implemented by hand but instead provides a few ways to use it.

§Passing parameters to libsql

Many functions in this library let you pass parameters to libsql. Doing this lets you avoid any risk of SQL injection, and is simpler than escaping things manually. These functions generally contain some paramter that generically accepts some implementation this trait.

§Positional parameters

These can be supplied in a few ways:

  • For heterogeneous parameter lists of 16 or less items a tuple syntax is supported by doing (1, "foo").
  • For hetergeneous parameter lists of 16 or greater, the [libsql::params!] is supported by doing libsql::params![1, "foo"].
  • For homogeneous paramter types (where they are all the same type), const arrays are supported by doing [1, 2, 3].

§Example (positional)

let mut stmt = conn.prepare("INSERT INTO test (a, b) VALUES (?1, ?2)").await?;

// Using a tuple:
stmt.execute((0, "foobar")).await?;

// Using `libsql::params!`:
stmt.execute(params![1i32, "blah"]).await?;

// array literal — non-references
stmt.execute([2i32, 3i32]).await?;

// array literal — references
stmt.execute(["foo", "bar"]).await?;

// Slice literal, references:
stmt.execute([2i32, 3i32]).await?;

§Named paramters

  • For heterogeneous parameter lists of 16 or less items a tuple syntax is supported by doing (("key1", 1), ("key2", "foo")).
  • For hetergeneous parameter lists of 16 or greater, the [libsql::params!] is supported by doing libsql::named_params!["key1": 1, "key2": "foo"].
  • For homogeneous paramter types (where they are all the same type), const arrays are supported by doing [("key1", 1), ("key2, 2), ("key3", 3)].

§Example (named)

let mut stmt = conn.prepare("INSERT INTO test (a, b) VALUES (:key1, :key2)").await?;

// Using a tuple:
stmt.execute(((":key1", 0), (":key2", "foobar"))).await?;

// Using `libsql::named_params!`:
stmt.execute(named_params! {":key1": 1i32, ":key2": "blah" }).await?;

// const array:
stmt.execute([(":key1", 2i32), (":key2", 3i32)]).await?;

Implementations on Foreign Types§

Source§

impl IntoParams for ()

Source§

impl<A, B> IntoParams for ((&str, A), (&str, B))
where A: IntoValue, B: IntoValue,

Source§

impl<A, B> IntoParams for (A, B)
where A: IntoValue, B: IntoValue,

Source§

impl<A, B, C> IntoParams for ((&str, A), (&str, B), (&str, C))
where A: IntoValue, B: IntoValue, C: IntoValue,

Source§

impl<A, B, C> IntoParams for (A, B, C)
where A: IntoValue, B: IntoValue, C: IntoValue,

Source§

impl<A, B, C, D> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D))
where A: IntoValue, B: IntoValue, C: IntoValue, D: IntoValue,

Source§

impl<A, B, C, D> IntoParams for (A, B, C, D)
where A: IntoValue, B: IntoValue, C: IntoValue, D: IntoValue,

Source§

impl<A, B, C, D, E> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D), (&str, E))
where A: IntoValue, B: IntoValue, C: IntoValue, D: IntoValue, E: IntoValue,

Source§

impl<A, B, C, D, E> IntoParams for (A, B, C, D, E)
where A: IntoValue, B: IntoValue, C: IntoValue, D: IntoValue, E: IntoValue,

Source§

impl<A, B, C, D, E, F> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D), (&str, E), (&str, F))

Source§

impl<A, B, C, D, E, F> IntoParams for (A, B, C, D, E, F)

Source§

impl<A, B, C, D, E, F, G> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D), (&str, E), (&str, F), (&str, G))

Source§

impl<A, B, C, D, E, F, G> IntoParams for (A, B, C, D, E, F, G)

Source§

impl<A, B, C, D, E, F, G, H> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D), (&str, E), (&str, F), (&str, G), (&str, H))

Source§

impl<A, B, C, D, E, F, G, H> IntoParams for (A, B, C, D, E, F, G, H)

Source§

impl<A, B, C, D, E, F, G, H, I> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D), (&str, E), (&str, F), (&str, G), (&str, H), (&str, I))

Source§

impl<A, B, C, D, E, F, G, H, I> IntoParams for (A, B, C, D, E, F, G, H, I)

Source§

impl<A, B, C, D, E, F, G, H, I, J> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D), (&str, E), (&str, F), (&str, G), (&str, H), (&str, I), (&str, J))

Source§

impl<A, B, C, D, E, F, G, H, I, J> IntoParams for (A, B, C, D, E, F, G, H, I, J)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D), (&str, E), (&str, F), (&str, G), (&str, H), (&str, I), (&str, J), (&str, K))

Source§

impl<A, B, C, D, E, F, G, H, I, J, K> IntoParams for (A, B, C, D, E, F, G, H, I, J, K)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D), (&str, E), (&str, F), (&str, G), (&str, H), (&str, I), (&str, J), (&str, K), (&str, L))

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L> IntoParams for (A, B, C, D, E, F, G, H, I, J, K, L)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D), (&str, E), (&str, F), (&str, G), (&str, H), (&str, I), (&str, J), (&str, K), (&str, L), (&str, M))

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M> IntoParams for (A, B, C, D, E, F, G, H, I, J, K, L, M)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D), (&str, E), (&str, F), (&str, G), (&str, H), (&str, I), (&str, J), (&str, K), (&str, L), (&str, M), (&str, N))

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N> IntoParams for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D), (&str, E), (&str, F), (&str, G), (&str, H), (&str, I), (&str, J), (&str, K), (&str, L), (&str, M), (&str, N), (&str, O))

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> IntoParams for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> IntoParams for ((&str, A), (&str, B), (&str, C), (&str, D), (&str, E), (&str, F), (&str, G), (&str, H), (&str, I), (&str, J), (&str, K), (&str, L), (&str, M), (&str, N), (&str, O), (&str, P))

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> IntoParams for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)

Source§

impl<T: IntoValue + Clone, const N: usize> IntoParams for &[T; N]

Source§

impl<T: IntoValue> IntoParams for Vec<(String, T)>

Source§

impl<T: IntoValue> IntoParams for Vec<T>

Source§

impl<T: IntoValue, const N: usize> IntoParams for [T; N]

Source§

impl<T: IntoValue, const N: usize> IntoParams for [(&str, T); N]

Implementors§