pub fn register_on_every_new_connection() -> c_intExpand description
Register SQLiteGIS as a SQLite auto-extension: from the next call onward, every new SQLite connection opened in this process has the SQLiteGIS spatial functions registered on it automatically.
This is the recommended way to wire SQLiteGIS into Diesel’s
SqliteConnection::establish(...) flow, which does not give the caller a
raw *mut sqlite3 to pass to register_functions directly.
Calling the function more than once is a no-op: a std::sync::Once
guarantees the underlying sqlite3_auto_extension registration happens
at most once per process.
Native targets only. On wasm32 the connection lifecycle is owned by
sqlite-wasm-rs and you should call register_functions from your
own auto_extension shim once per connection instead.
Returns SQLITE_OK on the first call, and SQLITE_OK on every
subsequent call too. A non-zero return from this function should be
treated as a SQLite-internal failure.
use diesel::{Connection, RunQueryDsl, sqlite::SqliteConnection};
use diesel::deserialize::QueryableByName;
use diesel::sql_types::Text;
sqlitegis::sqlite::register_on_every_new_connection();
let mut c = SqliteConnection::establish(":memory:").unwrap();
#[derive(QueryableByName)]
struct R { #[diesel(sql_type = Text)] wkt: String }
let row: R = diesel::sql_query(
"SELECT ST_AsText(ST_Point(1.0, 2.0, 4326)) AS wkt",
).get_result(&mut c).unwrap();
assert_eq!(row.wkt, "POINT(1 2)");