Skip to content

Commit 04e85b0

Browse files
committed
libsql,namespaces: add client-side ATTACH support
1 parent bc47b06 commit 04e85b0

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

libsql-server/tests/namespaces/meta.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ fn meta_store() {
113113
)?;
114114
let foo_conn = foo.connect()?;
115115

116-
foo_conn.execute("attach foo as foo", ()).await.unwrap();
117116
foo_conn
118-
.execute("select * from foo.sqlite_master", ())
117+
.execute_batch("attach foo as foo; select * from foo.sqlite_master")
119118
.await
120119
.unwrap();
121120
}

libsql/src/parser.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use crate::{Error, Result};
44
use fallible_iterator::FallibleIterator;
5-
use sqlite3_parser::ast::{Cmd, PragmaBody, QualifiedName, Stmt, TransactionType};
5+
use sqlite3_parser::ast::{Cmd, PragmaBody, QualifiedName, Stmt, TransactionType, Expr, Id};
66
use sqlite3_parser::lexer::sql::{Parser, ParserError};
77

88
/// A group of statements to be executed together.
@@ -30,6 +30,8 @@ pub enum StmtKind {
3030
Write,
3131
Savepoint,
3232
Release,
33+
Attach,
34+
Detach,
3335
Other,
3436
}
3537

@@ -116,6 +118,12 @@ impl StmtKind {
116118
savepoint_name: Some(_),
117119
..
118120
}) => Some(Self::Release),
121+
Cmd::Stmt(Stmt::Attach {
122+
expr: Expr::Id(Id(expr)),
123+
db_name: Expr::Id(Id(name)),
124+
..
125+
}) if expr == name => Some(Self::Attach),
126+
Cmd::Stmt(Stmt::Detach(_)) => Some(Self::Detach),
119127
_ => None,
120128
}
121129
}

libsql/src/replication/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl State {
6666
(State::Txn, StmtKind::Release) => State::Txn,
6767
(_, StmtKind::Release) => State::Invalid,
6868

69-
(state, StmtKind::Other | StmtKind::Write | StmtKind::Read) => state,
69+
(state, StmtKind::Other | StmtKind::Write | StmtKind::Read | StmtKind::Attach | StmtKind::Detach) => state,
7070
(State::Invalid, _) => State::Invalid,
7171

7272
(State::Init, StmtKind::TxnBegin) => State::Txn,

0 commit comments

Comments
 (0)