11//! Basic DuckLake query example with snapshot isolation
22//!
33//! This example demonstrates how to:
4- //! 1. Create a DuckLake catalog from DuckDB, PostgreSQL, or MySQL
4+ //! 1. Create a DuckLake catalog from DuckDB, PostgreSQL, MySQL, or SQLite
55//! 2. Bind the catalog to a specific snapshot for query consistency
66//! 3. Register it with DataFusion
77//! 4. Execute a simple SELECT query
3636//! "mysql://user:password@localhost:3306/database" \
3737//! "SELECT * FROM main.users"
3838//! ```
39+ //!
40+ //! With SQLite catalog (requires --features metadata-sqlite):
41+ //! ```bash
42+ //! cargo run --example basic_query --features metadata-sqlite \
43+ //! "sqlite:///path/to/catalog.db" \
44+ //! "SELECT * FROM main.users"
45+ //! ```
3946
4047use datafusion:: execution:: runtime_env:: RuntimeEnv ;
4148use datafusion:: prelude:: * ;
@@ -45,6 +52,8 @@ use datafusion_ducklake::DuckdbMetadataProvider;
4552use datafusion_ducklake:: MySqlMetadataProvider ;
4653#[ cfg( feature = "metadata-postgres" ) ]
4754use datafusion_ducklake:: PostgresMetadataProvider ;
55+ #[ cfg( feature = "metadata-sqlite" ) ]
56+ use datafusion_ducklake:: SqliteMetadataProvider ;
4857use datafusion_ducklake:: { DuckLakeCatalog , MetadataProvider , register_ducklake_functions} ;
4958use object_store:: ObjectStore ;
5059use object_store:: aws:: AmazonS3Builder ;
@@ -65,6 +74,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
6574 eprintln ! (
6675 " MySQL: cargo run --example basic_query --features metadata-mysql \" mysql://...\" \" SQL\" "
6776 ) ;
77+ eprintln ! (
78+ " SQLite: cargo run --example basic_query --features metadata-sqlite \" sqlite://...\" \" SQL\" "
79+ ) ;
6880 exit ( 1 ) ;
6981 }
7082 let catalog_source = & args[ 1 ] ;
@@ -73,6 +85,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
7385 // Detect provider type based on input
7486 let is_postgres = catalog_source. starts_with ( "postgresql://" ) ;
7587 let is_mysql = catalog_source. starts_with ( "mysql://" ) ;
88+ let is_sqlite = catalog_source. starts_with ( "sqlite:" ) ;
7689
7790 if is_postgres {
7891 #[ cfg( not( feature = "metadata-postgres" ) ) ]
@@ -106,6 +119,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
106119 println ! ( "Current snapshot ID: {}" , snapshot_id) ;
107120 run_query ( provider, snapshot_id, sql) . await ?;
108121 }
122+ } else if is_sqlite {
123+ #[ cfg( not( feature = "metadata-sqlite" ) ) ]
124+ {
125+ eprintln ! ( "Error: SQLite support requires the 'metadata-sqlite' feature" ) ;
126+ eprintln ! ( "Run with: cargo run --example basic_query --features metadata-sqlite" ) ;
127+ exit ( 1 ) ;
128+ }
129+
130+ #[ cfg( feature = "metadata-sqlite" ) ]
131+ {
132+ println ! ( "Connecting to SQLite catalog: {}" , catalog_source) ;
133+ let provider = Arc :: new ( SqliteMetadataProvider :: new ( catalog_source) . await ?) ;
134+ let snapshot_id = provider. get_current_snapshot ( ) ?;
135+ println ! ( "Current snapshot ID: {}" , snapshot_id) ;
136+ run_query ( provider, snapshot_id, sql) . await ?;
137+ }
109138 } else {
110139 #[ cfg( feature = "metadata-duckdb" ) ]
111140 {
0 commit comments