Skip to content

Commit e1f10bb

Browse files
committed
mark attach as experimental
1 parent f598dfa commit e1f10bb

File tree

9 files changed

+42
-5
lines changed

9 files changed

+42
-5
lines changed

cli/app.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ pub struct Opts {
8686
pub experimental_autovacuum: bool,
8787
#[clap(long, help = "Enable experimental triggers feature")]
8888
pub experimental_triggers: bool,
89+
#[clap(long, help = "Enable experimental attach feature")]
90+
pub experimental_attach: bool,
8991
}
9092

9193
const PROMPT: &str = "turso> ";
@@ -196,7 +198,8 @@ impl Limbo {
196198
.with_strict(opts.experimental_strict)
197199
.with_encryption(opts.experimental_encryption)
198200
.with_index_method(opts.experimental_index_method)
199-
.with_triggers(opts.experimental_triggers),
201+
.with_triggers(opts.experimental_triggers)
202+
.with_attach(opts.experimental_attach),
200203
)?
201204
} else {
202205
let flags = if opts.readonly {
@@ -215,6 +218,7 @@ impl Limbo {
215218
.with_index_method(opts.experimental_index_method)
216219
.with_autovacuum(opts.experimental_autovacuum)
217220
.with_triggers(opts.experimental_triggers)
221+
.with_attach(opts.experimental_attach)
218222
.turso_cli(),
219223
None,
220224
)?;

core/incremental/cursor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ mod tests {
318318
enable_index_method: false,
319319
enable_autovacuum: false,
320320
enable_triggers: false,
321+
enable_attach: false,
321322
},
322323
None,
323324
)?;

core/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ pub struct DatabaseOpts {
121121
pub enable_index_method: bool,
122122
pub enable_autovacuum: bool,
123123
pub enable_triggers: bool,
124+
pub enable_attach: bool,
124125
enable_load_extension: bool,
125126
}
126127

@@ -164,6 +165,11 @@ impl DatabaseOpts {
164165
self.enable_triggers = enable;
165166
self
166167
}
168+
169+
pub fn with_attach(mut self, enable: bool) -> Self {
170+
self.enable_attach = enable;
171+
self
172+
}
167173
}
168174

169175
#[derive(Clone, Debug, Default)]
@@ -1042,6 +1048,10 @@ impl Database {
10421048
self.opts.enable_triggers
10431049
}
10441050

1051+
pub fn experimental_attach_enabled(&self) -> bool {
1052+
self.opts.enable_attach
1053+
}
1054+
10451055
/// check if database is currently in MVCC mode
10461056
pub fn mvcc_enabled(&self) -> bool {
10471057
self.mv_store.load().is_some()
@@ -2242,6 +2252,10 @@ impl Connection {
22422252
self.db.experimental_triggers_enabled()
22432253
}
22442254

2255+
pub fn experimental_attach_enabled(&self) -> bool {
2256+
self.db.experimental_attach_enabled()
2257+
}
2258+
22452259
pub fn mvcc_enabled(&self) -> bool {
22462260
self.db.mvcc_enabled()
22472261
}

core/translate/attach.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use crate::translate::expr::{sanitize_string, translate_expr};
44
use crate::translate::{ProgramBuilder, ProgramBuilderOpts};
55
use crate::util::normalize_ident;
66
use crate::vdbe::insn::Insn;
7+
use crate::Connection;
78
use crate::Result;
9+
use std::sync::Arc;
810
use turso_parser::ast::{Expr, Literal};
911

1012
/// Translate ATTACH statement
@@ -15,7 +17,13 @@ pub fn translate_attach(
1517
db_name: &Expr,
1618
key: &Option<Box<Expr>>,
1719
mut program: ProgramBuilder,
20+
connection: Arc<Connection>,
1821
) -> Result<ProgramBuilder> {
22+
if !connection.experimental_attach_enabled() {
23+
return Err(crate::LimboError::ParseError(
24+
"ATTACH is an experimental feature. Enable with --experimental-attach flag".to_string(),
25+
));
26+
}
1927
// SQLite treats ATTACH as a function call to sqlite_attach(filename, dbname, key)
2028
// We'll allocate registers for the arguments and call the function
2129

@@ -119,7 +127,13 @@ pub fn translate_detach(
119127
expr: &Expr,
120128
resolver: &Resolver,
121129
mut program: ProgramBuilder,
130+
connection: Arc<Connection>,
122131
) -> Result<ProgramBuilder> {
132+
if !connection.experimental_attach_enabled() {
133+
return Err(crate::LimboError::ParseError(
134+
"DETACH is an experimental feature. Enable with --experimental-attach flag".to_string(),
135+
));
136+
}
123137
// SQLite treats DETACH as a function call to sqlite_detach(dbname)
124138

125139
program.extend(&ProgramBuilderOpts {

core/translate/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn translate_inner(
152152
}
153153
ast::Stmt::Analyze { name } => translate_analyze(name, resolver, program)?,
154154
ast::Stmt::Attach { expr, db_name, key } => {
155-
attach::translate_attach(&expr, resolver, &db_name, &key, program)?
155+
attach::translate_attach(&expr, resolver, &db_name, &key, program, connection.clone())?
156156
}
157157
ast::Stmt::Begin { typ, name } => translate_tx_begin(typ, name, resolver.schema, program)?,
158158
ast::Stmt::Commit { name } => translate_tx_commit(name, program)?,
@@ -261,7 +261,9 @@ pub fn translate_inner(
261261
connection,
262262
)?
263263
}
264-
ast::Stmt::Detach { name } => attach::translate_detach(&name, resolver, program)?,
264+
ast::Stmt::Detach { name } => {
265+
attach::translate_detach(&name, resolver, program, connection.clone())?
266+
}
265267
ast::Stmt::DropIndex {
266268
if_exists,
267269
idx_name,

macros/src/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl Args {
6161
.with_index_method(true)
6262
.with_encryption(true)
6363
.with_triggers(true)
64+
.with_attach(true)
6465
};
6566

6667
builder = quote! {

scripts/limbo-sqlite3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
77
TURSODB="$PROJECT_ROOT/target/debug/tursodb"
88

99
# Add experimental features for testing
10-
EXPERIMENTAL_FLAGS="--experimental-views --experimental-strict --experimental-triggers"
10+
EXPERIMENTAL_FLAGS="--experimental-views --experimental-strict --experimental-triggers --experimental-attach"
1111

1212
# if RUST_LOG is non-empty, enable tracing output
1313
if [ -n "$RUST_LOG" ]; then

scripts/turso-mvcc-sqlite3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ TURSODB="$PROJECT_ROOT/target/debug/tursodb"
88

99
# Add experimental features for testing
1010
# Note: MVCC is enabled via PRAGMA journal_mode = 'experimental_mvcc'
11-
EXPERIMENTAL_FLAGS="--experimental-views --experimental-strict --experimental-triggers"
11+
EXPERIMENTAL_FLAGS="--experimental-views --experimental-strict --experimental-triggers --experimental-attach"
1212

1313
# if RUST_LOG is non-empty, enable tracing output
1414
if [ -n "$RUST_LOG" ]; then

sdk-kit/src/rsapi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ impl TursoDatabase {
497497
"strict" => opts.with_strict(true),
498498
"autovacuum" => opts.with_autovacuum(true),
499499
"triggers" => opts.with_triggers(true),
500+
"attach" => opts.with_attach(true),
500501
_ => opts,
501502
};
502503
}

0 commit comments

Comments
 (0)