mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-18 17:14:20 +01:00
enable indices in the python SDK
This commit is contained in:
@@ -315,10 +315,9 @@ impl Drop for Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::arc_with_non_send_sync)]
|
#[allow(clippy::arc_with_non_send_sync)]
|
||||||
#[pyfunction(signature = (path, experimental_indexes=None))]
|
#[pyfunction(signature = (path))]
|
||||||
pub fn connect(path: &str, experimental_indexes: Option<bool>) -> Result<Connection> {
|
pub fn connect(path: &str) -> Result<Connection> {
|
||||||
let experimental_indexes = experimental_indexes.unwrap_or(true);
|
match turso_core::Connection::from_uri(path, true, false, false) {
|
||||||
match turso_core::Connection::from_uri(path, experimental_indexes, false, false) {
|
|
||||||
Ok((io, conn)) => Ok(Connection { conn, _io: io }),
|
Ok((io, conn)) => Ok(Connection { conn, _io: io }),
|
||||||
Err(e) => Err(PyErr::new::<ProgrammingError, _>(format!(
|
Err(e) => Err(PyErr::new::<ProgrammingError, _>(format!(
|
||||||
"Failed to create connection: {e:?}"
|
"Failed to create connection: {e:?}"
|
||||||
|
|||||||
@@ -89,6 +89,24 @@ def test_in_memory_fetchone_select_all_users(provider):
|
|||||||
assert alice
|
assert alice
|
||||||
assert alice == (1, "alice")
|
assert alice == (1, "alice")
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("provider", ["sqlite3", "turso"])
|
||||||
|
def test_in_memory_index(provider):
|
||||||
|
conn = connect(provider, ":memory:")
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("CREATE TABLE users (name TEXT PRIMARY KEY, email TEXT)")
|
||||||
|
cursor.execute("CREATE INDEX email_idx ON users(email)")
|
||||||
|
cursor.execute("INSERT INTO users VALUES ('alice', 'a@b.c'), ('bob', 'b@d.e')")
|
||||||
|
|
||||||
|
cursor.execute("SELECT * FROM users WHERE email = 'a@b.c'")
|
||||||
|
alice = cursor.fetchall()
|
||||||
|
|
||||||
|
cursor.execute("SELECT * FROM users WHERE email = 'b@d.e'")
|
||||||
|
bob = cursor.fetchall()
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
assert alice == [("alice", "a@b.c")]
|
||||||
|
assert bob == [("bob", "b@d.e")]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("provider", ["sqlite3", "turso"])
|
@pytest.mark.parametrize("provider", ["sqlite3", "turso"])
|
||||||
def test_fetchone_select_all_users(provider):
|
def test_fetchone_select_all_users(provider):
|
||||||
|
|||||||
Reference in New Issue
Block a user