Skip to content

Commit 01d65bb

Browse files
committed
Pass experimental feature flags from JS/python bindings
1 parent 86c0148 commit 01d65bb

File tree

6 files changed

+30
-13
lines changed

6 files changed

+30
-13
lines changed

bindings/javascript/packages/common/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
export type ExperimentalFeature = 'views' | 'strict' | 'encryption' | 'index_method' | 'autovacuum' | 'triggers' | 'attach';
2+
13
export interface DatabaseOpts {
24
readonly?: boolean,
35
fileMustExist?: boolean,
46
timeout?: number
57
tracing?: 'info' | 'debug' | 'trace'
8+
/** Experimental features to enable */
9+
experimental?: ExperimentalFeature[]
610
}
711

812
export interface NativeDatabase {

bindings/javascript/packages/native/compat.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ test('attach', () => {
8484
const path1 = `test-${(Math.random() * 10000) | 0}.db`;
8585
const path2 = `test-${(Math.random() * 10000) | 0}.db`;
8686
try {
87-
const db1 = new Database(path1);
87+
const db1 = new Database(path1, { experimental: ["attach"] });
8888
db1.exec("CREATE TABLE t(x)");
8989
db1.exec("INSERT INTO t VALUES (1), (2), (3)");
90-
const db2 = new Database(path2);
90+
const db2 = new Database(path2, { experimental: ["attach"] });
9191
db2.exec("CREATE TABLE q(x)");
9292
db2.exec("INSERT INTO q VALUES (4), (5), (6)");
9393

bindings/javascript/packages/native/promise.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ test('attach', async () => {
207207
const path1 = `test-${(Math.random() * 10000) | 0}.db`;
208208
const path2 = `test-${(Math.random() * 10000) | 0}.db`;
209209
try {
210-
const db1 = await connect(path1);
210+
const db1 = await connect(path1, { experimental: ["attach"] });
211211
await db1.exec("CREATE TABLE t(x)");
212212
await db1.exec("INSERT INTO t VALUES (1), (2), (3)");
213-
const db2 = await connect(path2);
213+
const db2 = await connect(path2, { experimental: ["attach"] });
214214
await db2.exec("CREATE TABLE q(x)");
215215
await db2.exec("INSERT INTO q VALUES (4), (5), (6)");
216216

bindings/javascript/src/lib.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ pub struct DatabaseOpts {
123123
pub timeout: Option<u32>,
124124
pub file_must_exist: Option<bool>,
125125
pub tracing: Option<String>,
126+
/// Experimental features to enable
127+
pub experimental: Option<Vec<String>>,
126128
}
127129

128130
fn step_sync(stmt: &Arc<RefCell<turso_core::Statement>>) -> napi::Result<u32> {
@@ -162,6 +164,7 @@ fn connect_sync(db: &DatabaseInner) -> napi::Result<()> {
162164

163165
let mut flags = turso_core::OpenFlags::Create;
164166
let mut busy_timeout = None;
167+
let mut core_opts = turso_core::DatabaseOpts::new();
165168
if let Some(opts) = &db.opts {
166169
if opts.readonly == Some(true) {
167170
flags.set(turso_core::OpenFlags::ReadOnly, true);
@@ -173,16 +176,25 @@ fn connect_sync(db: &DatabaseInner) -> napi::Result<()> {
173176
if let Some(timeout) = opts.timeout {
174177
busy_timeout = Some(std::time::Duration::from_millis(timeout as u64));
175178
}
179+
if let Some(experimental) = &opts.experimental {
180+
for feature in experimental {
181+
core_opts = match feature.as_str() {
182+
"views" => core_opts.with_views(true),
183+
"strict" => core_opts.with_strict(true),
184+
"encryption" => core_opts.with_encryption(true),
185+
"index_method" => core_opts.with_index_method(true),
186+
"autovacuum" => core_opts.with_autovacuum(true),
187+
"triggers" => core_opts.with_triggers(true),
188+
"attach" => core_opts.with_attach(true),
189+
_ => core_opts,
190+
};
191+
}
192+
}
176193
}
177194
let io = &db.io;
178-
let db_core = turso_core::Database::open_file_with_flags(
179-
io.clone(),
180-
&db.path,
181-
flags,
182-
turso_core::DatabaseOpts::new(),
183-
None,
184-
)
185-
.map_err(|e| to_generic_error(&format!("failed to open database {}", db.path), e))?;
195+
let db_core =
196+
turso_core::Database::open_file_with_flags(io.clone(), &db.path, flags, core_opts, None)
197+
.map_err(|e| to_generic_error(&format!("failed to open database {}", db.path), e))?;
186198

187199
let conn = db_core
188200
.connect()

bindings/javascript/sync/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ impl SyncEngine {
234234
readonly: None,
235235
timeout: None,
236236
tracing: opts.tracing.clone(),
237+
experimental: None,
237238
}),
238239
)?));
239240
let opts_filled = SyncEngineOptsFilled {

testing/cli_tests/cli_test_cases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def test_parse_error():
372372

373373

374374
def test_tables_with_attached_db():
375-
shell = TestTursoShell()
375+
shell = TestTursoShell(flags="-q --experimental-attach")
376376
shell.execute_dot(".open :memory:")
377377
shell.execute_dot("CREATE TABLE orders(a);")
378378
shell.execute_dot("ATTACH DATABASE 'testing/testing.db' AS attached;")

0 commit comments

Comments
 (0)