-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,927 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from typing import Any | ||
|
||
from scyllapy._internal import ( | ||
Consistency, | ||
SerialConsistency, | ||
Scylla, | ||
QueryResult, | ||
InlineBatch, | ||
) | ||
|
||
class Select: | ||
def __init__(self, table: str) -> None: ... | ||
def only(self, *columns: str) -> Select: ... | ||
def where(self, clause: str, params: list[Any] | None = None) -> Select: ... | ||
def group_by(self, group: str) -> Select: ... | ||
def order_by(self, order: str, desc: bool = False) -> Select: ... | ||
def per_partition_limit(self, per_partition_limit: int) -> Select: ... | ||
def limit(self, limit: int) -> Select: ... | ||
def allow_filtering(self) -> Select: ... | ||
def distinct(self) -> Select: ... | ||
def timeout(self, timeout: int | str) -> Select: ... | ||
def request_params( | ||
self, | ||
consistency: Consistency | None = None, | ||
serial_consistency: SerialConsistency | None = None, | ||
request_timeout: int | None = None, | ||
timestamp: int | None = None, | ||
is_idempotent: bool | None = None, | ||
tracing: bool | None = None, | ||
) -> Select: ... | ||
def add_to_batch(self, batch: InlineBatch) -> None: ... | ||
async def execute(self, scylla: Scylla) -> QueryResult: ... | ||
|
||
class Insert: | ||
def __init__(self, table: str) -> None: ... | ||
def if_not_exists(self) -> Insert: ... | ||
def set(self, name: str, value: Any) -> Insert: ... | ||
def timeout(self, timeout: int | str) -> Insert: ... | ||
def timestamp(self, timestamp: int) -> Insert: ... | ||
def ttl(self, ttl: int) -> Insert: ... | ||
def request_params( | ||
self, | ||
consistency: Consistency | None = None, | ||
serial_consistency: SerialConsistency | None = None, | ||
request_timeout: int | None = None, | ||
timestamp: int | None = None, | ||
is_idempotent: bool | None = None, | ||
tracing: bool | None = None, | ||
) -> Insert: ... | ||
def add_to_batch(self, batch: InlineBatch) -> None: ... | ||
async def execute(self, scylla: Scylla) -> QueryResult: ... | ||
|
||
class Delete: | ||
def __init__(self, table: str) -> None: ... | ||
def cols(self, *cols: str) -> Delete: ... | ||
def where(self, clause: str, values: list[Any] | None = None) -> Delete: ... | ||
def timeout(self, timeout: int | str) -> Delete: ... | ||
def timestamp(self, timestamp: int) -> Delete: ... | ||
def if_exists(self) -> Delete: ... | ||
def if_(self, clause: str, values: list[Any] | None = None) -> Delete: ... | ||
def request_params( | ||
self, | ||
consistency: Consistency | None = None, | ||
serial_consistency: SerialConsistency | None = None, | ||
request_timeout: int | None = None, | ||
timestamp: int | None = None, | ||
is_idempotent: bool | None = None, | ||
tracing: bool | None = None, | ||
) -> Delete: ... | ||
def add_to_batch(self, batch: InlineBatch) -> None: ... | ||
async def execute(self, scylla: Scylla) -> QueryResult: ... | ||
|
||
class Update: | ||
def __init__(self, table: str) -> None: ... | ||
def set(self, name: str, value: Any) -> Update: ... | ||
def inc(self, column: str, value: Any) -> Update: ... | ||
def dec(self, column: str, value: Any) -> Update: ... | ||
def where(self, clause: str, values: list[Any] | None = None) -> Update: ... | ||
def timeout(self, timeout: int | str) -> Update: ... | ||
def timestamp(self, timestamp: int) -> Update: ... | ||
def ttl(self, ttl: int) -> Update: ... | ||
def request_params( | ||
self, | ||
consistency: Consistency | None = None, | ||
serial_consistency: SerialConsistency | None = None, | ||
request_timeout: int | None = None, | ||
timestamp: int | None = None, | ||
is_idempotent: bool | None = None, | ||
tracing: bool | None = None, | ||
) -> Update: ... | ||
def if_exists(self) -> Update: ... | ||
def if_(self, clause: str, values: list[Any] | None = None) -> Update: ... | ||
def add_to_batch(self, batch: InlineBatch) -> None: ... | ||
async def execute(self, scylla: Scylla) -> QueryResult: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from ._internal.extra_types import BigInt, Counter, Double, SmallInt, TinyInt, Unset | ||
|
||
__all__ = ["BigInt", "Counter", "Double", "SmallInt", "TinyInt", "Unset"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from ._internal.query_builder import Select, Delete, Insert, Update | ||
|
||
__all__ = ["Select", "Delete", "Insert", "Update"] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import pytest | ||
from scyllapy import Scylla | ||
from scyllapy.query_builder import Delete | ||
from tests.utils import random_string | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_success(scylla: Scylla) -> None: | ||
table_name = random_string(4) | ||
await scylla.execute(f"CREATE TABLE {table_name} (id INT PRIMARY KEY, name TEXT)") | ||
await scylla.execute( | ||
f"INSERT INTO {table_name}(id, name) VALUES (?, ?)", [1, "meme"] | ||
) | ||
await Delete(table_name).where("id = ?", [1]).execute(scylla) | ||
res = await scylla.execute(f"SELECT * FROM {table_name}") | ||
assert not res.all() | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_if_exists(scylla: Scylla) -> None: | ||
table_name = random_string(4) | ||
await scylla.execute(f"CREATE TABLE {table_name} (id INT PRIMARY KEY, name TEXT)") | ||
await scylla.execute( | ||
f"INSERT INTO {table_name}(id, name) VALUES (?, ?)", [1, "meme"] | ||
) | ||
await Delete(table_name).where("id = ?", [1]).if_exists().execute(scylla) | ||
res = await scylla.execute(f"SELECT * FROM {table_name}") | ||
assert not res.all() | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_custom_if(scylla: Scylla) -> None: | ||
table_name = random_string(4) | ||
await scylla.execute(f"CREATE TABLE {table_name} (id INT PRIMARY KEY, name TEXT)") | ||
await scylla.execute( | ||
f"INSERT INTO {table_name}(id, name) VALUES (?, ?)", [1, "meme"] | ||
) | ||
await Delete(table_name).where("id = ?", [1]).if_("name != ?", [None]).execute( | ||
scylla | ||
) | ||
res = await scylla.execute(f"SELECT * FROM {table_name}") | ||
assert not res.all() | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_custom_custom_if(scylla: Scylla) -> None: | ||
table_name = random_string(4) | ||
await scylla.execute(f"CREATE TABLE {table_name} (id INT PRIMARY KEY, name TEXT)") | ||
await scylla.execute( | ||
f"INSERT INTO {table_name}(id, name) VALUES (?, ?)", [1, "meme"] | ||
) | ||
await Delete(table_name).where("id = ?", [1]).if_("name != ?", [None]).execute( | ||
scylla | ||
) | ||
res = await scylla.execute(f"SELECT * FROM {table_name}") | ||
assert not res.all() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pytest | ||
from scyllapy import Scylla | ||
from scyllapy.query_builder import Insert | ||
from tests.utils import random_string | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_insert_success(scylla: Scylla) -> None: | ||
table_name = random_string(4) | ||
await scylla.execute(f"CREATE TABLE {table_name} (id INT PRIMARY KEY, name TEXT)") | ||
await Insert(table_name).set("id", 1).set("name", "random").execute(scylla) | ||
result = await scylla.execute(f"SELECT * FROM {table_name}") | ||
assert result.all() == [{"id": 1, "name": "random"}] | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_insert_if_not_exists(scylla: Scylla) -> None: | ||
table_name = random_string(4) | ||
await scylla.execute(f"CREATE TABLE {table_name} (id INT PRIMARY KEY, name TEXT)") | ||
await Insert(table_name).set("id", 1).set("name", "random").execute(scylla) | ||
await Insert(table_name).set("id", 1).set( | ||
"name", | ||
"random2", | ||
).if_not_exists().execute(scylla) | ||
res = await scylla.execute(f"SELECT * FROM {table_name}") | ||
assert res.all() == [{"id": 1, "name": "random"}] | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_insert_request_params(scylla: Scylla) -> None: | ||
table_name = random_string(4) | ||
await scylla.execute(f"CREATE TABLE {table_name} (id INT PRIMARY KEY, name TEXT)") | ||
await Insert(table_name).set("id", 1).set("name", "random").execute(scylla) | ||
res = ( | ||
await Insert(table_name) | ||
.set("id", 1) | ||
.set("name", "random2") | ||
.request_params( | ||
tracing=True, | ||
) | ||
.execute(scylla) | ||
) | ||
assert res.trace_id |
Oops, something went wrong.