diff --git a/stubs/cysqlite/@tests/stubtest_allowlist.txt b/stubs/cysqlite/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..8b38570b67ba --- /dev/null +++ b/stubs/cysqlite/@tests/stubtest_allowlist.txt @@ -0,0 +1,3 @@ +cysqlite._cysqlite.__test__ +cysqlite._cysqlite.__reduce_cython__ +cysqlite._cysqlite.__setstate_cython__ diff --git a/stubs/cysqlite/METADATA.toml b/stubs/cysqlite/METADATA.toml new file mode 100644 index 000000000000..f7e4140b2f8a --- /dev/null +++ b/stubs/cysqlite/METADATA.toml @@ -0,0 +1,2 @@ +version = "0.2.*" +upstream_repository = "https://github.com/coleifer/cysqlite" diff --git a/stubs/cysqlite/cysqlite/__init__.pyi b/stubs/cysqlite/cysqlite/__init__.pyi new file mode 100644 index 000000000000..6977772cb0fb --- /dev/null +++ b/stubs/cysqlite/cysqlite/__init__.pyi @@ -0,0 +1,27 @@ +from typing import Final + +from ._constants import * +from ._cysqlite import ( + Blob as Blob, + Connection as Connection, + Row as Row, + TableFunction as TableFunction, + compile_option as compile_option, + connect as connect, + damerau_levenshtein_dist as damerau_levenshtein_dist, + levenshtein_dist as levenshtein_dist, + median as median, + rank_bm25 as rank_bm25, + rank_lucene as rank_lucene, + sqlite_version as sqlite_version, + sqlite_version_info as sqlite_version_info, + status as status, + threadsafety as threadsafety, +) +from .exceptions import * + +version: Final[str] +__version__: Final[str] +version_info: Final[tuple[int, int, int]] +apilevel: Final = "2.0" +paramstyle: Final = "qmark" diff --git a/stubs/cysqlite/cysqlite/_constants.pyi b/stubs/cysqlite/cysqlite/_constants.pyi new file mode 100644 index 000000000000..40aae4fcb2d3 --- /dev/null +++ b/stubs/cysqlite/cysqlite/_constants.pyi @@ -0,0 +1,189 @@ +from typing import Final + +SQLITE_ABORT: Final[int] +SQLITE_ALTER_TABLE: Final[int] +SQLITE_ANALYZE: Final[int] +SQLITE_ATTACH: Final[int] +SQLITE_AUTH: Final[int] +SQLITE_BUSY: Final[int] +SQLITE_CANTOPEN: Final[int] +SQLITE_CHECKPOINT_FULL: Final[int] +SQLITE_CHECKPOINT_PASSIVE: Final[int] +SQLITE_CHECKPOINT_RESTART: Final[int] +SQLITE_CHECKPOINT_TRUNCATE: Final[int] +SQLITE_CONSTRAINT: Final[int] +SQLITE_COPY: Final[int] +SQLITE_CORRUPT: Final[int] +SQLITE_CREATE_INDEX: Final[int] +SQLITE_CREATE_TABLE: Final[int] +SQLITE_CREATE_TEMP_INDEX: Final[int] +SQLITE_CREATE_TEMP_TABLE: Final[int] +SQLITE_CREATE_TEMP_TRIGGER: Final[int] +SQLITE_CREATE_TEMP_VIEW: Final[int] +SQLITE_CREATE_TRIGGER: Final[int] +SQLITE_CREATE_VIEW: Final[int] +SQLITE_CREATE_VTABLE: Final[int] +SQLITE_DBCONFIG_DEFENSIVE: Final[int] +SQLITE_DBCONFIG_DQS_DDL: Final[int] +SQLITE_DBCONFIG_DQS_DML: Final[int] +SQLITE_DBCONFIG_ENABLE_FKEY: Final[int] +SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER: Final[int] +SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION: Final[int] +SQLITE_DBCONFIG_ENABLE_QPSG: Final[int] +SQLITE_DBCONFIG_ENABLE_TRIGGER: Final[int] +SQLITE_DBCONFIG_ENABLE_VIEW: Final[int] +SQLITE_DBCONFIG_LEGACY_ALTER_TABLE: Final[int] +SQLITE_DBCONFIG_LEGACY_FILE_FORMAT: Final[int] +SQLITE_DBCONFIG_MAINDBNAME: Final[int] +SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE: Final[int] +SQLITE_DBCONFIG_RESET_DATABASE: Final[int] +SQLITE_DBCONFIG_TRIGGER_EQP: Final[int] +SQLITE_DBCONFIG_TRUSTED_SCHEMA: Final[int] +SQLITE_DBCONFIG_WRITABLE_SCHEMA: Final[int] +SQLITE_DBSTATUS_CACHE_HIT: Final[int] +SQLITE_DBSTATUS_CACHE_MISS: Final[int] +SQLITE_DBSTATUS_CACHE_USED: Final[int] +SQLITE_DBSTATUS_CACHE_WRITE: Final[int] +SQLITE_DBSTATUS_DEFERRED_FKS: Final[int] +SQLITE_DBSTATUS_LOOKASIDE_HIT: Final[int] +SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: Final[int] +SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE: Final[int] +SQLITE_DBSTATUS_LOOKASIDE_USED: Final[int] +SQLITE_DBSTATUS_SCHEMA_USED: Final[int] +SQLITE_DBSTATUS_STMT_USED: Final[int] +SQLITE_DELETE: Final[int] +SQLITE_DENY: Final[int] +SQLITE_DETACH: Final[int] +SQLITE_DONE: Final[int] +SQLITE_DROP_INDEX: Final[int] +SQLITE_DROP_TABLE: Final[int] +SQLITE_DROP_TEMP_INDEX: Final[int] +SQLITE_DROP_TEMP_TABLE: Final[int] +SQLITE_DROP_TEMP_TRIGGER: Final[int] +SQLITE_DROP_TEMP_VIEW: Final[int] +SQLITE_DROP_TRIGGER: Final[int] +SQLITE_DROP_VIEW: Final[int] +SQLITE_DROP_VTABLE: Final[int] +SQLITE_EMPTY: Final[int] +SQLITE_ERROR: Final[int] +SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: Final[int] +SQLITE_FCNTL_BUSYHANDLER: Final[int] +SQLITE_FCNTL_CHUNK_SIZE: Final[int] +SQLITE_FCNTL_CKPT_DONE: Final[int] +SQLITE_FCNTL_CKPT_START: Final[int] +SQLITE_FCNTL_CKSM_FILE: Final[int] +SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: Final[int] +SQLITE_FCNTL_COMMIT_PHASETWO: Final[int] +SQLITE_FCNTL_DATA_VERSION: Final[int] +SQLITE_FCNTL_EXTERNAL_READER: Final[int] +SQLITE_FCNTL_FILE_POINTER: Final[int] +SQLITE_FCNTL_GET_LOCKPROXYFILE: Final[int] +SQLITE_FCNTL_HAS_MOVED: Final[int] +SQLITE_FCNTL_JOURNAL_POINTER: Final[int] +SQLITE_FCNTL_LAST_ERRNO: Final[int] +SQLITE_FCNTL_LOCKSTATE: Final[int] +SQLITE_FCNTL_LOCK_TIMEOUT: Final[int] +SQLITE_FCNTL_MMAP_SIZE: Final[int] +SQLITE_FCNTL_NULL_IO: Final[int] +SQLITE_FCNTL_OVERWRITE: Final[int] +SQLITE_FCNTL_PDB: Final[int] +SQLITE_FCNTL_PERSIST_WAL: Final[int] +SQLITE_FCNTL_POWERSAFE_OVERWRITE: Final[int] +SQLITE_FCNTL_PRAGMA: Final[int] +SQLITE_FCNTL_RBU: Final[int] +SQLITE_FCNTL_RESERVE_BYTES: Final[int] +SQLITE_FCNTL_RESET_CACHE: Final[int] +SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: Final[int] +SQLITE_FCNTL_SET_LOCKPROXYFILE: Final[int] +SQLITE_FCNTL_SIZE_HINT: Final[int] +SQLITE_FCNTL_SIZE_LIMIT: Final[int] +SQLITE_FCNTL_SYNC: Final[int] +SQLITE_FCNTL_SYNC_OMITTED: Final[int] +SQLITE_FCNTL_TEMPFILENAME: Final[int] +SQLITE_FCNTL_TRACE: Final[int] +SQLITE_FCNTL_VFSNAME: Final[int] +SQLITE_FCNTL_VFS_POINTER: Final[int] +SQLITE_FCNTL_WAL_BLOCK: Final[int] +SQLITE_FCNTL_WIN32_AV_RETRY: Final[int] +SQLITE_FCNTL_WIN32_GET_HANDLE: Final[int] +SQLITE_FCNTL_WIN32_SET_HANDLE: Final[int] +SQLITE_FCNTL_ZIPVFS: Final[int] +SQLITE_FORMAT: Final[int] +SQLITE_FULL: Final[int] +SQLITE_FUNCTION: Final[int] +SQLITE_IGNORE: Final[int] +SQLITE_INSERT: Final[int] +SQLITE_INTERNAL: Final[int] +SQLITE_INTERRUPT: Final[int] +SQLITE_IOERR: Final[int] +SQLITE_LIMIT_ATTACHED: Final[int] +SQLITE_LIMIT_COLUMN: Final[int] +SQLITE_LIMIT_COMPOUND_SELECT: Final[int] +SQLITE_LIMIT_EXPR_DEPTH: Final[int] +SQLITE_LIMIT_FUNCTION_ARG: Final[int] +SQLITE_LIMIT_LENGTH: Final[int] +SQLITE_LIMIT_LIKE_PATTERN_LENGTH: Final[int] +SQLITE_LIMIT_SQL_LENGTH: Final[int] +SQLITE_LIMIT_TRIGGER_DEPTH: Final[int] +SQLITE_LIMIT_VARIABLE_NUMBER: Final[int] +SQLITE_LIMIT_VDBE_OP: Final[int] +SQLITE_LIMIT_WORKER_THREADS: Final[int] +SQLITE_LOCKED: Final[int] +SQLITE_MISMATCH: Final[int] +SQLITE_MISUSE: Final[int] +SQLITE_NOLFS: Final[int] +SQLITE_NOMEM: Final[int] +SQLITE_NOTADB: Final[int] +SQLITE_NOTFOUND: Final[int] +SQLITE_OK: Final[int] +SQLITE_OPEN_AUTOPROXY: Final[int] +SQLITE_OPEN_CREATE: Final[int] +SQLITE_OPEN_DELETEONCLOSE: Final[int] +SQLITE_OPEN_EXCLUSIVE: Final[int] +SQLITE_OPEN_FULLMUTEX: Final[int] +SQLITE_OPEN_MAIN_DB: Final[int] +SQLITE_OPEN_MAIN_JOURNAL: Final[int] +SQLITE_OPEN_MASTER_JOURNAL: Final[int] +SQLITE_OPEN_MEMORY: Final[int] +SQLITE_OPEN_NOMUTEX: Final[int] +SQLITE_OPEN_PRIVATECACHE: Final[int] +SQLITE_OPEN_READONLY: Final[int] +SQLITE_OPEN_READWRITE: Final[int] +SQLITE_OPEN_SHAREDCACHE: Final[int] +SQLITE_OPEN_SUBJOURNAL: Final[int] +SQLITE_OPEN_TEMP_DB: Final[int] +SQLITE_OPEN_TEMP_JOURNAL: Final[int] +SQLITE_OPEN_TRANSIENT_DB: Final[int] +SQLITE_OPEN_URI: Final[int] +SQLITE_OPEN_WAL: Final[int] +SQLITE_PERM: Final[int] +SQLITE_PRAGMA: Final[int] +SQLITE_PROTOCOL: Final[int] +SQLITE_RANGE: Final[int] +SQLITE_READ: Final[int] +SQLITE_READONLY: Final[int] +SQLITE_RECURSIVE: Final[int] +SQLITE_REINDEX: Final[int] +SQLITE_ROW: Final[int] +SQLITE_SAVEPOINT: Final[int] +SQLITE_SCHEMA: Final[int] +SQLITE_SELECT: Final[int] +SQLITE_STATUS_MALLOC_COUNT: Final[int] +SQLITE_STATUS_MALLOC_SIZE: Final[int] +SQLITE_STATUS_MEMORY_USED: Final[int] +SQLITE_STATUS_PAGECACHE_OVERFLOW: Final[int] +SQLITE_STATUS_PAGECACHE_SIZE: Final[int] +SQLITE_STATUS_PAGECACHE_USED: Final[int] +SQLITE_STATUS_PARSER_STACK: Final[int] +SQLITE_STATUS_SCRATCH_OVERFLOW: Final[int] +SQLITE_STATUS_SCRATCH_SIZE: Final[int] +SQLITE_STATUS_SCRATCH_USED: Final[int] +SQLITE_TOOBIG: Final[int] +SQLITE_TRACE_CLOSE: Final[int] +SQLITE_TRACE_PROFILE: Final[int] +SQLITE_TRACE_ROW: Final[int] +SQLITE_TRACE_STMT: Final[int] +SQLITE_TRANSACTION: Final[int] +SQLITE_UPDATE: Final[int] +SQLITE_VERSION: Final[str] +SQLITE_VERSION_NUMBER: Final[int] diff --git a/stubs/cysqlite/cysqlite/_cysqlite.pyi b/stubs/cysqlite/cysqlite/_cysqlite.pyi new file mode 100644 index 000000000000..f3fb8c850fbf --- /dev/null +++ b/stubs/cysqlite/cysqlite/_cysqlite.pyi @@ -0,0 +1,344 @@ +import types +from _typeshed import Incomplete, sentinel +from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence +from typing import Any, ClassVar, Final, Literal, NoReturn, ParamSpec, TypeAlias, TypeVar, final +from typing_extensions import Buffer, Self, disjoint_base + +from cysqlite.metadata import Column, ColumnMetadata, ForeignKey, Index, View + +_SqliteData: TypeAlias = str | Buffer | float | None +_AdaptedInputData: TypeAlias = _SqliteData | Any # There can be registered types with cysqlite. +_Parameters: TypeAlias = Sequence[_AdaptedInputData] | Mapping[str, _AdaptedInputData] +_IsolationLevel: TypeAlias = Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None +_Query: TypeAlias = Literal["INSERT", "UPDATE", "DELETE"] +_T = TypeVar("_T") +_P = ParamSpec("_P") + +HAS_COLUMN_METADATA: Final[int] +SENTINEL: Final[object] + +def compile_option(opt: str | Buffer) -> int: ... +def connect( + database: str, + flags: int | None = None, + timeout: float = 5.0, + vfs: Any | None = None, + uri: bool = False, + cached_statements: int = 100, + extensions: bool = True, + row_factory: Callable[..., Row] | None = None, + autoconnect: bool = True, + pragmas: dict[str, Any] | None = None, +) -> Connection: ... +def damerau_levenshtein_dist(s1: str, s2: str) -> int: ... +def levenshtein_dist(a: str, b: str) -> int: ... +def rank_bm25(py_match_info: Buffer, *raw_weights: int) -> float: ... +def rank_lucene(py_match_info: Buffer, *raw_weights: int) -> float: ... +def set_lookaside(size: int, slots: int) -> bool: ... +def set_mmap_size(default_size: int, max_size: int) -> bool: ... +def set_multithread() -> bool: ... +def set_serialized() -> bool: ... +def set_singlethread() -> bool: ... +def set_stmt_journal_spill(nbytes: int) -> bool: ... + +sqlite_version: Final[str] +sqlite_version_info: Final[tuple[Any, ...]] # tuple entries can be either int or str + +def status(flag: int) -> tuple[int, int]: ... + +threadsafety: Final[int] + +def vfs_list() -> list[str]: ... +@disjoint_base +class Atomic(_callable_context_manager): + txn: Transaction | Savepoint + def __init__(self, conn: Connection, lock: _IsolationLevel = None) -> None: ... + def __enter__(self) -> Transaction | Savepoint: ... + def __exit__( + self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None + ) -> bool | None: ... + def __reduce__(self) -> Any: ... + +@disjoint_base +class Blob: + closed: bool + def __init__( + self, conn: Connection, table: str, column: str, rowid: int, read_only: bool = ..., database: str | None = None + ) -> None: ... + def close(self) -> None: ... + def fileno(self) -> NoReturn: ... # it throws: _io.UnsupportedOperation + def flush(self) -> None: ... + def isatty(self) -> Literal[True]: ... + def read(self, size: int = -1) -> bytes: ... + def readable(self) -> Literal[True]: ... + def readall(self) -> bytes: ... + def readinto(self, b: Buffer) -> int: ... + def readline(self, size: int = -1) -> bytes: ... + def readlines(self, hint: int = -1) -> list[bytes]: ... + def reopen(self, rowid: int) -> None: ... + def seek(self, offset: int, whence: int = 0) -> int: ... + def seekable(self) -> Literal[True]: ... + def tell(self) -> int: ... + def truncate(self, size: int | None = None) -> NoReturn: ... + def writable(self) -> bool: ... + def write(self, data: str | Buffer) -> int: ... + def writelines(self, lines: Iterable[str | Buffer]) -> int: ... + def __delitem__(self, other: int) -> None: ... + def __enter__(self) -> Self: ... + def __exit__( + self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None + ) -> bool | None: ... + def __getitem__(self, key: int) -> bytes: ... + def __iter__(self) -> Self: ... + def __len__(self) -> int: ... + def __next__(self) -> bytes: ... + def __reduce__(self) -> Any: ... + def __setitem__(self, key: int | slice[int, int, int] | slice[int, int], value: Buffer) -> None: ... + +@final +class Connection(_callable_context_manager): + cached_statements: int + callback_error: BaseException | None + database: Incomplete + extensions: bool + flags: int + in_transaction: bool + pragmas: dict[str, Any] + print_callback_tracebacks: bool + row_factory: Callable[..., Row] | Callable[..., Any] + timeout: float + uri: bool + vfs: str + def __init__( + self, + database: str, + flags: int | None = None, + timeout: float = 5.0, + vfs: str | None = None, + uri: bool = False, + cached_statements: int = 100, + extensions: bool = True, + row_factory: Callable[..., Row] | None = None, + autoconnect: bool = True, + pragmas: dict[str, Any] | None = ..., + ) -> None: ... + def adapter(self, python_type: type[Any]) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]: ... + def atomic(self, lock: _IsolationLevel | None = None) -> Atomic: ... + def attach(self, filename: str, name: str) -> None: ... + def authorizer(self, fn: Callable[[int, str, str, str], int]) -> None: ... + def autocommit(self) -> int: ... + def backup( + self, + dest: Connection, + pages: int | None = None, + name: str | None = None, + progress: Callable[[int, int, bool], None] | None = None, + src_name: str | None = None, + ) -> None: ... + def backup_to_file( + self, + filename: str, + pages: int | None = None, + name: str | None = None, + progress: Callable[[int, int, bool], None] | None = None, + src_name: str | None = None, + ) -> None: ... + def begin(self, lock: _IsolationLevel = None) -> None: ... + def blob_open(self, table: str, column: str, rowid: int, read_only: bool = False, database: str | None = None) -> Blob: ... + def changes(self) -> int: ... + def checkpoint( + self, full: bool = False, truncate: bool = False, restart: bool = False, name: str | Buffer | None = None + ) -> tuple[int, int]: ... + def close(self) -> bool: ... + def commit(self) -> None: ... + def commit_hook(self, fn: Callable[[], None]) -> None: ... + def connect(self) -> bool: ... + def converter(self, data_type: str) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]: ... + def create_aggregate( + self, agg: Callable[..., Any], name: str | Buffer | None = None, nargs: int = -1, deterministic: bool = True + ) -> None: ... + def create_collation(self, fn: Callable[[str, str], int], name: str | Buffer | None = None) -> None: ... + def create_function( + self, fn: Callable[..., Any], name: str | Buffer | None = None, nargs: int = -1, deterministic: bool = True + ) -> None: ... + def create_window_function( + self, agg: Callable[..., Any], name: str | Buffer | None = None, nargs: int = -1, deterministic: bool = True + ) -> None: ... + def cursor(self) -> Cursor: ... + def database_list(self) -> list[tuple[str, str]]: ... + def db_config(self, op: int, setting: int | None = None) -> int: ... + def detach(self, name: str) -> None: ... + def execute(self, sql: str, params: _Parameters | None = ...) -> Cursor: ... + def execute_one(self, sql: str, params: _Parameters | None = ...) -> Row | tuple[Any, ...] | None: ... + def execute_scalar(self, sql: str, params: _Parameters | None = ...) -> int | None: ... + def execute_simple(self, sql: str, callback: Callable[..., Any] | None = None) -> None: ... + def executemany(self, sql: str, seq_of_params: Sequence[_Parameters]) -> Cursor: ... + def executescript(self, sql: str) -> Cursor: ... + def file_control(self, op: int, val: int, name: str | Buffer | None = None) -> int: ... + def finalize_statements(self) -> None: ... + def get_columns(self, table: str, database: str | None = None) -> list[Column]: ... + def get_foreign_keys(self, table: str, database: str | None = None) -> list[ForeignKey]: ... + def get_foreign_keys_enabled(self) -> int: ... + def get_indexes(self, table: str, database: str | None = None) -> list[Index]: ... + def get_load_extension(self) -> int: ... + def get_primary_keys(self, table: str, database: str | None = None) -> list[str]: ... + def get_stmt_usage(self) -> tuple[int, int]: ... + def get_tables(self, database: str | None = None) -> list[str]: ... + def get_triggers_enabled(self) -> int: ... + def get_views(self, database: str | None = None) -> list[View]: ... + def getlimit(self, category: int) -> int: ... + def interrupt(self) -> None: ... + def is_closed(self) -> bool: ... + def last_insert_rowid(self) -> int: ... + def load_extension(self, name: str | Buffer) -> None: ... + def optimize( + self, + debug: bool = False, + run_tables: bool = True, + set_limit: bool = True, + check_table_sizes: bool = False, + dry_run: bool = False, + ) -> Cursor: ... + def pragma( + self, key: str, value: Any = sentinel, database: str | None = None, multi: bool = False, permanent: bool = False + ) -> None: ... + def progress(self, fn: Callable[[int, int, bool], None], n: int = 1) -> None: ... + def register_adapter(self, python_type: type[Any], fn: Callable[..., Any]) -> None: ... + def register_converter(self, data_type: str, fn: Callable[..., Any]) -> None: ... + def register_type( + self, + data_type: str | None = None, + converter: Callable[..., Any] | None = None, + python_type: type[Any] | None = None, + adapter: Callable[..., Any] | None = None, + ) -> None: ... + def rollback(self) -> None: ... + def rollback_hook(self, fn: Callable[[], object] | None) -> None: ... + def savepoint(self, sid: str | None = None) -> Savepoint: ... + def set_autocheckpoint(self, n: int) -> None: ... + def set_busy_handler(self, timeout: float = 5.0) -> None: ... + def set_foreign_keys_enabled(self, enabled: int) -> int: ... + def set_load_extension(self, enabled: int) -> int: ... + def set_main_db_name(self, name: str) -> None: ... + def set_shared_cache(self, enabled: int) -> int: ... + def set_triggers_enabled(self, enabled: int) -> int: ... + def setlimit(self, category: int, limit: int) -> int: ... + def status(self, flag: int) -> tuple[int, int]: ... + def table_column_metadata(self, table: str | bytes, column: str | bytes, database: str | None = None) -> ColumnMetadata: ... + def total_changes(self) -> int: ... + def trace(self, fn: Callable[[int, int, str, int], Any], mask: int = 2, expand_sql: bool = True) -> None: ... + def transaction(self, lock: _IsolationLevel = None) -> Transaction: ... + def unregister_adapter(self, python_type: type[Any]) -> bool: ... + def unregister_converter(self, data_type: str) -> bool: ... + def update_hook(self, fn: Callable[[_Query, str, str, int], Any] | None) -> None: ... + def __enter__(self) -> Self: ... + def __exit__( + self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None + ) -> bool | None: ... + def __reduce__(self) -> Any: ... + +@final +class Cursor: + conn: Connection + description: tuple[str, ...] + lastrowid: int | None + row_factory: Callable[..., Row] | Callable[..., Any] + rowcount: int + + def __new__(cls, conn: Connection) -> Self: ... + def close(self) -> None: ... + def columns(self) -> list[str]: ... + def execute(self, sql: str, params: _Parameters | None = None) -> Self: ... + def executemany(self, sql: str, seq_of_params: Sequence[_Parameters] | None = None) -> Self: ... + def executescript(self, sql: str) -> Self: ... + def fetchall(self) -> list[Any | tuple[Any, ...]]: ... + def fetchone(self) -> tuple[Any, ...] | None: ... + def scalar(self) -> Any | None: ... + def __enter__(self) -> Self: ... + def __exit__( + self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None + ) -> bool | None: ... + def __iter__(self) -> Self: ... + def __next__(self) -> Row | Any: ... + def __reduce__(self) -> Any: ... + +@disjoint_base +class Row: + def as_dict(self) -> dict[str, Any]: ... + def get(self, key: str | int, default: _T | None = ...) -> Any | _T | None: ... + def items(self) -> list[tuple[str, Any]]: ... + def keys(self) -> list[str]: ... + def values(self) -> list[Any]: ... + def __contains__(self, key: str | int) -> bool: ... + def __eq__(self, other: object) -> bool: ... + def __ge__(self, other: object) -> bool: ... + def __getattr__(self, name: str) -> Any: ... + def __getitem__(self, key: int | str) -> Any: ... + def __gt__(self, other: object) -> bool: ... + def __hash__(self) -> int: ... + def __iter__(self) -> Iterator[Any]: ... + def __le__(self, other: object) -> bool: ... + def __len__(self) -> int: ... + def __lt__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __reduce__(self) -> Any: ... + +@disjoint_base +class Savepoint(_callable_context_manager): + def __init__(self, conn: Connection, sid: str | None = None) -> None: ... + def commit(self, begin: bool = True) -> None: ... + def rollback(self) -> None: ... + def __enter__(self) -> Self: ... + def __exit__( + self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None + ) -> bool | None: ... + def __reduce__(self) -> Any: ... + +class TableFunction: + _ncols: ClassVar[int] = ... + _nparams: ClassVar[int] = ... + columns: ClassVar[list[tuple[str, str]] | None] = ... + name: ClassVar[str | None] = ... + params: ClassVar[list[str] | None] = ... + print_tracebacks: ClassVar[bool] = ... + @classmethod + def get_table_columns_declaration(cls) -> str: ... + @classmethod + def register(cls, conn: Connection) -> None: ... + def delete(self, rowid: int) -> None: ... + # NOTE: initialize goes hand & hand with the values added to the class variable + # params SEE: https://cysqlite.readthedocs.io/en/latest/api.html#tablefunction + def initialize(self) -> None: ... + # NOTE: Values of insert can be any row of a given tuple-like object + # or Sequence hence adding both options. + def insert(self, rowid: int, values: Sequence[_AdaptedInputData] | tuple[_AdaptedInputData, ...]) -> int: ... + def iterate(self, idx: int) -> tuple[Any, ...]: ... + def update(self, old_rowid: int, new_rowid: int, values: list[Any]) -> None: ... + +@disjoint_base +class Transaction(_callable_context_manager): + def __init__(self, conn: Connection, lock: _IsolationLevel = None) -> None: ... + def commit(self, begin: bool = True) -> None: ... + def rollback(self, begin: bool = True) -> None: ... + def __enter__(self) -> Self: ... + def __exit__( + self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None + ) -> bool | None: ... + def __reduce__(self) -> Any: ... + +class _callable_context_manager: + def __call__(self, fn: Callable[_P, _T]) -> Callable[_P, _T]: ... + def __reduce__(self) -> Any: ... + def __reduce_cython__(self) -> Any: ... + def __setstate_cython__(self, __pyx_state: Any, /) -> None: ... + +@disjoint_base +class median: + def __init__(self, *args: Any) -> None: ... + def finalize(self) -> float: ... + def inverse(self, item: float) -> None: ... + def step(self, item: float) -> None: ... + def value(self) -> float: ... + def __reduce__(self) -> Any: ... + def __reduce_cython__(self) -> Any: ... + def __setstate_cython__(self, __pyx_state: Any, /) -> None: ... diff --git a/stubs/cysqlite/cysqlite/aio.pyi b/stubs/cysqlite/cysqlite/aio.pyi new file mode 100644 index 000000000000..6440e85a4e1f --- /dev/null +++ b/stubs/cysqlite/cysqlite/aio.pyi @@ -0,0 +1,111 @@ +import asyncio +import queue +import types +from collections.abc import Callable, Mapping, Sequence +from typing import Any, Final, Literal, TypeAlias, TypedDict, type_check_only +from typing_extensions import Buffer, Self, Unpack + +from ._cysqlite import Atomic, Connection, Cursor, Row, Savepoint, Transaction + +_SqliteData: TypeAlias = str | Buffer | int | float | None +_AdaptedInputData: TypeAlias = _SqliteData | Any +_Parameters: TypeAlias = Sequence[_AdaptedInputData] | Mapping[str, _AdaptedInputData] +_IsolationLevel: TypeAlias = Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None + +@type_check_only +class _BackupKwargs(TypedDict, total=False): + pages: int | None + name: str | None + progress: Callable[[int, int, bool], None] | None + src_name: str | None + +@type_check_only +class _ConnectKwargs(TypedDict, total=False): + flags: int | None + timeout: float + vfs: Any | None + uri: bool + cached_statements: int + extensions: bool + row_factory: Callable[..., Row] | Callable[..., Any] | None + autoconnect: bool + pragmas: dict[str, Any] | None + +@type_check_only +class _CheckPointKwargs(TypedDict, total=False): + full: bool + truncate: bool + restart: bool + name: str | Buffer | None + +SHUTDOWN: Final[object] + +class AsyncConnection: + conn: Connection + loop: asyncio.AbstractEventLoop + queue: queue.SimpleQueue[tuple[Callable[[], Any]]] + def __init__(self, conn: Connection, loop: asyncio.AbstractEventLoop) -> None: ... + def __del__(self) -> None: ... + async def execute(self, sql: str, params: _Parameters | None = None) -> AsyncCursor: ... + async def executemany(self, sql: str, seq_of_params: Sequence[_Parameters]) -> AsyncCursor: ... + async def executescript(self, sql: str) -> AsyncCursor: ... + async def execute_one(self, sql: str, params: _Parameters | None = None) -> Row | tuple[Any, ...] | None: ... + async def execute_scalar(self, sql: str, params: _Parameters | None = None) -> int: ... + async def commit(self) -> None: ... + async def rollback(self) -> None: ... + async def close(self) -> bool | None: ... + async def last_insert_rowid(self) -> int: ... + async def backup(self, dest: AsyncConnection, **kwargs: Unpack[_BackupKwargs]) -> None: ... + async def backup_to_file(self, filename: str, **kwargs: Unpack[_BackupKwargs]) -> None: ... + async def checkpoint(self, **kwargs: Unpack[_CheckPointKwargs]) -> tuple[int, int]: ... + def transaction(self, lock: _IsolationLevel | None = None) -> AsyncTransaction: ... + def savepoint(self, sid: str | None = None) -> AsyncSavepoint: ... + def atomic(self, lock: str | _IsolationLevel | None = None) -> AsyncAtomic: ... + @property + def in_transaction(self) -> bool: ... + # pragma is the exact same as it's backend. + def pragma(self, key: str, value: Any = ..., database: str | None = None, multi: bool = False) -> None: ... + async def __aenter__(self) -> Self: ... + async def __aexit__( + self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None + ) -> None: ... + +class AsyncCursor: + conn: Connection + def __init__(self, conn: AsyncConnection, cursor: Cursor) -> None: ... + async def fetchone(self) -> tuple[Any, ...] | None: ... + async def fetchall(self) -> list[Any | tuple[Any, ...]]: ... + async def scalar(self) -> int: ... + @property + def description(self) -> tuple[Any, ...]: ... + @property + def lastrowid(self) -> int: ... + @property + def rowcount(self) -> int: ... + def __aiter__(self) -> Self: ... + async def fetchmany(self, size: int = 100, constructor: type[Sequence[Row | Any]] = ...) -> Sequence[Row | Any]: ... + async def __anext__(self) -> Row | Any: ... + +class _AsyncTransactionWrapper: + conn: AsyncConnection + def __init__(self, conn: AsyncConnection, *args: Any) -> None: ... + def get_wrapper(self) -> Any: ... + async def __aenter__(self) -> Self: ... + async def __aexit__( + self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None + ) -> None: ... + async def commit(self, *args: Any) -> None: ... + async def rollback(self, *args: Any) -> None: ... + +class AsyncTransaction(_AsyncTransactionWrapper): + def get_wrapper(self) -> Transaction: ... + +class AsyncSavepoint(_AsyncTransactionWrapper): + def get_wrapper(self) -> Savepoint: ... + +class AsyncAtomic(_AsyncTransactionWrapper): + def get_wrapper(self) -> Atomic: ... + async def commit(self, *args: Any) -> None: ... + async def rollback(self, *args: Any) -> None: ... + +def connect(database: str, **kwargs: Unpack[_ConnectKwargs]) -> AsyncConnection: ... diff --git a/stubs/cysqlite/cysqlite/exceptions.pyi b/stubs/cysqlite/cysqlite/exceptions.pyi new file mode 100644 index 000000000000..6f347f1ca711 --- /dev/null +++ b/stubs/cysqlite/cysqlite/exceptions.pyi @@ -0,0 +1,11 @@ +class SqliteError(Exception): ... +class Error(SqliteError): ... +class Warning(SqliteError): ... +class InterfaceError(Error): ... +class DatabaseError(Error): ... +class DataError(DatabaseError): ... +class OperationalError(DatabaseError): ... +class IntegrityError(DatabaseError): ... +class InternalError(DatabaseError): ... +class ProgrammingError(DatabaseError): ... +class NotSupportedError(DatabaseError): ... diff --git a/stubs/cysqlite/cysqlite/metadata.pyi b/stubs/cysqlite/cysqlite/metadata.pyi new file mode 100644 index 000000000000..05b5b3363086 --- /dev/null +++ b/stubs/cysqlite/cysqlite/metadata.pyi @@ -0,0 +1,36 @@ +from typing import Any, NamedTuple +from typing_extensions import Buffer + +class Index(NamedTuple): + name: str + sql: str + columns: list[str] + unique: bool + table: str + +class Column(NamedTuple): + name: str + data_type: str + null: bool + primary_key: bool + table: str + default: Any | None + +class ForeignKey(NamedTuple): + column: str + dest_table: str + dest_column: str + table: str + +class View(NamedTuple): + name: str + sql: str + +class ColumnMetadata(NamedTuple): + table: str | Buffer + column: str | Buffer + datatype: str + collation: str + not_null: bool + primary_key: bool + auto_increment: bool diff --git a/stubs/cysqlite/cysqlite/utils.pyi b/stubs/cysqlite/cysqlite/utils.pyi new file mode 100644 index 000000000000..79a8496852a2 --- /dev/null +++ b/stubs/cysqlite/cysqlite/utils.pyi @@ -0,0 +1,7 @@ +from typing import Literal + +from ._cysqlite import Connection + +def slow_query_log( + conn: Connection, threshold_ms: int = 50, logger: str | None = None, level: int = 30, expand_sql: bool = True +) -> Literal[True]: ...