@@ -7,24 +7,32 @@ use sqlx::{
77
88#[ tokio:: main( flavor = "current_thread" ) ]
99async fn main ( ) -> anyhow:: Result < ( ) > {
10- let opts = SqliteConnectOptions :: from_str ( & std:: env:: var ( "DATABASE_URL" ) ?) ?
11- // The sqlx.toml file controls loading extensions for the CLI
12- // and for the query checking macros, *not* for the
13- // application while it's running. Thus, if we want the
14- // extension to be available during program execution, we need
15- // to load it.
16- //
17- // Note that while in this case the extension path is the same
18- // when checking the program (sqlx.toml) and when running it
19- // (here), this is not required. The runtime environment can
20- // be entirely different from the development one.
21- //
22- // The extension can be described with a full path, as seen
23- // here, but in many cases that will not be necessary. As long
24- // as the extension is installed in a directory on the library
25- // search path, it is sufficient to just provide the extension
26- // name, like "ipaddr"
27- . extension ( "/tmp/sqlite3-lib/ipaddr" ) ;
10+ let opts = SqliteConnectOptions :: from_str ( & std:: env:: var ( "DATABASE_URL" ) ?) ?;
11+ // The sqlx.toml file controls loading extensions for the CLI
12+ // and for the query checking macros, *not* for the
13+ // application while it's running. Thus, if we want the
14+ // extension to be available during program execution, we need
15+ // to load it.
16+ //
17+ // Note that while in this case the extension paths are the
18+ // same when checking the program (sqlx.toml) and when running
19+ // it (here), this is not required. The runtime environment
20+ // can be entirely different from the development one.
21+ //
22+ // The extension can be described with a full path, as seen
23+ // here, but in many cases that will not be necessary. As long
24+ // as the extension is installed in a directory on the library
25+ // search path, it is sufficient to just provide the extension
26+ // name, like "ipaddr"
27+ let opts = unsafe { opts. extension ( "/tmp/sqlite3-lib/ipaddr" ) } ;
28+ // The entrypoint for an extension is usually inferred as
29+ // `sqlite3_extension_init` or `sqlite3_X_init` where X is the
30+ // lowercase, ASCII-only equivalent of the filename. For the
31+ // extension below, this would be `sqlite3_uuidrenamed_init`.
32+ // The entrypoint can instead be explicitly provided.
33+ let opts = unsafe {
34+ opts. extension_with_entrypoint ( "/tmp/sqlite3-lib/uuid_renamed" , "sqlite3_uuid_init" )
35+ } ;
2836
2937 let db = SqlitePool :: connect_with ( opts) . await ?;
3038
@@ -41,7 +49,11 @@ async fn main() -> anyhow::Result<()> {
4149 . execute ( & db)
4250 . await ?;
4351
44- println ! ( "Query which requires the extension was successfully executed." ) ;
52+ query ! ( "insert into uuids (uuid) values (uuid4())" )
53+ . execute ( & db)
54+ . await ?;
55+
56+ println ! ( "Queries which require the extensions were successfully executed." ) ;
4557
4658 Ok ( ( ) )
4759}
0 commit comments