diff --git a/.changes/unreleased/Added-20260718-120000.yaml b/.changes/unreleased/Added-20260718-120000.yaml new file mode 100644 index 00000000..53409427 --- /dev/null +++ b/.changes/unreleased/Added-20260718-120000.yaml @@ -0,0 +1,6 @@ +kind: Added +body: Support for PostgreSQL enums - enum columns now generate an `enums.py` module with `str`-based enum classes, including schema-qualified naming and runtime value coercion +time: 2026-07-18T12:00:00.0000000Z +custom: + Author: rayakame + PR: "148" diff --git a/.changes/unreleased/Added-20260718-120001.yaml b/.changes/unreleased/Added-20260718-120001.yaml new file mode 100644 index 00000000..73541b83 --- /dev/null +++ b/.changes/unreleased/Added-20260718-120001.yaml @@ -0,0 +1,6 @@ +kind: Added +body: New `model_type` option `pydantic` generating `pydantic.BaseModel` models (requires pydantic >= 2.9) +time: 2026-07-18T12:00:01.0000000Z +custom: + Author: rayakame + PR: "148" diff --git a/.changes/unreleased/Added-20260718-120002.yaml b/.changes/unreleased/Added-20260718-120002.yaml new file mode 100644 index 00000000..4b8f92bb --- /dev/null +++ b/.changes/unreleased/Added-20260718-120002.yaml @@ -0,0 +1,6 @@ +kind: Added +body: '`query_parameter_limit` is now implemented and opt-in: when set to a non-negative value, queries with more parameters than the limit take a single `params: Params` argument; unset or negative values keep parameters expanded' +time: 2026-07-18T12:00:02.0000000Z +custom: + Author: rayakame + PR: "148" diff --git a/.changes/unreleased/Breaking-20251210-092132.yaml b/.changes/unreleased/Breaking-20251210-092132.yaml index c83b8042..e2287562 100644 --- a/.changes/unreleased/Breaking-20251210-092132.yaml +++ b/.changes/unreleased/Breaking-20251210-092132.yaml @@ -1,5 +1,5 @@ kind: Breaking -body: Config option `driver` is now required instead of defaulting to asyncpg +body: Config option `sql_driver` is now required instead of defaulting to asyncpg time: 2025-12-10T09:21:32.2253488Z custom: Author: rayakame diff --git a/.changes/unreleased/Breaking-20260718-120003.yaml b/.changes/unreleased/Breaking-20260718-120003.yaml new file mode 100644 index 00000000..a0c27638 --- /dev/null +++ b/.changes/unreleased/Breaking-20260718-120003.yaml @@ -0,0 +1,6 @@ +kind: Breaking +body: Model and row class fields now escape reserved names like function parameters already did - a column named `id` generates the field `id_` +time: 2026-07-18T12:00:03.0000000Z +custom: + Author: rayakame + PR: "148" diff --git a/.changes/unreleased/Breaking-20260719-120000.yaml b/.changes/unreleased/Breaking-20260719-120000.yaml new file mode 100644 index 00000000..c5fefa47 --- /dev/null +++ b/.changes/unreleased/Breaking-20260719-120000.yaml @@ -0,0 +1,6 @@ +kind: Breaking +body: 'Generated code now requires Python 3.12+. Type aliases use the lazy PEP 695 `type` statement (which also makes them safe at module level with `omit_typechecking_block`), `QueryResults` uses PEP 695 generic-class syntax, and enums subclass `enum.StrEnum` instead of `(str, enum.Enum)`' +time: 2026-07-19T12:00:00.0000000Z +custom: + Author: rayakame + PR: "148" diff --git a/.changes/unreleased/Changed-20260718-120004.yaml b/.changes/unreleased/Changed-20260718-120004.yaml new file mode 100644 index 00000000..7d5ae8f2 --- /dev/null +++ b/.changes/unreleased/Changed-20260718-120004.yaml @@ -0,0 +1,6 @@ +kind: Changed +body: Complete rewrite of the code generator internals into a config/transform/render/driver pipeline +time: 2026-07-18T12:00:04.0000000Z +custom: + Author: rayakame + PR: "148" diff --git a/.changes/unreleased/Fixed-20260718-120006.yaml b/.changes/unreleased/Fixed-20260718-120006.yaml new file mode 100644 index 00000000..380a6caf --- /dev/null +++ b/.changes/unreleased/Fixed-20260718-120006.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: '`:many` query functions no longer subscript the generic at runtime (`QueryResults(...)` instead of `QueryResults[T](...)`). The subscripted call went through `typing`''s `_GenericAlias.__call__` and raised-and-swallowed an `AttributeError` on every invocation (the class uses `__slots__`, so `__orig_class__` was never actually stored), costing roughly 10x the plain constructor call while providing no runtime or type-checking benefit - the function''s return annotation already carries the full `QueryResults[T]` type' +time: 2026-07-18T12:00:06.0000000Z +custom: + Author: rayakame + PR: "148" diff --git a/.changes/unreleased/Fixed-20260719-090000.yaml b/.changes/unreleased/Fixed-20260719-090000.yaml new file mode 100644 index 00000000..4a2dd0dd --- /dev/null +++ b/.changes/unreleased/Fixed-20260719-090000.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: 'sqlite modules now register only the conversion halves they need: parameters register an adapter, non-overridden return columns register a converter. Previously every used conversion type registered both, so a module could install a global `register_converter` as a side effect - changing what overridden return columns receive under `PARSE_DECLTYPES`. Import resolution follows the same split: `ciso8601` is imported exactly when an emitted converter body references it, `datetime`/`decimal` stay in the `TYPE_CHECKING` block when the emitted setup does not reference them at runtime, and `from import enums` is now also emitted when an overridden enum parameter is converted back via `enums.X(...)` at runtime' +time: 2026-07-19T09:00:00.0000000Z +custom: + Author: rayakame + PR: "148" diff --git a/.changes/unreleased/Fixed-20260719-120001.yaml b/.changes/unreleased/Fixed-20260719-120001.yaml new file mode 100644 index 00000000..5c1631af --- /dev/null +++ b/.changes/unreleased/Fixed-20260719-120001.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: 'Type overrides now convert correctly in every position: array parameters convert element-wise instead of passing the whole list into the driver-type constructor, and `:copyfrom` records convert overridden columns back to the driver type before `copy_records_to_table` (previously the raw override value was sent and failed to encode)' +time: 2026-07-19T12:00:01.0000000Z +custom: + Author: rayakame + PR: "148" diff --git a/.changes/unreleased/Fixed-20260719-120002.yaml b/.changes/unreleased/Fixed-20260719-120002.yaml new file mode 100644 index 00000000..9712c6a7 --- /dev/null +++ b/.changes/unreleased/Fixed-20260719-120002.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: 'sqlite SQL type names are now matched case-insensitively and with precision suffixes: a column declared `DATETIME` registers its adapter/converter pair (previously it was silently skipped and returned raw strings under `PARSE_DECLTYPES`), and `decimal(10,2)` is annotated `decimal.Decimal` instead of `typing.Any`' +time: 2026-07-19T12:00:02.0000000Z +custom: + Author: rayakame + PR: "148" diff --git a/.changes/unreleased/Fixed-20260719-120003.yaml b/.changes/unreleased/Fixed-20260719-120003.yaml new file mode 100644 index 00000000..e02a21ed --- /dev/null +++ b/.changes/unreleased/Fixed-20260719-120003.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: 'A SQL column named `conn` (or `self` with `emit_classes`) no longer generates a duplicate function parameter (a `SyntaxError` in the generated module); the parameter is renamed `conn_2`. `:many` query functions with array parameters now type-check: `QueryResultsArgsType` gained a `Sequence` member. The `:execrows` docstring on the sqlite3 driver now correctly documents `-1` for non-DML statements' +time: 2026-07-19T12:00:03.0000000Z +custom: + Author: rayakame + PR: "148" diff --git a/.changes/unreleased/Fixed-20260719-120004.yaml b/.changes/unreleased/Fixed-20260719-120004.yaml new file mode 100644 index 00000000..1d7ebb93 --- /dev/null +++ b/.changes/unreleased/Fixed-20260719-120004.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: '`omit_typechecking_block: true` no longer crashes generated asyncpg modules at import time: the `ConnectionLike` alias is lazy (PEP 695), module-level import order satisfies E402, and `typing` is only imported where it is actually referenced. `models.py` is emitted even when all models are filtered out, matching v0.4.x. `inflection_exclude_table_names` entries match both the bare and the schema-qualified table name (v0.4.x only matched the qualified form)' +time: 2026-07-19T12:00:04.0000000Z +custom: + Author: rayakame + PR: "148" diff --git a/.coderabbit.yaml b/.coderabbit.yaml new file mode 100644 index 00000000..b95000fe --- /dev/null +++ b/.coderabbit.yaml @@ -0,0 +1,263 @@ +language: en-US +tone_instructions: '' +early_access: false +enable_free_tier: true +inheritance: false +reviews: + profile: assertive + request_changes_workflow: false + high_level_summary: true + high_level_summary_instructions: '' + high_level_summary_placeholder: '`@coderabbitai` summary' + high_level_summary_in_walkthrough: false + auto_title_placeholder: '`@coderabbitai`' + auto_title_instructions: '' + review_status: true + review_details: false + review_progress: true + commit_status: true + fail_commit_status: false + collapse_walkthrough: true + changed_files_summary: true + sequence_diagrams: true + estimate_code_review_effort: true + assess_linked_issues: true + related_issues: true + related_prs: true + suggested_labels: true + labeling_instructions: [] + mutually_exclusive_groups: {} + auto_apply_labels: false + suggested_reviewers: true + auto_assign_reviewers: false + suggested_reviewers_instructions: [] + in_progress_fortune: true + poem: false + enable_prompt_for_ai_agents: true + path_filters: + - "!test/driver_*/*/classes/**" + - "!test/driver_*/*/functions/**" + - "!**/*.wasm" + path_instructions: [] + abort_on_close: true + disable_cache: false + slop_detection: + enabled: true + auto_review: + enabled: true + description_keyword: '' + auto_incremental_review: true + auto_pause_after_reviewed_commits: 5 + ignore_title_keywords: [] + labels: [] + drafts: false + base_branches: [] + ignore_usernames: [] + finishing_touches: + docstrings: + enabled: true + unit_tests: + enabled: false + simplify: + enabled: false + autofix: + enabled: true + fix_ci: + enabled: true + resolve_merge_conflict: + enabled: true + custom: [] + pre_merge_checks: + override_requested_reviewers_only: false + docstrings: + mode: warning + threshold: 80 + title: + mode: warning + requirements: '' + description: + mode: warning + issue_assessment: + mode: warning + custom_checks: [] + post_merge_actions: [] + tools: + ast-grep: + rule_dirs: [] + util_dirs: [] + essential_rules: true + packages: [] + shellcheck: + enabled: true + ruff: + enabled: true + markdownlint: + enabled: true + github-checks: + enabled: true + timeout_ms: 90000 + languagetool: + enabled: true + enabled_rules: [] + disabled_rules: [] + enabled_categories: [] + disabled_categories: [] + enabled_only: false + level: default + biome: + enabled: true + hadolint: + enabled: true + swiftlint: + enabled: true + phpstan: + enabled: true + level: default + phpmd: + enabled: true + phpcs: + enabled: true + golangci-lint: + enabled: true + yamllint: + enabled: true + gitleaks: + enabled: true + trufflehog: + enabled: true + checkov: + enabled: true + tflint: + enabled: true + detekt: + enabled: true + eslint: + enabled: true + e18e: + enabled: true + flake8: + enabled: false + fbinfer: + enabled: true + enable_java: false + fortitudeLint: + enabled: true + rubocop: + enabled: true + buf: + enabled: true + regal: + enabled: true + actionlint: + enabled: true + zizmor: + enabled: true + pmd: + enabled: true + clang: + enabled: true + cppcheck: + enabled: true + opengrep: + enabled: true + semgrep: + enabled: true + circleci: + enabled: true + clippy: + enabled: true + sqlfluff: + enabled: false + squawk: + enabled: true + trivy: + enabled: true + prismaLint: + enabled: true + pylint: + enabled: false + oxc: + enabled: true + shopifyThemeCheck: + enabled: true + luacheck: + enabled: true + brakeman: + enabled: true + dotenvLint: + enabled: true + htmlhint: + enabled: true + stylelint: + enabled: true + checkmake: + enabled: true + osvScanner: + enabled: true + oasdiff: + enabled: true + reactDoctor: + enabled: true + presidio: + enabled: true + blinter: + enabled: true + smartyLint: + enabled: true + emberTemplateLint: + enabled: true + skillspector: + enabled: true + psscriptanalyzer: + enabled: true +chat: + art: true + allow_non_org_members: true + auto_reply: true + integrations: + jira: + usage: auto + linear: + usage: auto +knowledge_base: + opt_out: false + web_search: + enabled: true + code_guidelines: + enabled: true + filePatterns: [] + learnings: + scope: auto + approval_delay: 0 + issues: + scope: auto + jira: + usage: auto + project_keys: [] + linear: + usage: auto + team_keys: [] + pull_requests: + scope: auto + mcp: + usage: auto + disabled_servers: [] + automatic_repository_linking: false + linked_repositories: [] +code_generation: + docstrings: + language: en-US + path_instructions: [] + unit_tests: + path_instructions: [] +issue_enrichment: + auto_enrich: + enabled: false + planning: + enabled: true + auto_planning: + enabled: true + labels: [] + labeling: + labeling_instructions: [] + auto_apply_labels: false diff --git a/.coverage b/.coverage deleted file mode 100644 index ceef134d..00000000 Binary files a/.coverage and /dev/null differ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index efa75802..9f7ab757 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: POSTGRES_PASSWORD: postgres POSTGRES_DB: testdb ports: - - 5432/tcp # host‑port is picked automatically + - 5432/tcp # host-port is picked automatically options: >- --health-cmd="pg_isready -U postgres -d testdb" --health-interval=10s @@ -36,7 +36,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ "3.10", "3.11", "3.12", "3.13" ] + python-version: [ "3.12", "3.13" ] steps: @@ -52,7 +52,7 @@ jobs: - name: Run tests via nox env: - # GitHub tells you which host‑port was assigned via the `job.services` context + # GitHub tells you which host-port was assigned via the `job.services` context POSTGRES_URI: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports['5432'] }}/testdb run: | uv run nox -s pytest -- --coverage diff --git a/.github/workflows/fragments-check.yml b/.github/workflows/fragments-check.yml index 8956ed0b..d1062ee5 100644 --- a/.github/workflows/fragments-check.yml +++ b/.github/workflows/fragments-check.yml @@ -27,13 +27,13 @@ jobs: for file in $changelog_fragments; do if grep -qE "PR: *\"?$pr_number\"?" "$file"; then - echo "✅ Found PR number $pr_number in $file" + echo "OK: Found PR number $pr_number in $file" found_match=true fi done if [ "$found_match" = false ]; then - echo "❌ No matching PR number found in changelog fragments." + echo "ERROR: No matching PR number found in changelog fragments." exit 1 fi diff --git a/.github/workflows/prepare_release.yml b/.github/workflows/prepare_release.yml index ee9abeb6..cd93aef2 100644 --- a/.github/workflows/prepare_release.yml +++ b/.github/workflows/prepare_release.yml @@ -42,10 +42,16 @@ jobs: args: latest - name: Set version + env: + NEW_VERSION: ${{ steps.latest.outputs.output }} run: | - sed -i 's/^const PluginVersion = ".*"/const PluginVersion = "'"${{ steps.latest.outputs.output }}"'"/' internal/core/config.go - - echo "✅ Updated PluginVersion to $new_version" + if ! [[ "$NEW_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "unexpected version format: $NEW_VERSION" >&2 + exit 1 + fi + sed -i 's/^const PluginVersion = ".*"/const PluginVersion = "'"$NEW_VERSION"'"/' internal/config/constants.go + + echo "OK: Updated PluginVersion to $NEW_VERSION" - name: Create Pull Request diff --git a/.gitignore b/.gitignore index 001a4cc9..0b50c772 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,21 @@ go.work.sum .env __pycache__/ + +# Python tooling caches and outputs +.venv/ +.nox/ +.pytest_cache/ +.ruff_cache/ +.coverage +coverage.xml +public/ + +# local test scratch artifacts +sqlite.db +test/log.json +test/log.txt +test/models.py +test/queries.py +test/enums.py +/sqlc-gen-better-python.wasm diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..b6ad9b22 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,174 @@ +version: "2" +linters: + # Default set of linters. + # The value can be: + # - `standard`: https://golangci-lint.run/docs/linters/#enabled-by-default + # - `all`: enables all linters by default. + # - `none`: disables all linters by default. + # - `fast`: enables only linters considered as "fast" (`golangci-lint help linters --json | jq '[ .[] | select(.fast==true) ] | map(.name)'`). + # Default: standard + default: none + enable: + - asciicheck + - bidichk + - bodyclose + - containedctx + # - contextcheck + - copyloopvar + # - cyclop + - decorder + - depguard + - dogsled + - dupl + - durationcheck + - embeddedstructfieldcheck + - errcheck + - errchkjson + - errname + - errorlint + - exhaustive + - exptostd + - fatcontext + - forbidigo + - forcetypeassert + - funcorder + - ginkgolinter + - gochecksumtype + - goconst + - gocritic + - godoclint + - godot + - godox + - gosec + - gosmopolitan + - govet + - grouper + - iface + - importas + - inamedparam + - ineffassign + - interfacebloat + - intrange + - iotamixing + - loggercheck + - makezero + - mirror + - misspell + - mnd + - musttag + - nakedret + - nestif + - nilerr + - nilnesserr + - nilnil + - nlreturn + - noctx + - nolintlint + - nonamedreturns + - nosprintfhostport + - paralleltest + - perfsprint + - prealloc + - predeclared + - reassign + - recvcheck + - rowserrcheck + - sqlclosecheck + - staticcheck + - tagalign + - tagliatelle + - tparallel + - unconvert + - unparam + - unused + - usestdlibvars + - wastedassign + - whitespace + - exhaustruct + settings: + mnd: + ignored-functions: + - '^.*NNewLine$' + exhaustruct: + # List of regular expressions to match type names that should be excluded from processing. + # Anonymous structs can be matched by '' alias. + # Has precedence over `include`. + # Each regular expression must match the full type name, including package path. + # For example, to match type `net/http.Cookie` regular expression should be `.*/http\.Cookie`, + # but not `http\.Cookie`. + # Default: [] + exclude: + # Internal IR types: literals name only meaningful fields instead of + # restating every zero value at each construction site. + - '.*/internal/model\.PyType$' + - '.*/internal/model\.QueryValue$' + - '.*/internal/model\.Column$' + - '.*/internal/render\.importSpec$' + - '.*/plugin\.Identifier$' + allow-empty: true + tagliatelle: + case: + rules: + json: snake + yaml: snake + nonamedreturns: + report-error-in-defer: true + errcheck: + check-type-assertions: true + check-blank: true + disable-default-exclusions: true + exhaustive: + default-signifies-exhaustive: true + depguard: + # Rules to apply. + # + # Variables: + # - File Variables + # Use an exclamation mark `!` to negate a variable. + # Example: `!$test` matches any file that is not a go test file. + # + # `$all` - matches all go files + # `$test` - matches all go test files + # + # - Package Variables + # + # `$gostd` - matches all of go's standard library (Pulled from `GOROOT`) + # + # Default (applies if no custom rules are defined): Only allow $gostd in all files. + rules: + main: + list-mode: strict + # List of file globs that will match this list of settings to compare against. + # By default, if a path is relative, it is relative to the directory where the golangci-lint command is executed. + # The placeholder '${base-path}' is substituted with a path relative to the mode defined with `run.relative-path-mode`. + # The placeholder '${config-path}' is substituted with a path relative to the configuration file. + # Default: $all + files: + - "$all" + - "!$test" + # List of allowed packages. + # Entries can be a variable (starting with $), a string prefix, or an exact match (if ending with $). + # Default: [] + allow: + - "$gostd" + - "github.com/sqlc-dev/plugin-sdk-go" + - "github.com/jinzhu/inflection" + - "github.com/rayakame/sqlc-gen-better-python" + - "golang.org/x/text/cases" + - "golang.org/x/text/language" +formatters: + # Enable specific formatter. + # Default: [] (uses standard Go formatting) + enable: + - gci + - swaggo + - gofmt + - gofumpt + - goimports + - golines + + settings: + golines: + max-len: 130 + chain-split-dots: false + diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..08abdec6 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,186 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Ground rules + +- NEVER add Claude as an author, co-author, or contributor to commits. No + `Co-Authored-By` trailers, no "Generated with" lines. Commits are authored + solely by the repository owner. +- NEVER commit (or push) unless explicitly told to. Finish the work, validate + it, and report; the user decides when to commit. +- Use only plain ASCII characters in everything you write (code, comments, + docs, SQL, commit messages). No em-dashes, curly quotes, arrows, or box + drawing. Non-ASCII in .sql files has corrupted sqlc's byte-offset parameter + rewriting before. + +## What this is + +A sqlc WASM plugin written in Go that generates Python database code (models + +query functions + enums) from SQL. The plugin is compiled to `wasip1/wasm` and +executed by `sqlc generate`. Supported Python drivers: `asyncpg`, `aiosqlite`, +`sqlite3`; model types: `dataclass`, `attrs`, `msgspec`, `pydantic`. + +Generated code targets Python 3.12+ (PEP 695 type aliases and generics, +`enum.StrEnum`). Generated output must be deterministic and byte-identical +across runs: CI compares committed fixtures with `sqlc diff`, checks them with +`ruff format --check`, pyright strict, and ruff, and runs runtime pytest +suites against real databases. + +## Commands + +### Go (plugin source) + +```text +make tests # go test -shuffle=on ./... +make fmt # golangci-lint fmt +make lint # golangci-lint run +make lint-fix # auto-fix a subset of linters +make pipelines # lint-fix + fmt + lint (default goal) +``` + +There is pre-existing golangci-lint debt (~40 issues); when linting your own +changes, check that no NEW issues appear in the files you touched. + +### Building the WASM plugin + +After any Go change, the plugin must be rebuilt before `sqlc generate` picks +it up: + +```text +scripts\build\build.bat # Windows (scripts/build/build.sh on Unix) +``` + +This builds with `GOOS=wasip1 GOARCH=wasm`, computes the new SHA-256, patches +the `sha256:` field in the root `sqlc.yaml` and every `test/driver_*/sqlc.yaml` +(sqlc refuses to run the plugin on a hash mismatch), and copies the `.wasm` +into each test driver directory. + +### Python (verification of generated code) + +Python tooling is uv + nox. One-time setup: `uv sync --group dev`. Requires +`sqlc` on PATH and Python >= 3.12. + +```text +uv run nox # all default sessions +uv run nox -s asyncpg # regenerate test/driver_asyncpg via sqlc, then pyright + ruff on it +uv run nox -s aiosqlite # same for aiosqlite +uv run nox -s sqlite3 # same for sqlite3 +uv run nox -s asyncpg_check # `sqlc diff` variant: verifies committed generated code is up to date (CI uses these) +uv run nox -s pyright ruff # type-check / lint the test suite itself +uv run nox -s pytest # runtime tests (needs postgres, see below) +``` + +Extra pytest args pass through after `--`, e.g. +`uv run nox -s pytest -- test/driver_asyncpg/msgspec/test_msgspec_classes.py -k test_name`. + +pytest needs a local PostgreSQL, configured via the `POSTGRES_URI` env var +(default `postgresql://root:187187@localhost:5432/root`). CONTRIBUTING.md has +a `docker run` one-liner for it. + +The full verification loop after a generator change: `go build ./...` -> +rebuild wasm -> `uv run nox` -> `uv run nox -s asyncpg_check sqlite3_check +aiosqlite_check` -> commit the regenerated fixtures together with the Go +change (when told to commit). + +### Changelog + +Every PR needs a changie fragment: `make changelog` (or `changie new`). +Fragments live in `.changes/unreleased/`. + +## Architecture + +Entry point: `plugin/main.go` -> `codegen.Run(internal.Handler)`. The whole +generation pipeline lives in `internal/handler.go`: + +1. **`internal/config`** - parses and validates plugin options from the + `GenerateRequest` (driver, model type, docstrings, overrides, ...). + Enum-like constants in `constants.go`, override matching in `overrides.go`. +2. **`internal/types`** - engine-specific SQL-type -> Python-type mapping + (`postgresql.go`, `sqlite.go`), selected by `GetTypeConversionFunc(engine)`. +3. **`internal/transform`** - turns the sqlc catalog/queries into the IR: + `BuildEnums()`, `BuildTables()`, `BuildQueries(tables)`, + `FilterUnusedModels()`. `type.go` builds `PyType` and normalizes + `SQLType` (lowercased once here; every downstream consumer relies on it). +4. **`internal/model`** - the IR structs (`Enum`, `Table`, `Query`, `PyType`, + ...) plus naming logic: initialisms, table-name singularization + (jinzhu/inflection; exclusions match bare AND schema-qualified names), + Python reserved-word escaping (`reserved.go`), and `DedupName`. +5. **`internal/driver`** - the `Driver` interface (`driver.go`) with + `asyncpg.go` for PostgreSQL and `sqlite_base.go` as the single + implementation for BOTH sqlite drivers (parameterized by module name + + async flag; there are no separate aiosqlite/sqlite3 files). A driver knows + which query commands it supports and emits query function bodies and the + `QueryResults` class. `conversion.go` holds the ordered sqlite + adapter/converter spec table; adapters are registered for parameter types, + converters for non-overridden return types, and the import resolver + mirrors exactly what `WriteConversionSetup` emits. `rowbuilder.go` builds + row-decoding expressions (overrides/enums convert inline; lists convert + element-wise). `common.go` has the shared signature/param expansion; + `convertParamExpr` converts overridden params back to their DefaultType + (element-wise for lists) and is also used by the copyfrom emitter. +6. **`internal/render`** - file-level orchestration: produces `models.py` + (always, even when empty), `enums.py` (when enums exist), and one queries + module per query file; resolves imports (`imports.go`, including the + `typing.TYPE_CHECKING` block and the omit_typechecking_block layout), + returns `[]*plugin.File`. +7. **`internal/writer`** - `CodeWriter`, the low-level indented-Python emitter + (lines, headers, docstrings in google/numpy/pep257 conventions, + `QueryResults` class skeleton, line-length-aware call wrapping). + +`internal/log` is a debug logger; with the `debug: true` plugin option its +buffer is emitted as an extra output file. + +### Invariants that bite + +- Generated output must be byte-identical to the committed fixtures AND a + no-op under `ruff format` (line-length 320; anything longer is emitted + pre-exploded with magic trailing commas via `writer.MaxLineLength`, + `FitsLine`, `WriteWrappedCall`). +- Import resolution must match emission exactly: a name referenced at runtime + by emitted code needs a runtime import; an annotation-only name belongs in + the TYPE_CHECKING block (annotations are lazy via + `from __future__ import annotations`). pyright strict + ruff (select ALL) + on the fixtures are the enforcement. +- Type aliases in generated code must be lazy (PEP 695 `type` statements): + with `omit_typechecking_block: true` they execute at module level, and + `asyncpg.Connection[...]` is a stub-only generic that raises TypeError if + evaluated eagerly. +- sqlite `register_converter` is process-global; per-module registration + emits only what that module needs (params -> adapters, non-overridden + returns -> converters). +- Column overrides do not attach to `ANY($1::type[])` parameters (sqlc does + not link them to the column); only `db_type` overrides reach those. + +### Test layout + +`test/driver_/` each contain a `sqlc.yaml` generating a matrix of +codegen blocks (4 model types x `classes`/`functions`, plus special-purpose +blocks like `omit_tc/` for omit_typechecking_block coverage) from shared +schema/query files into committed subdirectories. Query .sql files map 1:1 to +generated Python modules, so edge cases get their own query file when they +need an isolated module (e.g. adapter-only vs converter-only sqlite +conversion setups). The generated Python is committed on purpose: CI +regenerates it (`*_check` sessions use `sqlc diff`), type-checks it with +pyright in strict mode, lints it with ruff, and runs runtime pytest suites +(`test_*.py` next to the generated packages). When a Go change alters +generated output, rebuild the wasm, rerun the driver sessions, and commit the +regenerated files (when told to commit). + +Keep .sql files ASCII-only: multi-byte characters in comments corrupt sqlc's +byte-offset parameter rewriting and can silently drop `?` placeholders. + +The root `sqlc.yaml` generating into `test/` directly is a scratch config for +quick manual `sqlc generate` runs during development. + +### Lint config gotchas + +- `ruff.toml` is the root config; per-directory `ruff.toml` files under + `test/driver_*//` extend it to set the matching docstring convention. + Never define `[lint.per-file-ignores]` in an extending config: it REPLACES + the root's table for that subtree instead of merging. Add patterns to the + root config instead. +- Validate ruff changes with `--no-cache`; stale caches have masked real + failures locally that CI then caught. +- pyright is configured in `pyproject.toml` (pythonVersion 3.12, strict). Do + not use `executionEnvironments`; it breaks third-party import resolution. diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..eb1d1995 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +-include .env +export + +.PHONY: pipelines tests fmt lint lint-fix changelog +.DEFAULT_GOAL := pipelines + +pipelines: + make lint-fix + make fmt + make lint + +tests: + go test -shuffle=on ./... + +fmt: + golangci-lint fmt + +lint: + golangci-lint run + +lint-fix: + golangci-lint run --no-config --default=none --fix -E godot,intrange,misspell,nlreturn,perfsprint,tagalign + +changelog: + go tool changie new diff --git a/README.md b/README.md index b22c19f0..ff9a41ec 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,17 @@ A WASM plugin for SQLC allowing the generation of Python code. +The generated code requires **Python 3.12 or newer** (it uses PEP 695 type +aliases and generics, and `enum.StrEnum`). + > [!NOTE] > Every Release before `v1.0.0`, including this one is an beta release. > These versions are primarly released for interested people who want to test this plugin and help make it better. > -> I want to be very open about the current state of the project. Everything that is implemented works, and is beeing used -> in production envirouments already. But there are some drivers and features that are sadly not implemented yet, biggest one -> beeing that enums don't have support yet. I am working on that but I have a lot of stuff todo at the moment so I can't give a clear -> estimate on how long this is going to take. Feel free to lmk any wanted features and I'm going to do my best on implementing them with -> the time I have rn. +> Everything that is implemented works and is being used in production environments already. +> Since `v0.5.0` this includes full support for PostgreSQL enums and a fourth model type, `pydantic`. +> Feel free to lmk any wanted features and I'm going to do my best on implementing them with the time I have rn. ## Example Config @@ -52,8 +53,8 @@ More options at the [`sqlc` config reference](https://docs.sqlc.dev/en/stable/re |----------------------------------|----------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `package` | string | yes | The name of the package where the generated files will be located | | `emit_init_file` | bool | yes | If set to to `false` there will be no `__init__.py` file created in the package that you specified. Only set this to false if you know that you already have a `__init__.py` file otherwise the generated code wont work. | -| `sql_driver` | string | no | The name of the sql driver you want to use. Defaults to `aiosqlite`. Valid options are listed [here](#feature-support) | -| `model_type` | string | no | The model type you want to use. This can be one of `dataclass`, `msgspec` or `attrs`. Defaults to `dataclass` | +| `sql_driver` | string | yes | The name of the sql driver you want to use. Valid options are listed [here](#feature-support) | +| `model_type` | string | no | The model type you want to use. This can be one of `dataclass`, `msgspec`, `attrs` or [`pydantic`](#pydantic-models). Defaults to `dataclass` | | `initialisms` | list[string] | no | An array of [initialisms](https://google.github.io/styleguide/go/decisions.html#initialisms) to upper-case. For example, `app_id` becomes `AppID`. Defaults to `["id"]`. | | `emit_exact_table_names` | bool | no | If `true`, model names will mirror table names. Otherwise sqlc attempts to singularize plural table names. | | `emit_classes` | bool | no | If `true`, every query function will be put into a class called `Querier`. Otherwise every function will be a standalone function. | @@ -62,7 +63,7 @@ More options at the [`sqlc` config reference](https://docs.sqlc.dev/en/stable/re | `omit_typechecking_block` | bool | no | If set to `true`, will not wrap all non-builtin types behind a `typing.TYPE_CHECKING` block. Defaults to `false` | | `docstrings` | string | no | If set, there will be docstrings generated in the selected format. This can be one of `google`, `numpy`, `pep257` and `none`. `none` will not generate any docstrings. | | `docstrings_emit_sql` | bool | no | If set to `false` the SQL code for each query wont be included in the docstrings. This defaults to `true` but is not used when `docstrings` is not set or set to `none` | -| `query_parameter_limit` | integer | no | Not yet implemented. | +| `query_parameter_limit` | integer | no | If set to a non-negative value, queries with more parameters than the limit get them bundled into a single `params: Params` argument instead of expanded arguments. If unset or negative, parameters are never bundled (`:copyfrom` always uses a Params class). | | `omit_kwargs_limit` | integer | no | This can be used to set a limit where any query with less or equal amounts of parameters will not require kwargs for the parameters. This defaults to `0` which makes every query require kwargs for their parameters. | | `speedups` | bool | no | If set to `true` the plugin will use other librarys for type conversion. Needs extra dependecys to be installed. This option currently only affects `sqlite3` & `aiosqlite` and uses the library `ciso8601` | | `overrides` | list[Override] | no | A list of [type overrides](#type-overrides). | @@ -91,6 +92,46 @@ options: ``` +### Enums + +PostgreSQL enum types generate an `enums.py` module containing `enum.StrEnum` classes: + +```python +class Mood(enum.StrEnum): + SAD = "sad" + OK = "ok" + HAPPY = "happy" +``` + +Enum columns are typed with these classes in models and query functions, and values read +from the database are coerced into them. Enums in non-default schemas get schema-qualified +class names (e.g. `CustomMood` for `custom.mood`), so same-named enums never collide. + +### Pydantic models + +With `model_type: pydantic`, models are generated as `pydantic.BaseModel` subclasses +(requires `pydantic >= 2.9`). Two things to be aware of: + +- Every generated class sets `model_config = pydantic.ConfigDict(arbitrary_types_allowed=True)`. + This is required for field types pydantic has no core schema for (e.g. `memoryview` for + `bytea`/`blob` columns and custom override types); those fields are still validated with + an `isinstance` check, and all other fields get full pydantic validation on construction. +- Unlike the other model types, pydantic resolves field annotations at runtime, so the + generated files import the referenced modules at runtime instead of inside + `if typing.TYPE_CHECKING:` blocks. If you lint generated code with ruff, set + `lint.flake8-type-checking.runtime-evaluated-base-classes = ["pydantic.BaseModel"]`. + +### SQLite type conversion + +For the `sqlite3` and `aiosqlite` drivers, the generated code registers adapters and +converters (for `date`, `datetime`/`timestamp`, `decimal`, `bool` and `blob` columns) via +`register_adapter`/`register_converter`. For these to work, you must open your connection +with declared-type parsing enabled: + +```python +conn = sqlite3.connect(dsn, detect_types=sqlite3.PARSE_DECLTYPES) +``` + ## Feature Support Every [sqlc macro](https://docs.sqlc.dev/en/latest/reference/macros.html) is supported. diff --git a/coverage.xml b/coverage.xml deleted file mode 100644 index 8a9e249f..00000000 --- a/coverage.xml +++ /dev/null @@ -1,5555 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/internal/builders.go b/internal/builders.go deleted file mode 100644 index c091558e..00000000 --- a/internal/builders.go +++ /dev/null @@ -1,439 +0,0 @@ -package internal - -import ( - "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/core" - "github.com/rayakame/sqlc-gen-better-python/internal/inflection" - "github.com/sqlc-dev/plugin-sdk-go/metadata" - "github.com/sqlc-dev/plugin-sdk-go/plugin" - "github.com/sqlc-dev/plugin-sdk-go/sdk" - "sort" - "strings" -) - -func (gen *PythonGenerator) buildTable(schema *plugin.Schema, table *plugin.Table) core.Table { - var tableName string - if schema.Name == gen.req.Catalog.DefaultSchema { - tableName = table.Rel.Name - } else { - tableName = schema.Name + "_" + table.Rel.Name - } - structName := tableName - if !gen.config.EmitExactTableNames { - structName = inflection.Singular(inflection.SingularParams{ - Name: structName, - Exclusions: gen.config.InflectionExcludeTableNames, - }) - } - t := core.Table{ - Table: &plugin.Identifier{Schema: schema.Name, Name: table.Rel.Name}, - Name: core.SnakeToCamel(structName, gen.config), - Comment: table.Comment, - } - for i, column := range table.Columns { - t.Columns = append(t.Columns, core.Column{ - Name: core.ColumnName(column, i), - Type: gen.makePythonType(column), - Comment: column.Comment, - }) - } - return t -} - -func (gen *PythonGenerator) buildTables() []core.Table { - tables := make([]core.Table, 0) - for _, schema := range gen.req.Catalog.Schemas { - if schema.Name == "pg_catalog" || schema.Name == "information_schema" { - continue - } - for _, table := range schema.Tables { - t := gen.buildTable(schema, table) - tables = append(tables, t) - } - } - if len(tables) > 0 { - sort.Slice(tables, func(i, j int) bool { return tables[i].Name < tables[j].Name }) - } - return tables -} - -func (gen *PythonGenerator) makePythonType(col *plugin.Column) core.PyType { - columnType := sdk.DataType(col.Type) - strType := gen.typeConversionFunc(gen.req, col, gen.config) - for _, override := range gen.config.Overrides { - if override.PyTypeName == "" { - continue - } - cname := col.Name - if col.OriginalName != "" { - cname = col.OriginalName - } - sameTable := override.Matches(col.Table, gen.req.Catalog.DefaultSchema) - if override.Column != "" && override.ColumnName.MatchString(cname) && sameTable { - return core.PyType{ - SqlType: columnType, - Type: override.PyTypeName, - DefaultType: strType, - IsNullable: !col.NotNull, - IsList: col.GetIsArray() || col.GetIsSqlcSlice(), - IsEnum: false, - IsOverride: true, - Override: &override, - } - } - if override.DBType != "" && override.DBType == columnType { - return core.PyType{ - SqlType: columnType, - Type: override.PyTypeName, - DefaultType: strType, - IsNullable: !col.NotNull, - IsList: col.GetIsArray() || col.GetIsSqlcSlice(), - IsEnum: false, - IsOverride: true, - Override: &override, - } - } - } - return core.PyType{ - SqlType: columnType, - Type: strType, - DefaultType: strType, - IsNullable: !col.NotNull, - IsList: col.GetIsArray() || col.GetIsSqlcSlice(), - IsEnum: false, - } -} - -func (gen *PythonGenerator) buildEnums() []core.Enum { - var enums []core.Enum - for _, schema := range gen.req.Catalog.Schemas { - if schema.Name == "pg_catalog" || schema.Name == "information_schema" { - continue - } - for _, enum := range schema.Enums { - var enumName string - if schema.Name == gen.req.Catalog.DefaultSchema { - enumName = enum.Name - } else { - enumName = schema.Name + "_" + enum.Name - } - - e := core.Enum{ - Name: core.SnakeToCamel(enumName, gen.config), - Comment: enum.Comment, - } - - seen := make(map[string]struct{}, len(enum.Vals)) - for i, v := range enum.Vals { - value := core.EnumReplace(v) - if _, found := seen[value]; found || value == "" { - value = fmt.Sprintf("value_%d", i) - } - e.Constants = append(e.Constants, core.Constant{ - Name: core.SnakeToCamel(enumName+"_"+value, gen.config), - Value: v, - Type: e.Name, - }) - seen[value] = struct{}{} - } - enums = append(enums, e) - } - } - if len(enums) > 0 { - sort.Slice(enums, func(i, j int) bool { return enums[i].Name < enums[j].Name }) - } - return enums -} - -type goColumn struct { - id int - *plugin.Column - embed *goEmbed -} - -type goEmbed struct { - modelType string - modelName string - fields []core.Column -} - -var cmdReturnsData = map[string]struct{}{ - metadata.CmdBatchMany: {}, - metadata.CmdBatchOne: {}, - metadata.CmdMany: {}, - metadata.CmdOne: {}, -} - -func putOutColumns(query *plugin.Query) bool { - _, found := cmdReturnsData[query.Cmd] - return found -} - -// look through all the structs and attempt to find a matching one to embed -// We need the name of the struct and its field names. -func newGoEmbed(embed *plugin.Identifier, structs []core.Table, defaultSchema string) *goEmbed { - if embed == nil { - return nil - } - - for _, s := range structs { - embedSchema := defaultSchema - if embed.Schema != "" { - embedSchema = embed.Schema - } - - // compare the other attributes - if embed.Catalog != s.Table.Catalog || embed.Name != s.Table.Name || embedSchema != s.Table.Schema { - continue - } - - fields := make([]core.Column, len(s.Columns)) - for i, f := range s.Columns { - fields[i] = f - } - return &goEmbed{ - modelType: s.Name, - modelName: s.Name, - fields: fields, - } - } - - return nil -} - -func (gen *PythonGenerator) buildQueries(tables []core.Table) ([]core.Query, error) { - qs := make([]core.Query, 0, len(gen.req.Queries)) - for _, query := range gen.req.Queries { - if query.Name == "" { - continue - } - if query.Cmd == "" { - continue - } - - constantName := core.UpperSnakeCase(query.Name) - - comments := query.Comments - - gq := core.Query{ - Cmd: query.Cmd, - ConstantName: constantName, - FuncName: strings.ToLower(constantName), - FieldName: sdk.LowerTitle(query.Name) + "Stmt", - MethodName: query.Name, - SourceName: query.Filename, - SQL: query.Text, - Comments: comments, - Table: query.InsertIntoTable, - } - - //qpl := int(*gen.config.QueryParameterLimit) TODO maybe? - - //if len(query.Params) == 1 && qpl != 0 { - if query.Cmd == metadata.CmdCopyFrom { - var cols []goColumn - for _, p := range query.Params { - cols = append(cols, goColumn{ - id: int(p.Number), - Column: p.Column, - }) - } - s, err := gen.columnsToStruct(gq.MethodName+"Params", cols, true) - if err != nil { - return nil, err - } - gq.Args = []core.QueryValue{{ - Emit: true, - Name: "params", - Table: s, - Typ: core.PyType{ - Type: gq.MethodName + "Params", - }, - }} - } else { - if len(query.Params) == 1 { - p := query.Params[0] - gq.Args = []core.QueryValue{{ - Name: core.Escape(core.ParamName(p)), - DBName: p.Column.GetName(), - Typ: gen.makePythonType(p.Column), - Column: p.Column, - }} - } else if len(query.Params) >= 1 { - var values []core.QueryValue - for _, p := range query.Params { - values = append(values, core.QueryValue{ - Name: core.Escape(core.ParamName(p)), - DBName: p.Column.GetName(), - Typ: gen.makePythonType(p.Column), - Column: p.Column, - }) - } - gq.Args = values - - // if query params is 2, and query params limit is 4 AND this is a copyfrom, we still want to emit the query's model - // otherwise we end up with a copyfrom using a struct without the struct definition - //if len(query.Params) <= qpl && query.Cmd != ":copyfrom" { - // gq.Args.Emit = false - //} - } - } - - if len(query.Columns) == 1 && query.Columns[0].EmbedTable == nil { - c := query.Columns[0] - name := core.ColumnName(c, 0) - name = strings.Replace(name, "$", "_", -1) - gq.Ret = core.QueryValue{ - Name: core.Escape(name), - DBName: name, - Typ: gen.makePythonType(c), - } - } else if putOutColumns(query) { - var gs *core.Table - var emit bool - - for _, s := range tables { - if len(s.Columns) != len(query.Columns) { - continue - } - same := true - for i, f := range s.Columns { - c := query.Columns[i] - sameName := f.Name == core.ColumnName(c, i) - sameType := f.Type.Type == gen.makePythonType(c).Type - sameTable := sdk.SameTableName(c.Table, s.Table, gen.req.Catalog.DefaultSchema) - if !sameName || !sameType || !sameTable { - same = false - } - } - if same { - gs = &s - break - } - } - - if gs == nil { - var columns []goColumn - for i, c := range query.Columns { - columns = append(columns, goColumn{ - id: i, - Column: c, - embed: newGoEmbed(c.EmbedTable, tables, gen.req.Catalog.DefaultSchema), - }) - } - var err error - gs, err = gen.columnsToStruct(gq.MethodName+"Row", columns, true) - if err != nil { - return nil, err - } - emit = true - } - gq.Ret = core.QueryValue{ - Emit: emit, - Name: "i", - Table: gs, - } - } - - qs = append(qs, gq) - } - sort.Slice(qs, func(i, j int) bool { return qs[i].MethodName < qs[j].MethodName }) - return qs, nil -} - -func (gen *PythonGenerator) columnsToStruct(name string, columns []goColumn, useID bool) (*core.Table, error) { - gs := core.Table{ - Name: name, - } - seen := map[string][]int{} - suffixes := map[int]int{} - for i, c := range columns { - colName := core.ColumnName(c.Column, i) - - // override col/tag with expected model name - if c.embed != nil { - colName = c.embed.modelName - } - - fieldName := core.SnakeToCamel(colName, gen.config) - baseFieldName := fieldName - // Track suffixes by the ID of the column, so that columns referring to the same numbered parameter can be - // reused. - suffix := 0 - if o, ok := suffixes[c.id]; ok && useID { - suffix = o - } else if v := len(seen[fieldName]); v > 0 && !c.IsNamedParam { - suffix = v + 1 - } - suffixes[c.id] = suffix - if suffix > 0 { - fieldName = fmt.Sprintf("%s_%d", fieldName, suffix) - } - - f := core.Column{ - Name: inflection.Singular(inflection.SingularParams{ - Name: core.ColumnName(c.Column, i), - Exclusions: gen.config.InflectionExcludeTableNames, - }), - DBName: colName, - Column: c.Column, - } - - if c.embed == nil { - f.Type = gen.makePythonType(c.Column) - } else { - f.Type = core.PyType{ - SqlType: c.embed.modelType, - Type: "models." + c.embed.modelType, - IsList: false, - IsNullable: false, - IsEnum: false, - } - f.EmbedFields = c.embed.fields - } - - gs.Columns = append(gs.Columns, f) - if _, found := seen[baseFieldName]; !found { - seen[baseFieldName] = []int{i} - } else { - seen[baseFieldName] = append(seen[baseFieldName], i) - } - } - - // If a field does not have a known type, but another - // field with the same name has a known type, assign - // the known type to the field without a known type - /*for i, field := range gs.Columns { - if len(seen[field.Name]) > 1 && field.Type.Type == "interface{}" { - for _, j := range seen[field.Name] { - if i == j { - continue - } - otherField := gs.Fields[j] - if otherField.Type != field.Type { - field.Type = otherField.Type - } - gs.Fields[i] = field - } - } - }*/ - - err := checkIncompatibleFieldTypes(gs.Columns) - if err != nil { - return nil, err - } - - return &gs, nil -} - -func checkIncompatibleFieldTypes(fields []core.Column) error { - fieldTypes := map[string]string{} - for _, field := range fields { - if fieldType, found := fieldTypes[field.Name]; !found { - fieldTypes[field.Name] = field.Type.Type - } else if field.Type.Type != fieldType { - return fmt.Errorf("named param %s has incompatible types: %s, %s", field.Name, field.Type.Type, fieldType) - } - } - return nil -} diff --git a/internal/codegen/builders/docstrings.go b/internal/codegen/builders/docstrings.go deleted file mode 100644 index 19976e18..00000000 --- a/internal/codegen/builders/docstrings.go +++ /dev/null @@ -1,764 +0,0 @@ -package builders - -import ( - "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/core" - "github.com/sqlc-dev/plugin-sdk-go/metadata" -) - -var docstringConfig *string -var docstringConfigEmitSQL *bool -var docstringConfigDriver core.SQLDriverType = core.SQLDriverAsyncpg - -func SetDocstringConfig(c *string, b *bool, d core.SQLDriverType) { - docstringConfig = c - docstringConfigEmitSQL = b - docstringConfigDriver = d -} - -func (b *IndentStringBuilder) WriteQueryResultsIterDocstring() { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedLine(2, `"""`+"Initialize iteration support.") - b.NewLine() - if *docstringConfig == core.DocstringConventionNumpy { - b.WriteIndentedLine(2, "Returns") - b.WriteIndentedLine(2, "-------") - b.WriteIndentedLine(2, "QueryResults[T]") - b.WriteIndentedLine(3, "Self as an iterator.") - } else if *docstringConfig == core.DocstringConventionGoogle { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(3, "Self as an iterator.") - } else if *docstringConfig == core.DocstringConventionPEP257 { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(2, "Self as an iterator.") - } - b.WriteIndentedLine(2, `"""`) -} - -func (b *IndentStringBuilder) WriteQueryResultsAiterDocstring() { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedLine(2, `"""`+"Initialize iteration support for `async for`.") - b.NewLine() - if *docstringConfig == core.DocstringConventionNumpy { - b.WriteIndentedLine(2, "Returns") - b.WriteIndentedLine(2, "-------") - b.WriteIndentedLine(2, "QueryResults[T]") - b.WriteIndentedLine(3, "Self as an asynchronous iterator.") - } else if *docstringConfig == core.DocstringConventionGoogle { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(3, "Self as an asynchronous iterator.") - } else if *docstringConfig == core.DocstringConventionPEP257 { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(2, "Self as an asynchronous iterator.") - } - b.WriteIndentedLine(2, `"""`) -} - -func (b *IndentStringBuilder) WriteQueryResultsNextDocstringSqlite() { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedLine(2, `"""Yield the next item in the query result using a sqlite3 cursor.`) - b.NewLine() - if *docstringConfig == core.DocstringConventionNumpy { - b.WriteIndentedLine(2, "Returns") - b.WriteIndentedLine(2, "-------") - b.WriteIndentedLine(2, "T") - b.WriteIndentedLine(3, "The next decoded result.") - b.NewLine() - b.WriteIndentedLine(2, "Raises") - b.WriteIndentedLine(2, "------") - b.WriteIndentedLine(2, "StopIteration") - b.WriteIndentedLine(3, "When no more records are available.") - } else if *docstringConfig == core.DocstringConventionGoogle { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(3, "The next decoded result of type `T`.") - b.NewLine() - b.WriteIndentedLine(2, "Raises:") - b.WriteIndentedLine(3, "StopIteration: When no more records are available.") - } else if *docstringConfig == core.DocstringConventionPEP257 { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(2, "The next decoded result of type `T`.") - b.NewLine() - b.WriteIndentedLine(2, "Raises:") - b.WriteIndentedLine(2, "StopIteration -- When no more records are available.") - } - b.WriteIndentedLine(2, `"""`) -} - -func (b *IndentStringBuilder) WriteQueryResultsAnextDocstringAiosqlite() { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedLine(2, `"""Yield the next item in the query result using an aiosqlite cursor.`) - b.NewLine() - if *docstringConfig == core.DocstringConventionNumpy { - b.WriteIndentedLine(2, "Returns") - b.WriteIndentedLine(2, "-------") - b.WriteIndentedLine(2, "T") - b.WriteIndentedLine(3, "The next decoded result.") - b.NewLine() - b.WriteIndentedLine(2, "Raises") - b.WriteIndentedLine(2, "------") - b.WriteIndentedLine(2, "StopAsyncIteration") - b.WriteIndentedLine(3, "When no more records are available.") - } else if *docstringConfig == core.DocstringConventionGoogle { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(3, "The next decoded result of type `T`.") - b.NewLine() - b.WriteIndentedLine(2, "Raises:") - b.WriteIndentedLine(3, "StopAsyncIteration: When no more records are available.") - } else if *docstringConfig == core.DocstringConventionPEP257 { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(2, "The next decoded result of type `T`.") - b.NewLine() - b.WriteIndentedLine(2, "Raises:") - b.WriteIndentedLine(2, "StopAsyncIteration -- When no more records are available.") - } - b.WriteIndentedLine(2, `"""`) -} - -func (b *IndentStringBuilder) WriteQueryResultsAnextDocstringAsyncpg() { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedLine(2, `"""Yield the next item in the query result using an asyncpg cursor.`) - b.NewLine() - if *docstringConfig == core.DocstringConventionNumpy { - b.WriteIndentedLine(2, "Returns") - b.WriteIndentedLine(2, "-------") - b.WriteIndentedLine(2, "T") - b.WriteIndentedLine(3, "The next decoded result.") - b.NewLine() - b.WriteIndentedLine(2, "Raises") - b.WriteIndentedLine(2, "------") - b.WriteIndentedLine(2, "StopAsyncIteration") - b.WriteIndentedLine(3, "When no more records are available.") - } else if *docstringConfig == core.DocstringConventionGoogle { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(3, "The next decoded result of type `T`.") - b.NewLine() - b.WriteIndentedLine(2, "Raises:") - b.WriteIndentedLine(3, "StopAsyncIteration: When no more records are available.") - } else if *docstringConfig == core.DocstringConventionPEP257 { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(2, "The next decoded result of type `T`.") - b.NewLine() - b.WriteIndentedLine(2, "Raises:") - b.WriteIndentedLine(2, "StopAsyncIteration -- When no more records are available.") - } - b.WriteIndentedLine(2, `"""`) -} - -func (b *IndentStringBuilder) WriteQueryResultsAwaitDocstring() { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedLine(2, `"""`+"Allow `await` on the object to return all rows as a fully decoded sequence.") - b.NewLine() - if *docstringConfig == core.DocstringConventionNumpy { - b.WriteIndentedLine(2, "Returns") - b.WriteIndentedLine(2, "-------") - b.WriteIndentedLine(2, "collections.abc.Sequence[T]") - b.WriteIndentedLine(3, "A sequence of decoded objects of type `T`.") - } else if *docstringConfig == core.DocstringConventionGoogle { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(3, "A sequence of decoded objects of type `T`.") - } else if *docstringConfig == core.DocstringConventionPEP257 { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(2, "A sequence of decoded objects of type `T`.") - } - b.WriteIndentedLine(2, `"""`) -} - -func (b *IndentStringBuilder) WriteQueryResultsCallDocstring() { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedLine(2, `"""`+"Allow calling the object to return all rows as a fully decoded sequence.") - b.NewLine() - if *docstringConfig == core.DocstringConventionNumpy { - b.WriteIndentedLine(2, "Returns") - b.WriteIndentedLine(2, "-------") - b.WriteIndentedLine(2, "collections.abc.Sequence[T]") - b.WriteIndentedLine(3, "A sequence of decoded objects of type `T`.") - } else if *docstringConfig == core.DocstringConventionGoogle { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(3, "A sequence of decoded objects of type `T`.") - } else if *docstringConfig == core.DocstringConventionPEP257 { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(2, "A sequence of decoded objects of type `T`.") - } - b.WriteIndentedLine(2, `"""`) -} - -func (b *IndentStringBuilder) WriteQueryResultsInitDocstring(docstringConnType string, docstringDriverReturnType string) { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedString(2, fmt.Sprintf(`"""Initialize the QueryResults instance.`)) - if *docstringConfig == core.DocstringConventionNumpy { - b.WriteLine(`"""`) - } else if *docstringConfig == core.DocstringConventionGoogle { - b.NNewLine(2) - b.WriteIndentedLine(2, "Args:") - b.WriteIndentedLine(3, "conn:") - b.WriteIndentedLine(4, fmt.Sprintf("The connection object of type `%s` used to execute queries.", docstringConnType)) - b.WriteIndentedLine(3, "sql:") - b.WriteIndentedLine(4, "The SQL statement that will be executed when fetching/iterating.") - b.WriteIndentedLine(3, "decode_hook:") - b.WriteIndentedLine(4, fmt.Sprintf("A callback that turns an `%s` object into `T` that will be returned.", docstringDriverReturnType)) - b.WriteIndentedLine(3, "*args:") - b.WriteIndentedLine(4, "Arguments that should be sent when executing the sql query.") - b.WriteIndentedLine(2, `"""`) - } else if *docstringConfig == core.DocstringConventionPEP257 { - b.NNewLine(2) - b.WriteIndentedLine(2, "Arguments:") - b.WriteIndentedLine(2, fmt.Sprintf("conn -- The connection object of type `%s` used to execute queries.", docstringConnType)) - b.WriteIndentedLine(2, "sql -- The SQL statement that will be executed when fetching/iterating.") - b.WriteIndentedLine(2, fmt.Sprintf("decode_hook -- A callback that turns an `%s` object into `T` that will be returned.", docstringDriverReturnType)) - b.WriteIndentedLine(2, "*args -- Arguments that should be sent when executing the sql query.") - b.WriteIndentedLine(2, `"""`) - } -} - -func (b *IndentStringBuilder) WriteQueryResultsClassDocstring(docstringConnType string, docstringDriverReturnType string) { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedString(1, `"""Helper class that allows both iteration and normal fetching of data from the db.`) - if *docstringConfig == core.DocstringConventionNumpy { - b.NewLine() - b.NewLine() - b.WriteIndentedLine(1, "Parameters") - b.WriteIndentedLine(1, "----------") - b.WriteIndentedLine(1, "conn") - b.WriteIndentedLine(2, fmt.Sprintf("The connection object of type `%s` used to execute queries.", docstringConnType)) - b.WriteIndentedLine(1, "sql") - b.WriteIndentedLine(2, "The SQL statement that will be executed when fetching/iterating.") - b.WriteIndentedLine(1, "decode_hook") - b.WriteIndentedLine(2, fmt.Sprintf("A callback that turns an `%s` object into `T` that will be returned.", docstringDriverReturnType)) - b.WriteIndentedLine(1, "*args") - b.WriteIndentedLine(2, "Arguments that should be sent when executing the sql query.") - b.NewLine() - b.WriteIndentedLine(1, `"""`) - } else { - b.WriteLine(`"""`) - } - b.NewLine() -} - -func (b *IndentStringBuilder) WriteQueryClassConnDocstring(docstringConnType string) { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedLine(2, `"""Connection object used to make queries.`) - b.NewLine() - if *docstringConfig == core.DocstringConventionNumpy { - b.WriteIndentedLine(2, "Returns") - b.WriteIndentedLine(2, "-------") - b.WriteIndentedLine(2, docstringConnType) - b.NewLine() - } else if *docstringConfig == core.DocstringConventionGoogle { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(3, fmt.Sprintf("Connection object of type `%s` used to make queries.", docstringConnType)) - } else if *docstringConfig == core.DocstringConventionPEP257 { - b.WriteIndentedLine(2, "Returns:") - b.WriteIndentedLine(2, fmt.Sprintf("%s -- Connection object used to make queries.", docstringConnType)) - } - b.WriteIndentedLine(2, `"""`) -} - -func (b *IndentStringBuilder) WriteQueryClassDocstring(sourceName string, docstringConnType string) { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedString(1, fmt.Sprintf(`"""Queries from file %s.`, sourceName)) - if *docstringConfig == core.DocstringConventionNumpy { - b.NewLine() - b.NewLine() - b.WriteIndentedLine(1, "Parameters") - b.WriteIndentedLine(1, "----------") - b.WriteIndentedLine(1, fmt.Sprintf("conn : %s", docstringConnType)) - b.WriteIndentedLine(2, "The connection object used to execute queries.") - b.NewLine() - b.WriteIndentedLine(1, `"""`) - } else { - b.WriteLine(`"""`) - } - b.NewLine() -} - -func (b *IndentStringBuilder) WriteQueryClassInitDocstring(lvl int, docstringConnType string) { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedString(lvl, fmt.Sprintf(`"""Initialize the instance using the connection.`)) - if *docstringConfig == core.DocstringConventionNumpy { - b.WriteLine(`"""`) - } else if *docstringConfig == core.DocstringConventionGoogle { - b.NNewLine(2) - b.WriteIndentedLine(lvl, "Args:") - b.WriteIndentedLine(lvl+1, "conn:") - b.WriteIndentedLine(lvl+2, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - b.WriteIndentedLine(lvl, `"""`) - } else if *docstringConfig == core.DocstringConventionPEP257 { - b.NNewLine(2) - b.WriteIndentedLine(lvl, "Arguments:") - b.WriteIndentedLine(lvl, fmt.Sprintf("conn -- Connection object of type `%s` used to execute queries.", docstringConnType)) - b.WriteIndentedLine(lvl, `"""`) - } -} - -func (b *IndentStringBuilder) WriteModelClassDocstring(table *core.Table) { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteIndentedLine(1, `"""`+fmt.Sprintf("Model representing %s.", table.Name)) - if *docstringConfig == core.DocstringConventionNumpy { - b.NewLine() - b.WriteIndentedLine(1, "Attributes") - b.WriteIndentedLine(1, "----------") - for _, col := range table.Columns { - type_ := col.Type.Type - if col.Type.IsList { - type_ = "collections.abc.Sequence[" + type_ + "]" - } - if col.Type.IsNullable { - type_ = type_ + " | None" - } - b.WriteIndentedLine(1, fmt.Sprintf("%s : %s", col.Name, type_)) - } - b.NewLine() - } else if *docstringConfig == core.DocstringConventionGoogle { - b.NewLine() - b.WriteIndentedLine(1, "Attributes:") - for _, col := range table.Columns { - type_ := col.Type.Type - if col.Type.IsList { - type_ = "collections.abc.Sequence[" + type_ + "]" - } - if col.Type.IsNullable { - type_ = type_ + " | None" - } - b.WriteIndentedLine(2, fmt.Sprintf("%s: %s", col.Name, type_)) - } - } else if *docstringConfig == core.DocstringConventionPEP257 { - b.NewLine() - b.WriteIndentedLine(1, "Attributes:") - for _, col := range table.Columns { - type_ := col.Type.Type - if col.Type.IsList { - type_ = "collections.abc.Sequence[" + type_ + "]" - } - if col.Type.IsNullable { - type_ = type_ + " | None" - } - b.WriteIndentedLine(1, fmt.Sprintf("%s -- %s", col.Name, type_)) - } - } - b.WriteIndentedLine(1, `"""`) - b.NewLine() -} - -func (b *IndentStringBuilder) WriteModelFileModuleDocstring() { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteLine(`"""Module containing models."""`) -} - -func (b *IndentStringBuilder) WriteQueryFileModuleDocstring(sourceName string) { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteLine(fmt.Sprintf(`"""Module containing queries from file %s."""`, sourceName)) -} - -func (b *IndentStringBuilder) WriteInitFileModuleDocstring() { - if *docstringConfig == core.DocstringConventionNone { - return - } - b.WriteLine(`"""Package containing queries and models automatically generated using sqlc-gen-better-python."""`) -} - -func (b *IndentStringBuilder) writeQueryFunctionSQL(lvl int, query *core.Query) { - if *docstringConfigEmitSQL { - b.WriteIndentedLine(lvl, "```sql") - for _, line := range core.SplitLines(query.SQL) { - b.WriteIndentedLine(lvl, line) - } - b.WriteIndentedLine(lvl, "```") - b.NewLine() - } -} - -func (b *IndentStringBuilder) WriteQueryFunctionDocstring(lvl int, query *core.Query, docstringConnType string, queryArgs []core.FunctionArg, returnType core.PyType) { - if *docstringConfig == core.DocstringConventionNone { - return - } - - if query.Cmd == metadata.CmdExec { - b.WriteIndentedLine(lvl, `"""`+fmt.Sprintf("Execute SQL query with `name: %s %s`.", query.MethodName, query.Cmd)) - b.NewLine() - b.writeQueryFunctionSQL(lvl, query) - if len(queryArgs) == 0 && docstringConnType == "" { - b.WriteIndentedLine(lvl, `"""`) - return - } - if *docstringConfig == core.DocstringConventionNumpy { - b.WriteIndentedLine(lvl, "Parameters") - b.WriteIndentedLine(lvl, "----------") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn : %s", docstringConnType)) - b.WriteIndentedLine(lvl+1, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s : %s", arg.Name, arg.Type)) - } - b.NewLine() - } else if *docstringConfig == core.DocstringConventionGoogle { - b.WriteIndentedLine(lvl, "Args:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl+1, "conn:") - b.WriteIndentedLine(lvl+2, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl+1, fmt.Sprintf("%s: %s.", arg.Name, arg.Type)) - } - } else if *docstringConfig == core.DocstringConventionPEP257 { - b.WriteIndentedLine(lvl, "Arguments:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn -- Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s -- %s.", arg.Name, arg.Type)) - } - } - b.WriteIndentedLine(lvl, `"""`) - } else if query.Cmd == metadata.CmdExecRows { - b.WriteIndentedLine(lvl, `"""`+fmt.Sprintf("Execute SQL query with `name: %s %s` and return the number of affected rows.", query.MethodName, query.Cmd)) - b.NewLine() - b.writeQueryFunctionSQL(lvl, query) - if *docstringConfig == core.DocstringConventionNumpy { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Parameters") - b.WriteIndentedLine(lvl, "----------") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn : %s", docstringConnType)) - b.WriteIndentedLine(lvl+1, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s : %s", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns") - b.WriteIndentedLine(lvl, "-------") - b.WriteIndentedLine(lvl, returnType.Type) - if docstringConfigDriver == core.SQLDriverAioSQLite { - b.WriteIndentedLine(lvl+1, "The number of affected rows. This will be -1 for queries like `CREATE TABLE`.") - } else { - b.WriteIndentedLine(lvl+1, "The number of affected rows. This will be 0 for queries like `CREATE TABLE`.") - } - b.NewLine() - } else if *docstringConfig == core.DocstringConventionGoogle { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Args:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl+1, "conn:") - b.WriteIndentedLine(lvl+2, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl+1, fmt.Sprintf("%s: %s.", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns:") - if docstringConfigDriver == core.SQLDriverAioSQLite { - b.WriteIndentedLine(lvl+1, fmt.Sprintf("The number (`%s`) of affected rows. This will be -1 for queries like `CREATE TABLE`.", returnType.Type)) - } else { - b.WriteIndentedLine(lvl+1, fmt.Sprintf("The number (`%s`) of affected rows. This will be 0 for queries like `CREATE TABLE`.", returnType.Type)) - } - } else if *docstringConfig == core.DocstringConventionPEP257 { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Arguments:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn -- Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s -- %s.", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns:") - if docstringConfigDriver == core.SQLDriverAioSQLite { - b.WriteIndentedLine(lvl+1, fmt.Sprintf("%s -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`.", returnType.Type)) - } else { - b.WriteIndentedLine(lvl+1, fmt.Sprintf("%s -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`.", returnType.Type)) - } - } - b.WriteIndentedLine(lvl, `"""`) - } else if query.Cmd == metadata.CmdCopyFrom { - b.WriteIndentedLine(lvl, `"""`+fmt.Sprintf("Execute COPY FROM query to insert rows into a table with `name: %s %s` and return the number of affected rows.", query.MethodName, query.Cmd)) - b.NewLine() - if *docstringConfig == core.DocstringConventionNumpy { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Parameters") - b.WriteIndentedLine(lvl, "----------") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn : %s", docstringConnType)) - b.WriteIndentedLine(lvl+1, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s : %s", arg.Name, arg.Type)) - b.WriteIndentedLine(lvl+1, "A list of params for rows that should be inserted.") - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns") - b.WriteIndentedLine(lvl, "-------") - b.WriteIndentedLine(lvl, returnType.Type) - b.WriteIndentedLine(lvl+1, "The number of affected rows.") - b.NewLine() - } else if *docstringConfig == core.DocstringConventionGoogle { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Args:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl+1, "conn:") - b.WriteIndentedLine(lvl+2, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl+1, fmt.Sprintf("%s: %s.", arg.Name, arg.Type)) - b.WriteIndentedLine(lvl+2, "A list of params for rows that should be inserted.") - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns:") - b.WriteIndentedLine(lvl+1, fmt.Sprintf("The number (`%s`) of affected rows.", returnType.Type)) - } else if *docstringConfig == core.DocstringConventionPEP257 { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Arguments:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn -- Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s -- %s. A list of params for rows that should be inserted.", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns:") - b.WriteIndentedLine(lvl, fmt.Sprintf("%s -- The number of affected rows.", returnType.Type)) - } - b.WriteIndentedLine(lvl, `"""`) - } else if query.Cmd == metadata.CmdExecResult { - b.WriteIndentedLine(lvl, `"""`+fmt.Sprintf("Execute and return the result of SQL query with `name: %s %s`.", query.MethodName, query.Cmd)) - b.NewLine() - b.writeQueryFunctionSQL(lvl, query) - if *docstringConfig == core.DocstringConventionNumpy { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Parameters") - b.WriteIndentedLine(lvl, "----------") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn : %s", docstringConnType)) - b.WriteIndentedLine(lvl+1, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s : %s", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns") - b.WriteIndentedLine(lvl, "-------") - b.WriteIndentedLine(lvl, returnType.Type) - b.WriteIndentedLine(lvl+1, "The result returned when executing the query.") - b.NewLine() - } else if *docstringConfig == core.DocstringConventionGoogle { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Args:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl+1, "conn:") - b.WriteIndentedLine(lvl+2, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl+1, fmt.Sprintf("%s: %s.", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns:") - b.WriteIndentedLine(lvl+1, fmt.Sprintf("The result of type `%s` returned when executing the query.", returnType.Type)) - } else if *docstringConfig == core.DocstringConventionPEP257 { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Arguments:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn -- Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s -- %s.", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns:") - b.WriteIndentedLine(lvl, fmt.Sprintf("%s -- The result returned when executing the query.", returnType.Type)) - } - b.WriteIndentedLine(lvl, `"""`) - } else if query.Cmd == metadata.CmdExecLastId { - b.WriteIndentedLine(lvl, `"""`+fmt.Sprintf("Execute SQL query with `name: %s %s` and return the id of the last affected row.", query.MethodName, query.Cmd)) - b.NewLine() - b.writeQueryFunctionSQL(lvl, query) - if *docstringConfig == core.DocstringConventionNumpy { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Parameters") - b.WriteIndentedLine(lvl, "----------") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn : %s", docstringConnType)) - b.WriteIndentedLine(lvl+1, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s : %s", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns") - b.WriteIndentedLine(lvl, "-------") - b.WriteIndentedLine(lvl, returnType.Type) - b.WriteIndentedLine(lvl+1, "The id of the last affected row. Will be `None` if no rows are affected.") - b.NewLine() - } else if *docstringConfig == core.DocstringConventionGoogle { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Args:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl+1, "conn:") - b.WriteIndentedLine(lvl+2, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl+1, fmt.Sprintf("%s: %s.", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns:") - b.WriteIndentedLine(lvl+1, fmt.Sprintf("The id (`%s`) of the last affected row. Will be `None` if no rows are affected.", returnType.Type)) - } else if *docstringConfig == core.DocstringConventionPEP257 { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Arguments:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn -- Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s -- %s.", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns:") - b.WriteIndentedLine(lvl, fmt.Sprintf("%s -- The id of the last affected row. Will be `None` if no rows are affected.", returnType.Type)) - } - b.WriteIndentedLine(lvl, `"""`) - } else if query.Cmd == metadata.CmdOne { - b.WriteIndentedLine(lvl, `"""`+fmt.Sprintf("Fetch one from the db using the SQL query with `name: %s %s`.", query.MethodName, query.Cmd)) - b.NewLine() - b.writeQueryFunctionSQL(lvl, query) - if *docstringConfig == core.DocstringConventionNumpy { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Parameters") - b.WriteIndentedLine(lvl, "----------") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn : %s", docstringConnType)) - b.WriteIndentedLine(lvl+1, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s : %s", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns") - b.WriteIndentedLine(lvl, "-------") - b.WriteIndentedLine(lvl, returnType.Type) - b.WriteIndentedLine(lvl+1, "Result fetched from the db. Will be `None` if not found.") - b.NewLine() - - } else if *docstringConfig == core.DocstringConventionGoogle { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Args:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl+1, "conn:") - b.WriteIndentedLine(lvl+2, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl+1, fmt.Sprintf("%s: %s.", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns:") - b.WriteIndentedLine(lvl+1, fmt.Sprintf("Result of type `%s` fetched from the db. Will be `None` if not found.", returnType.Type)) - } else if *docstringConfig == core.DocstringConventionPEP257 { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Arguments:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn -- Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s -- %s.", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns:") - b.WriteIndentedLine(lvl, fmt.Sprintf("%s -- Result fetched from the db. Will be `None` if not found.", returnType.Type)) - } - b.WriteIndentedLine(lvl, `"""`) - } else if query.Cmd == metadata.CmdMany { - b.WriteIndentedLine(lvl, `"""`+fmt.Sprintf("Fetch many from the db using the SQL query with `name: %s %s`.", query.MethodName, query.Cmd)) - b.NewLine() - b.writeQueryFunctionSQL(lvl, query) - if *docstringConfig == core.DocstringConventionNumpy { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Parameters") - b.WriteIndentedLine(lvl, "----------") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn : %s", docstringConnType)) - b.WriteIndentedLine(lvl+1, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s : %s", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns") - b.WriteIndentedLine(lvl, "-------") - b.WriteIndentedLine(lvl, fmt.Sprintf("QueryResults[%s]", returnType.Type)) - b.WriteIndentedLine(lvl+1, "Helper class that allows both iteration and normal fetching of data from the db.") - b.NewLine() - } else if *docstringConfig == core.DocstringConventionGoogle { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Args:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl+1, "conn:") - b.WriteIndentedLine(lvl+2, fmt.Sprintf("Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl+1, fmt.Sprintf("%s: %s.", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns:") - b.WriteIndentedLine(lvl+1, fmt.Sprintf("Helper class of type `QueryResults[%s]` that allows both iteration and normal fetching of data from the db.", returnType.Type)) - } else if *docstringConfig == core.DocstringConventionPEP257 { - if len(queryArgs) != 0 || docstringConnType != "" { - b.WriteIndentedLine(lvl, "Arguments:") - if docstringConnType != "" { - b.WriteIndentedLine(lvl, fmt.Sprintf("conn -- Connection object of type `%s` used to execute the query.", docstringConnType)) - } - for _, arg := range queryArgs { - b.WriteIndentedLine(lvl, fmt.Sprintf("%s -- %s.", arg.Name, arg.Type)) - } - b.NewLine() - } - b.WriteIndentedLine(lvl, "Returns:") - b.WriteIndentedLine(lvl, fmt.Sprintf("QueryResults[%s] -- Helper class that allows both iteration and normal fetching of data from the db.", returnType.Type)) - } - b.WriteIndentedLine(lvl, `"""`) - } -} diff --git a/internal/codegen/builders/query_results.go b/internal/codegen/builders/query_results.go deleted file mode 100644 index 4af93240..00000000 --- a/internal/codegen/builders/query_results.go +++ /dev/null @@ -1,84 +0,0 @@ -package builders - -import "fmt" - -func (b *IndentStringBuilder) WriteSyncQueryResultsClassHeader(connType string, initFields []string, driverReturnType string) { - b.WriteLine(`T = typing.TypeVar("T")`) - b.NNewLine(2) - b.WriteLine("class QueryResults(typing.Generic[T]):") - b.WriteQueryResultsClassDocstring(connType, driverReturnType) - b.WriteIndentedLine(1, `__slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql")`) - b.NewLine() - b.WriteIndentedLine(1, "def __init__(") - b.WriteIndentedLine(2, "self,") - b.WriteIndentedLine(2, fmt.Sprintf("conn: %s,", connType)) - b.WriteIndentedLine(2, "sql: str,") - b.WriteIndentedLine(2, fmt.Sprintf("decode_hook: collections.abc.Callable[[%s], T],", driverReturnType)) - b.WriteIndentedLine(2, "*args: QueryResultsArgsType,") - b.WriteIndentedLine(1, ") -> None:") - b.WriteQueryResultsInitDocstring(connType, driverReturnType) - b.WriteIndentedLine(2, "self._conn = conn") - b.WriteIndentedLine(2, "self._sql = sql") - b.WriteIndentedLine(2, "self._decode_hook = decode_hook") - b.WriteIndentedLine(2, "self._args = args") - for _, line := range initFields { - b.WriteIndentedLine(2, line) - } - b.NewLine() - b.WriteIndentedLine(1, "def __iter__(self) -> QueryResults[T]:") - b.WriteQueryResultsIterDocstring() - b.WriteIndentedLine(2, "return self") - b.NewLine() -} - -func (b *IndentStringBuilder) WriteAsyncQueryResultsClassHeader(connType string, initFields []string, driverReturnType string) { - b.WriteLine(`T = typing.TypeVar("T")`) - b.NNewLine(2) - b.WriteLine("class QueryResults(typing.Generic[T]):") - b.WriteQueryResultsClassDocstring(connType, driverReturnType) - b.WriteIndentedLine(1, `__slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql")`) - b.NewLine() - b.WriteIndentedLine(1, "def __init__(") - b.WriteIndentedLine(2, "self,") - b.WriteIndentedLine(2, fmt.Sprintf("conn: %s,", connType)) - b.WriteIndentedLine(2, "sql: str,") - b.WriteIndentedLine(2, fmt.Sprintf("decode_hook: collections.abc.Callable[[%s], T],", driverReturnType)) - b.WriteIndentedLine(2, "*args: QueryResultsArgsType,") - b.WriteIndentedLine(1, ") -> None:") - b.WriteQueryResultsInitDocstring(connType, driverReturnType) - b.WriteIndentedLine(2, "self._conn = conn") - b.WriteIndentedLine(2, "self._sql = sql") - b.WriteIndentedLine(2, "self._decode_hook = decode_hook") - b.WriteIndentedLine(2, "self._args = args") - for _, line := range initFields { - b.WriteIndentedLine(2, line) - } - b.NewLine() - b.WriteIndentedLine(1, "def __aiter__(self) -> QueryResults[T]:") - b.WriteQueryResultsAiterDocstring() - b.WriteIndentedLine(2, "return self") - b.NewLine() -} - -func (b *IndentStringBuilder) WriteQueryResultsCallFunction(wrapperLines []string) { - b.WriteIndentedLine(1, "def __call__(") - b.WriteIndentedLine(2, "self,") - b.WriteIndentedLine(1, ") -> collections.abc.Sequence[T]:") - b.WriteQueryResultsCallDocstring() - for _, line := range wrapperLines { - b.WriteIndentedLine(2, line) - } -} - -func (b *IndentStringBuilder) WriteQueryResultsAwaitFunction(wrapperLines []string) { - b.WriteIndentedLine(1, "def __await__(") - b.WriteIndentedLine(2, "self,") - b.WriteIndentedLine(1, ") -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]:") - b.WriteQueryResultsAwaitDocstring() - b.WriteIndentedLine(2, "async def _wrapper() -> collections.abc.Sequence[T]:") - for _, line := range wrapperLines { - b.WriteIndentedLine(3, line) - } - b.WriteIndentedLine(2, "return _wrapper().__await__()") - -} diff --git a/internal/codegen/builders/string.go b/internal/codegen/builders/string.go deleted file mode 100644 index 4b17299e..00000000 --- a/internal/codegen/builders/string.go +++ /dev/null @@ -1,70 +0,0 @@ -package builders - -import ( - "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/core" - "os" - "strings" -) - -type IndentStringBuilder struct { - strings.Builder - - indentChar string - charsPerIndentLevel int -} - -func NewIndentStringBuilder(indentChar string, charsPerIndentLevel int) *IndentStringBuilder { - return &IndentStringBuilder{ - indentChar: indentChar, - charsPerIndentLevel: charsPerIndentLevel, - } -} - -func (b *IndentStringBuilder) WriteQueryFunctionArgs(args []core.FunctionArg, conf *core.Config) { - for i, arg := range args { - if i == 0 && len(args) > int(*conf.OmitKwargsLimit) { - b.WriteString(", *") - } - b.WriteString(fmt.Sprintf(", %s", arg.FunctionFormat)) - } -} - -func (b *IndentStringBuilder) WriteIndentedString(level int, txt string) int { - count, _ := b.WriteString(strings.Repeat(b.indentChar, level*b.charsPerIndentLevel) + txt) - return count -} - -func (b *IndentStringBuilder) WriteSqlcHeader() { - sqlcVersion := os.Getenv("SQLC_VERSION") - - b.WriteString("# Code generated by sqlc. DO NOT EDIT.\n") - b.WriteString("# versions:\n") - b.WriteString("# sqlc " + sqlcVersion + "\n") - b.WriteString("# sqlc-gen-better-python " + core.PluginVersion + "\n") -} - -func (b *IndentStringBuilder) WriteLine(txt string) { - b.WriteString(txt) - b.WriteString("\n") -} - -func (b *IndentStringBuilder) WriteIndentedLine(level int, txt string) { - b.WriteIndentedString(level, txt) - b.WriteString("\n") -} - -func (b *IndentStringBuilder) WriteImportAnnotations() { - b.WriteLine("from __future__ import annotations") - b.WriteString("\n") -} - -func (b *IndentStringBuilder) NewLine() { - b.WriteString("\n") -} - -func (b *IndentStringBuilder) NNewLine(n int) { - for range n { - b.WriteString("\n") - } -} diff --git a/internal/codegen/common.go b/internal/codegen/common.go deleted file mode 100644 index e302e4f3..00000000 --- a/internal/codegen/common.go +++ /dev/null @@ -1,81 +0,0 @@ -package codegen - -import ( - "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/codegen/builders" - "github.com/rayakame/sqlc-gen-better-python/internal/codegen/drivers" - "github.com/rayakame/sqlc-gen-better-python/internal/core" -) - -type TypeBuildPyQueryFunc func(*core.Query, *builders.IndentStringBuilder, []core.FunctionArg, core.PyType, *core.Config) error -type TypeAcceptedDriverCMDs func() []string -type TypeDriverTypeCheckingHook func() []string -type TypeDriverBuildQueryResults func(*builders.IndentStringBuilder) string - -func defaultDriverTypeCheckingHook() []string { - return nil -} -func defaultDriverBuildQueryResults(_ *builders.IndentStringBuilder) string { - return "" -} - -type Driver struct { - conf *core.Config - - connType string - buildPyQueryFunc TypeBuildPyQueryFunc - acceptedDriverCMDs TypeAcceptedDriverCMDs - - driverTypeCheckingHook TypeDriverTypeCheckingHook - driverBuildQueryResults TypeDriverBuildQueryResults - - //BuildPyQueriesFiles(*core.Importer, []core.Query) ([]*plugin.File, error) -} - -func NewDriver(conf *core.Config) (*Driver, error) { - var buildPyQueryFunc TypeBuildPyQueryFunc - var acceptedDriverCMDs TypeAcceptedDriverCMDs - var connType string - var driverTypeCheckingHook TypeDriverTypeCheckingHook = defaultDriverTypeCheckingHook - var driverBuildQueryResults TypeDriverBuildQueryResults = defaultDriverBuildQueryResults - switch conf.SqlDriver { - case core.SQLDriverAioSQLite: - buildPyQueryFunc = drivers.AioSQLiteBuildPyQueryFunc - acceptedDriverCMDs = drivers.AioSQLiteAcceptedDriverCMDs - connType = drivers.AioSQLiteConn - driverBuildQueryResults = drivers.AiosqliteBuildQueryResults - case core.SQLDriverSQLite: - buildPyQueryFunc = drivers.SQLite3BuildPyQueryFunc - acceptedDriverCMDs = drivers.SQLite3AcceptedDriverCMDs - connType = drivers.SQLite3Conn - driverBuildQueryResults = drivers.SQLite3BuildQueryResults - case core.SQLDriverAsyncpg: - buildPyQueryFunc = drivers.AsyncpgBuildPyQueryFunc - acceptedDriverCMDs = drivers.AsyncpgAcceptedDriverCMDs - connType = drivers.AsyncpgConn - driverTypeCheckingHook = drivers.AsyncpgTypeCheckingHook - driverBuildQueryResults = drivers.AsyncpgBuildQueryResults - default: - return nil, fmt.Errorf("unsupported driver: %s", conf.SqlDriver.String()) - } - builders.SetDocstringConfig(conf.EmitDocstrings, conf.EmitDocstringsSQL, conf.SqlDriver) - - return &Driver{ - buildPyQueryFunc: buildPyQueryFunc, - acceptedDriverCMDs: acceptedDriverCMDs, - conf: conf, - connType: connType, - driverTypeCheckingHook: driverTypeCheckingHook, - driverBuildQueryResults: driverBuildQueryResults, - }, nil -} - -func (dr *Driver) supportedCMD(command string) error { - cmds := dr.acceptedDriverCMDs() - for _, cmd := range cmds { - if cmd == command { - return nil - } - } - return fmt.Errorf("unsupported command for selected driver: %s", command) -} diff --git a/internal/codegen/drivers/aiosqlite.go b/internal/codegen/drivers/aiosqlite.go deleted file mode 100644 index fe634fae..00000000 --- a/internal/codegen/drivers/aiosqlite.go +++ /dev/null @@ -1,316 +0,0 @@ -package drivers - -import ( - "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/codegen/builders" - "github.com/rayakame/sqlc-gen-better-python/internal/core" - "github.com/rayakame/sqlc-gen-better-python/internal/typeConversion" - "github.com/rayakame/sqlc-gen-better-python/internal/types" - "github.com/sqlc-dev/plugin-sdk-go/metadata" - "github.com/sqlc-dev/plugin-sdk-go/plugin" - "strconv" - "strings" -) - -const AioSQLiteConn = "aiosqlite.Connection" - -func AioSQLiteBuildTypeConvFunc(queries []core.Query, body *builders.IndentStringBuilder, conf *core.Config) { - // this function fucking got out of hand - queryValueUses := func(name string, qv core.QueryValue) bool { - if !qv.IsEmpty() { - if qv.IsStruct() && qv.EmitStruct() { - if val, pyType := core.TableUses(name, *qv.Table); val { - if pyType.DoConversion(typeConversion.SqliteDoTypeConversion) { - return true - } - } - } else if qv.IsStruct() { - if val, pyType := core.TableUses(name, *qv.Table); val { - if pyType.DoConversion(typeConversion.SqliteDoTypeConversion) { - return true - } - } - } else { - if qv.Typ.Type == name { - if qv.Typ.DoConversion(typeConversion.SqliteDoTypeConversion) { - return true - } - } - } - } - return false - } - toConvert := make(map[string]bool) - for _, query := range queries { - for sqlType, _ := range typeConversion.SqliteGetConversions() { - name := types.SqliteTypeToPython(&plugin.GenerateRequest{}, &plugin.Column{Type: &plugin.Identifier{ - Catalog: "", - Schema: "", - Name: sqlType, - }}, conf) - if queryValueUses(name, query.Ret) { - toConvert[name] = true - } - for _, arg := range query.Args { - if queryValueUses(name, arg) { - toConvert[name] = true - } - } - } - } - adapters := make([]string, 0) - converters := make([]string, 0) - if _, found := toConvert["datetime.date"]; found { - body.WriteLine("def _adapt_date(val: datetime.date) -> str:") - body.WriteIndentedLine(1, "return val.isoformat()") - body.NNewLine(2) - adapters = append(adapters, "aiosqlite.register_adapter(datetime.date, _adapt_date)") - body.WriteLine("def _convert_date(val: bytes) -> datetime.date:") - if conf.Speedups { - body.WriteIndentedLine(1, "return ciso8601.parse_datetime(val.decode()).date()") - } else { - body.WriteIndentedLine(1, "return datetime.date.fromisoformat(val.decode())") - } - body.NNewLine(2) - converters = append(converters, `aiosqlite.register_converter("date", _convert_date)`) - } - if _, found := toConvert["decimal.Decimal"]; found { - body.WriteLine("def _adapt_decimal(val: decimal.Decimal) -> str:") - body.WriteIndentedLine(1, "return str(val)") - body.NNewLine(2) - adapters = append(adapters, "aiosqlite.register_adapter(decimal.Decimal, _adapt_decimal)") - body.WriteLine("def _convert_decimal(val: bytes) -> decimal.Decimal:") - body.WriteIndentedLine(1, "return decimal.Decimal(val.decode())") - body.NNewLine(2) - converters = append(converters, `aiosqlite.register_converter("decimal", _convert_decimal)`) - } - if _, found := toConvert["datetime.datetime"]; found { - body.WriteLine("def _adapt_datetime(val: datetime.datetime) -> str:") - body.WriteIndentedLine(1, "return val.isoformat()") - body.NNewLine(2) - adapters = append(adapters, "aiosqlite.register_adapter(datetime.datetime, _adapt_datetime)") - body.WriteLine("def _convert_datetime(val: bytes) -> datetime.datetime:") - if conf.Speedups { - body.WriteIndentedLine(1, "return ciso8601.parse_datetime(val.decode())") - } else { - body.WriteIndentedLine(1, "return datetime.datetime.fromisoformat(val.decode())") - } - body.NNewLine(2) - converters = append(converters, `aiosqlite.register_converter("datetime", _convert_datetime)`) - converters = append(converters, `aiosqlite.register_converter("timestamp", _convert_datetime)`) - } - if _, found := toConvert["bool"]; found { - body.WriteLine("def _adapt_bool(val: bool) -> int:") - body.WriteIndentedLine(1, "return int(val)") - body.NNewLine(2) - adapters = append(adapters, "aiosqlite.register_adapter(bool, _adapt_bool)") - body.WriteLine("def _convert_bool(val: bytes) -> bool:") - body.WriteIndentedLine(1, "return bool(int(val))") - body.NNewLine(2) - converters = append(converters, `aiosqlite.register_converter("bool", _convert_bool)`) - converters = append(converters, `aiosqlite.register_converter("boolean", _convert_bool)`) - } - if _, found := toConvert["memoryview"]; found { - body.WriteLine("def _adapt_memoryview(val: memoryview) -> bytes:") - body.WriteIndentedLine(1, "return val.tobytes()") - body.NNewLine(2) - adapters = append(adapters, "aiosqlite.register_adapter(memoryview, _adapt_memoryview)") - body.WriteLine("def _convert_memoryview(val: bytes) -> memoryview:") - body.WriteIndentedLine(1, "return memoryview(val)") - body.NNewLine(2) - converters = append(converters, `aiosqlite.register_converter("blob", _convert_memoryview)`) - } - for i, line := range adapters { - body.WriteLine(line) - if i == len(adapters)-1 { - body.NewLine() - } - } - for i, line := range converters { - body.WriteLine(line) - if i == len(converters)-1 { - body.NNewLine(2) - } - } -} - -func AiosqliteBuildQueryResults(body *builders.IndentStringBuilder) string { - body.WriteAsyncQueryResultsClassHeader(AioSQLiteConn, []string{ - "self._cursor: aiosqlite.Cursor | None = None", - fmt.Sprintf("self._iterator: collections.abc.AsyncIterator[%s] | None = None", Sqlite3Result), - }, Sqlite3Result) - body.WriteQueryResultsAwaitFunction([]string{ - "result = await (await self._conn.execute(self._sql, self._args)).fetchall()", - "return [self._decode_hook(row) for row in result]", - }) - body.NewLine() - body.WriteIndentedLine(1, "async def __anext__(self) -> T:") - body.WriteQueryResultsAnextDocstringAiosqlite() - body.WriteIndentedLine(2, "if self._cursor is None or self._iterator is None:") - body.WriteIndentedLine(3, "self._cursor: aiosqlite.Cursor | None = await self._conn.execute(self._sql, self._args)") - body.WriteIndentedLine(3, "self._iterator = self._cursor.__aiter__()") - body.WriteIndentedLine(2, "try:") - body.WriteIndentedLine(3, "record = await self._iterator.__anext__()") - body.WriteIndentedLine(2, "except StopAsyncIteration:") - body.WriteIndentedLine(3, "self._cursor = None") - body.WriteIndentedLine(3, "self._iterator = None") - body.WriteIndentedLine(3, "raise") - body.WriteIndentedLine(2, "return self._decode_hook(record)") - return "QueryResults" -} - -func AioSQLiteBuildPyQueryFunc(query *core.Query, body *builders.IndentStringBuilder, args []core.FunctionArg, retType core.PyType, conf *core.Config) error { - indentLevel := 0 - params := fmt.Sprintf("conn: %s", AioSQLiteConn) - conn := "conn" - asyncFunc := "async " - docstringConnType := AioSQLiteConn - if conf.EmitClasses { - params = "self" - conn = "self._conn" - indentLevel = 1 - docstringConnType = "" - } - if query.Cmd == metadata.CmdMany { - asyncFunc = "" - } - body.WriteIndentedString(indentLevel, fmt.Sprintf("%sdef %s(%s", asyncFunc, query.FuncName, params)) - body.WriteQueryFunctionArgs(args, conf) - if query.Cmd == metadata.CmdExec { - body.WriteLine(fmt.Sprintf(") -> %s:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("await %s.execute(%s", conn, query.ConstantName)) - sqlite3WriteParams(query, body) - body.WriteLine(")") - } else if query.Cmd == metadata.CmdExecResult { - body.WriteLine(fmt.Sprintf(") -> %s:", "aiosqlite.Cursor")) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, core.PyType{Type: "aiosqlite.Cursor"}) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return await %s.execute(%s", conn, query.ConstantName)) - sqlite3WriteParams(query, body) - body.WriteLine(")") - } else if query.Cmd == metadata.CmdExecRows { - body.WriteLine(fmt.Sprintf(") -> %s:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return (await %s.execute(%s", conn, query.ConstantName)) - sqlite3WriteParams(query, body) - body.WriteLine(")).rowcount") - } else if query.Cmd == metadata.CmdExecLastId { - body.WriteLine(fmt.Sprintf(") -> %s:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return (await %s.execute(%s", conn, query.ConstantName)) - sqlite3WriteParams(query, body) - body.WriteLine(")).lastrowid") - } else if query.Cmd == metadata.CmdOne { - body.WriteLine(fmt.Sprintf(") -> %s | None:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("row = await (await %s.execute(%s", conn, query.ConstantName)) - sqlite3WriteParams(query, body) - body.WriteLine(")).fetchone()") - body.WriteIndentedLine(indentLevel+1, "if row is None:") - body.WriteIndentedLine(indentLevel+2, "return None") - if query.Ret.IsStruct() { - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return %s(", retType.Type)) - i := 0 - for _, col := range query.Ret.Table.Columns { - if i != 0 { - body.WriteString(", ") - } - if len(col.EmbedFields) != 0 { - var inner []string - body.WriteString(fmt.Sprintf("%s=%s(", col.Name, col.Type.Type)) - for _, embedCol := range col.EmbedFields { - if embedCol.Type.DoOverride() { - inner = append(inner, fmt.Sprintf("%s=%s(row[%s])", embedCol.Name, embedCol.Type.Type, strconv.Itoa(i))) - } else { - inner = append(inner, fmt.Sprintf("%s=row[%s]", embedCol.Name, strconv.Itoa(i))) - } - i++ - } - body.WriteString(strings.Join(inner, ", ") + ")") - } else { - if col.Type.DoOverride() { - body.WriteString(fmt.Sprintf("%s=%s(row[%s])", col.Name, col.Type.Type, strconv.Itoa(i))) - } else { - body.WriteString(fmt.Sprintf("%s=row[%s]", col.Name, strconv.Itoa(i))) - } - i++ - } - } - body.WriteLine(")") - } else { - if query.Ret.Typ.DoOverride() { - body.WriteIndentedLine(indentLevel+1, fmt.Sprintf("return %s(row[0])", query.Ret.Typ.Type)) - } else { - body.WriteIndentedLine(indentLevel+1, "return row[0]") - } - } - } else if query.Cmd == metadata.CmdMany { - body.WriteLine(fmt.Sprintf(") -> QueryResults[%s]:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - - decodeHook := "_decode_hook" - if !query.Ret.IsStruct() && !query.Ret.Typ.DoOverride() { - decodeHook = "operator.itemgetter(0)" - } else if !query.Ret.IsStruct() && query.Ret.Typ.DoOverride() { - body.WriteIndentedLine(indentLevel+1, fmt.Sprintf("def _decode_hook(row: %s) -> %s:", Sqlite3Result, retType.Type)) - body.WriteIndentedLine(indentLevel+2, fmt.Sprintf("return %s(row[0])", retType.Type)) - } else { - body.WriteIndentedLine(indentLevel+1, fmt.Sprintf("def _decode_hook(row: %s) -> %s:", Sqlite3Result, retType.Type)) - body.WriteIndentedString(indentLevel+2, fmt.Sprintf("return %s(", retType.Type)) - i := 0 - for _, col := range query.Ret.Table.Columns { - if i != 0 { - body.WriteString(", ") - } - if len(col.EmbedFields) != 0 { - var inner []string - body.WriteString(fmt.Sprintf("%s=%s(", col.Name, col.Type.Type)) - for _, embedCol := range col.EmbedFields { - if embedCol.Type.DoOverride() { - inner = append(inner, fmt.Sprintf("%s=%s(row[%s])", embedCol.Name, embedCol.Type.Type, strconv.Itoa(i))) - } else { - inner = append(inner, fmt.Sprintf("%s=row[%s]", embedCol.Name, strconv.Itoa(i))) - } - i++ - } - body.WriteString(strings.Join(inner, ", ") + ")") - } else { - if col.Type.DoOverride() { - body.WriteString(fmt.Sprintf("%s=%s(row[%s])", col.Name, col.Type.Type, strconv.Itoa(i))) - } else { - body.WriteString(fmt.Sprintf("%s=row[%s]", col.Name, strconv.Itoa(i))) - } - i++ - } - } - body.WriteLine(")") - } - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return QueryResults[%s](%s, %s, %s", retType.Type, conn, query.ConstantName, decodeHook)) - params := "" - for i, arg := range query.Args { - if !arg.IsEmpty() { - if i == len(query.Args)-1 { - params += fmt.Sprintf(" %s", arg.Name) - } else { - params += fmt.Sprintf(" %s,", arg.Name) - } - } - } - if params != "" { - body.WriteString("," + params) - } - body.WriteLine(")") - } - return nil -} - -func AioSQLiteAcceptedDriverCMDs() []string { - return []string{ - metadata.CmdExec, - metadata.CmdExecResult, - metadata.CmdExecLastId, - metadata.CmdExecRows, - metadata.CmdOne, - metadata.CmdMany, - } -} diff --git a/internal/codegen/drivers/asyncpg.go b/internal/codegen/drivers/asyncpg.go deleted file mode 100644 index 87f1e605..00000000 --- a/internal/codegen/drivers/asyncpg.go +++ /dev/null @@ -1,251 +0,0 @@ -package drivers - -import ( - "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/codegen/builders" - "github.com/rayakame/sqlc-gen-better-python/internal/core" - "github.com/rayakame/sqlc-gen-better-python/internal/typeConversion" - "github.com/sqlc-dev/plugin-sdk-go/metadata" - "strconv" - "strings" -) - -const AsyncpgConn = "ConnectionLike" -const AsyncpgResult = "asyncpg.Record" - -func AsyncpgTypeCheckingHook() []string { - return []string{ - fmt.Sprintf( - "ConnectionLike: typing.TypeAlias = asyncpg.Connection[%[1]s] | asyncpg.pool.PoolConnectionProxy[%[1]s]", - AsyncpgResult, - ), - } -} - -func AsyncpgBuildQueryResults(body *builders.IndentStringBuilder) string { - body.WriteAsyncQueryResultsClassHeader(AsyncpgConn, []string{ - fmt.Sprintf("self._cursor: asyncpg.cursor.CursorFactory[%s] | None = None", AsyncpgResult), - fmt.Sprintf("self._iterator: asyncpg.cursor.CursorIterator[%s] | None = None", AsyncpgResult), - }, AsyncpgResult) - body.WriteQueryResultsAwaitFunction([]string{ - "result = await self._conn.fetch(self._sql, *self._args)", - "return [self._decode_hook(row) for row in result]", - }) - body.NewLine() - body.WriteIndentedLine(1, "async def __anext__(self) -> T:") - body.WriteQueryResultsAnextDocstringAsyncpg() - body.WriteIndentedLine(2, "if self._cursor is None or self._iterator is None:") - body.WriteIndentedLine(3, "self._cursor = self._conn.cursor(self._sql, *self._args)") - body.WriteIndentedLine(3, "self._iterator = self._cursor.__aiter__()") - body.WriteIndentedLine(2, "try:") - body.WriteIndentedLine(3, "record = await self._iterator.__anext__()") - body.WriteIndentedLine(2, "except StopAsyncIteration:") - body.WriteIndentedLine(3, "self._cursor = None") - body.WriteIndentedLine(3, "self._iterator = None") - body.WriteIndentedLine(3, "raise") - body.WriteIndentedLine(2, "return self._decode_hook(record)") - return "QueryResults" -} - -func AsyncpgBuildPyQueryFunc(query *core.Query, body *builders.IndentStringBuilder, args []core.FunctionArg, retType core.PyType, conf *core.Config) error { - indentLevel := 0 - params := fmt.Sprintf("conn: %s", AsyncpgConn) - conn := "conn" - asyncFunc := "async " - docstringConnType := AsyncpgConn - if conf.EmitClasses { - params = "self" - conn = "self._conn" - indentLevel = 1 - docstringConnType = "" - } - if query.Cmd == metadata.CmdMany { - asyncFunc = "" - } - body.WriteIndentedString(indentLevel, fmt.Sprintf("%sdef %s(%s", asyncFunc, query.FuncName, params)) - body.WriteQueryFunctionArgs(args, conf) - if query.Cmd == metadata.CmdExec { - body.WriteLine(fmt.Sprintf(") -> %s:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("await %s.execute(%s", conn, query.ConstantName)) - asyncpgWriteParams(query, body) - body.WriteLine(")") - } else if query.Cmd == metadata.CmdExecResult { - body.WriteLine(") -> str:") - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, core.PyType{Type: "str"}) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return await %s.execute(%s", conn, query.ConstantName)) - asyncpgWriteParams(query, body) - body.WriteLine(")") - } else if query.Cmd == metadata.CmdExecRows { - body.WriteLine(fmt.Sprintf(") -> %s:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("r = await %s.execute(%s", conn, query.ConstantName)) - asyncpgWriteParams(query, body) - body.WriteLine(")") - if conf.Speedups { - body.WriteIndentedLine(indentLevel+1, "return int(n) if (n := r.split()[-1]).isdigit() else 0") - } else { - body.WriteIndentedLine(indentLevel+1, "return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0") - } - } else if query.Cmd == metadata.CmdCopyFrom { - body.WriteLine(fmt.Sprintf(") -> %s:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - body.WriteIndentedLine(indentLevel+1, "records = [") - params := "" - columns := `` - for i, arg := range query.Args[0].Table.Columns { - if i == len(query.Args[0].Table.Columns)-1 && i != 0 { - params += fmt.Sprintf("%s.%s", "param", arg.Name) - columns += fmt.Sprintf(`"%s"`, arg.Name) - } else { - params += fmt.Sprintf("%s.%s, ", "param", arg.Name) - columns += fmt.Sprintf(`"%s", `, arg.Name) - } - } - body.WriteIndentedLine(indentLevel+2, fmt.Sprintf("(%s)", params)) - body.WriteIndentedLine(indentLevel+2, fmt.Sprintf("for param in %s", query.Args[0].Name)) - body.WriteIndentedLine(indentLevel+1, "]") - body.WriteIndentedLine(indentLevel+1, fmt.Sprintf(`r = await %s.copy_records_to_table("%s", columns=[%s], records=records)`, conn, query.Table.Name, columns)) - if conf.Speedups { - body.WriteIndentedLine(indentLevel+1, "return int(n) if (n := r.split()[-1]).isdigit() else 0") - } else { - body.WriteIndentedLine(indentLevel+1, "return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0") - } - } else if query.Cmd == metadata.CmdOne { - body.WriteLine(fmt.Sprintf(") -> %s | None:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("row = await %s.fetchrow(%s", conn, query.ConstantName)) - asyncpgWriteParams(query, body) - body.WriteLine(")") - body.WriteIndentedLine(indentLevel+1, "if row is None:") - body.WriteIndentedLine(indentLevel+2, "return None") - if query.Ret.IsStruct() { - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return %s(", retType.Type)) - i := 0 - for _, col := range query.Ret.Table.Columns { - if i != 0 { - body.WriteString(", ") - } - if len(col.EmbedFields) != 0 { - var inner []string - body.WriteString(fmt.Sprintf("%s=%s(", col.Name, col.Type.Type)) - for _, embedCol := range col.EmbedFields { - if embedCol.Type.DoOverride() || embedCol.Type.DoConversion(typeConversion.AsyncpgDoTypeConversion) { - if embedCol.Type.IsNullable { - inner = append(inner, fmt.Sprintf("%s=%s(row[%s]) if row[%s] is not None else None", embedCol.Name, embedCol.Type.Type, strconv.Itoa(i), strconv.Itoa(i))) - } else { - inner = append(inner, fmt.Sprintf("%s=%s(row[%s])", embedCol.Name, embedCol.Type.Type, strconv.Itoa(i))) - } - } else { - inner = append(inner, fmt.Sprintf("%s=row[%s]", embedCol.Name, strconv.Itoa(i))) - } - i++ - } - body.WriteString(strings.Join(inner, ", ") + ")") - } else { - if col.Type.DoConversion(typeConversion.AsyncpgDoTypeConversion) || col.Type.DoOverride() { - if col.Type.IsNullable { - body.WriteString(fmt.Sprintf("%s=%s(row[%s]) if row[%s] is not None else None", col.Name, col.Type.Type, strconv.Itoa(i), strconv.Itoa(i))) - } else { - body.WriteString(fmt.Sprintf("%s=%s(row[%s])", col.Name, col.Type.Type, strconv.Itoa(i))) - } - } else { - body.WriteString(fmt.Sprintf("%s=row[%s]", col.Name, strconv.Itoa(i))) - } - i++ - } - } - body.WriteLine(")") - } else { - if retType.DoConversion(typeConversion.AsyncpgDoTypeConversion) || retType.DoOverride() { - body.WriteIndentedLine(indentLevel+1, fmt.Sprintf("return %s(row[0])", retType.Type)) - } else { - body.WriteIndentedLine(indentLevel+1, "return row[0]") - } - } - } else if query.Cmd == metadata.CmdMany { - body.WriteLine(fmt.Sprintf(") -> QueryResults[%s]:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - decode_hook := "_decode_hook" - if !query.Ret.IsStruct() && !(retType.DoConversion(typeConversion.AsyncpgDoTypeConversion) || retType.DoOverride()) { - decode_hook = "operator.itemgetter(0)" - } else if !query.Ret.IsStruct() { - body.WriteIndentedLine(indentLevel+1, fmt.Sprintf("def _decode_hook(row: %s) -> %s:", AsyncpgResult, retType.Type)) - body.WriteIndentedLine(indentLevel+2, fmt.Sprintf("return %s(row[0])", retType.Type)) - } else { - body.WriteIndentedLine(indentLevel+1, fmt.Sprintf("def _decode_hook(row: %s) -> %s:", AsyncpgResult, retType.Type)) - body.WriteIndentedString(indentLevel+2, fmt.Sprintf("return %s(", retType.Type)) - i := 0 - for _, col := range query.Ret.Table.Columns { - if i != 0 { - body.WriteString(", ") - } - if len(col.EmbedFields) != 0 { - var inner []string - body.WriteString(fmt.Sprintf("%s=%s(", col.Name, col.Type.Type)) - for _, embedCol := range col.EmbedFields { - if embedCol.Type.DoOverride() || embedCol.Type.DoConversion(typeConversion.AsyncpgDoTypeConversion) { - if embedCol.Type.IsNullable { - inner = append(inner, fmt.Sprintf("%s=%s(row[%s]) if row[%s] is not None else None", embedCol.Name, embedCol.Type.Type, strconv.Itoa(i), strconv.Itoa(i))) - } else { - inner = append(inner, fmt.Sprintf("%s=%s(row[%s])", embedCol.Name, embedCol.Type.Type, strconv.Itoa(i))) - } - } else { - inner = append(inner, fmt.Sprintf("%s=row[%s]", embedCol.Name, strconv.Itoa(i))) - } - i++ - } - body.WriteString(strings.Join(inner, ", ") + ")") - } else { - if col.Type.DoConversion(typeConversion.AsyncpgDoTypeConversion) || col.Type.DoOverride() { - if col.Type.IsNullable { - body.WriteString(fmt.Sprintf("%s=%s(row[%s]) if row[%s] is not None else None", col.Name, col.Type.Type, strconv.Itoa(i), strconv.Itoa(i))) - } else { - body.WriteString(fmt.Sprintf("%s=%s(row[%s])", col.Name, col.Type.Type, strconv.Itoa(i))) - } - } else { - body.WriteString(fmt.Sprintf("%s=row[%s]", col.Name, strconv.Itoa(i))) - } - i++ - } - } - body.WriteLine(")") - } - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return QueryResults[%s](%s, %s, %s", retType.Type, conn, query.ConstantName, decode_hook)) - asyncpgWriteParams(query, body) - body.WriteLine(")") - } - return nil -} - -func AsyncpgAcceptedDriverCMDs() []string { - return []string{ - metadata.CmdExec, - metadata.CmdExecResult, - metadata.CmdExecRows, - metadata.CmdOne, - metadata.CmdMany, - metadata.CmdCopyFrom, - } -} - -func asyncpgWriteParams(query *core.Query, body *builders.IndentStringBuilder) { - if len(query.Args) == 0 { - return - } - params := "" - for i, arg := range query.Args { - if !arg.IsEmpty() { - argName := arg.Name - if arg.Typ.DoOverride() { - argName = fmt.Sprintf("%s(%s)", arg.Typ.DefaultType, argName) - } - if i == len(query.Args)-1 { - params += fmt.Sprintf(" %s", argName) - } else { - params += fmt.Sprintf(" %s,", argName) - } - } - } - body.WriteString("," + params) -} diff --git a/internal/codegen/drivers/sqlite3.go b/internal/codegen/drivers/sqlite3.go deleted file mode 100644 index e43f78c3..00000000 --- a/internal/codegen/drivers/sqlite3.go +++ /dev/null @@ -1,334 +0,0 @@ -package drivers - -import ( - "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/codegen/builders" - "github.com/rayakame/sqlc-gen-better-python/internal/core" - "github.com/rayakame/sqlc-gen-better-python/internal/typeConversion" - "github.com/rayakame/sqlc-gen-better-python/internal/types" - "github.com/sqlc-dev/plugin-sdk-go/metadata" - "github.com/sqlc-dev/plugin-sdk-go/plugin" - "strconv" - "strings" -) - -const Sqlite3Result = "sqlite3.Row" -const SQLite3Conn = "sqlite3.Connection" - -func SQLite3BuildTypeConvFunc(queries []core.Query, body *builders.IndentStringBuilder, conf *core.Config) { - // this function fucking got out of hand - queryValueUses := func(name string, qv core.QueryValue) bool { - if !qv.IsEmpty() { - if qv.IsStruct() && qv.EmitStruct() { - if val, pyType := core.TableUses(name, *qv.Table); val { - if pyType.DoConversion(typeConversion.SqliteDoTypeConversion) { - return true - } - } - } else if qv.IsStruct() { - if val, pyType := core.TableUses(name, *qv.Table); val { - if pyType.DoConversion(typeConversion.SqliteDoTypeConversion) { - return true - } - } - } else { - if qv.Typ.Type == name { - if qv.Typ.DoConversion(typeConversion.SqliteDoTypeConversion) { - return true - } - } - } - } - return false - } - toConvert := make(map[string]bool) - for _, query := range queries { - for sqlType, _ := range typeConversion.SqliteGetConversions() { - name := types.SqliteTypeToPython(&plugin.GenerateRequest{}, &plugin.Column{Type: &plugin.Identifier{ - Catalog: "", - Schema: "", - Name: sqlType, - }}, conf) - if queryValueUses(name, query.Ret) { - toConvert[name] = true - } - for _, arg := range query.Args { - if queryValueUses(name, arg) { - toConvert[name] = true - } - } - } - } - adapters := make([]string, 0) - converters := make([]string, 0) - if _, found := toConvert["datetime.date"]; found { - body.WriteLine("def _adapt_date(val: datetime.date) -> str:") - body.WriteIndentedLine(1, "return val.isoformat()") - body.NNewLine(2) - adapters = append(adapters, "sqlite3.register_adapter(datetime.date, _adapt_date)") - body.WriteLine("def _convert_date(val: bytes) -> datetime.date:") - if conf.Speedups { - body.WriteIndentedLine(1, "return ciso8601.parse_datetime(val.decode()).date()") - } else { - body.WriteIndentedLine(1, "return datetime.date.fromisoformat(val.decode())") - } - body.NNewLine(2) - converters = append(converters, `sqlite3.register_converter("date", _convert_date)`) - } - if _, found := toConvert["decimal.Decimal"]; found { - body.WriteLine("def _adapt_decimal(val: decimal.Decimal) -> str:") - body.WriteIndentedLine(1, "return str(val)") - body.NNewLine(2) - adapters = append(adapters, "sqlite3.register_adapter(decimal.Decimal, _adapt_decimal)") - body.WriteLine("def _convert_decimal(val: bytes) -> decimal.Decimal:") - body.WriteIndentedLine(1, "return decimal.Decimal(val.decode())") - body.NNewLine(2) - converters = append(converters, `sqlite3.register_converter("decimal", _convert_decimal)`) - } - if _, found := toConvert["datetime.datetime"]; found { - body.WriteLine("def _adapt_datetime(val: datetime.datetime) -> str:") - body.WriteIndentedLine(1, "return val.isoformat()") - body.NNewLine(2) - adapters = append(adapters, "sqlite3.register_adapter(datetime.datetime, _adapt_datetime)") - body.WriteLine("def _convert_datetime(val: bytes) -> datetime.datetime:") - if conf.Speedups { - body.WriteIndentedLine(1, "return ciso8601.parse_datetime(val.decode())") - } else { - body.WriteIndentedLine(1, "return datetime.datetime.fromisoformat(val.decode())") - } - body.NNewLine(2) - converters = append(converters, `sqlite3.register_converter("datetime", _convert_datetime)`) - converters = append(converters, `sqlite3.register_converter("timestamp", _convert_datetime)`) - } - if _, found := toConvert["bool"]; found { - body.WriteLine("def _adapt_bool(val: bool) -> int:") - body.WriteIndentedLine(1, "return int(val)") - body.NNewLine(2) - adapters = append(adapters, "sqlite3.register_adapter(bool, _adapt_bool)") - body.WriteLine("def _convert_bool(val: bytes) -> bool:") - body.WriteIndentedLine(1, "return bool(int(val))") - body.NNewLine(2) - converters = append(converters, `sqlite3.register_converter("bool", _convert_bool)`) - converters = append(converters, `sqlite3.register_converter("boolean", _convert_bool)`) - } - if _, found := toConvert["memoryview"]; found { - body.WriteLine("def _adapt_memoryview(val: memoryview) -> bytes:") - body.WriteIndentedLine(1, "return val.tobytes()") - body.NNewLine(2) - adapters = append(adapters, "sqlite3.register_adapter(memoryview, _adapt_memoryview)") - body.WriteLine("def _convert_memoryview(val: bytes) -> memoryview:") - body.WriteIndentedLine(1, "return memoryview(val)") - body.NNewLine(2) - converters = append(converters, `sqlite3.register_converter("blob", _convert_memoryview)`) - } - for i, line := range adapters { - body.WriteLine(line) - if i == len(adapters)-1 { - body.NewLine() - } - } - for i, line := range converters { - body.WriteLine(line) - if i == len(converters)-1 { - body.NNewLine(2) - } - } -} - -func SQLite3BuildQueryResults(body *builders.IndentStringBuilder) string { - body.WriteSyncQueryResultsClassHeader(SQLite3Conn, []string{ - "self._cursor: sqlite3.Cursor | None = None", - fmt.Sprintf("self._iterator: collections.abc.Iterator[%s] | None = None", Sqlite3Result), - }, Sqlite3Result) - body.WriteQueryResultsCallFunction([]string{ - "result = self._conn.execute(self._sql, self._args).fetchall()", - "return [self._decode_hook(row) for row in result]", - }) - body.NewLine() - body.WriteIndentedLine(1, "def __next__(self) -> T:") - body.WriteQueryResultsNextDocstringSqlite() - body.WriteIndentedLine(2, "if self._cursor is None or self._iterator is None:") - body.WriteIndentedLine(3, "self._cursor: sqlite3.Cursor | None = self._conn.execute(self._sql, self._args)") - body.WriteIndentedLine(3, "self._iterator = self._cursor.__iter__()") - body.WriteIndentedLine(2, "try:") - body.WriteIndentedLine(3, "record = self._iterator.__next__()") - body.WriteIndentedLine(2, "except StopIteration:") - body.WriteIndentedLine(3, "self._cursor = None") - body.WriteIndentedLine(3, "self._iterator = None") - body.WriteIndentedLine(3, "raise") - body.WriteIndentedLine(2, "return self._decode_hook(record)") - return "QueryResults" -} - -func SQLite3BuildPyQueryFunc(query *core.Query, body *builders.IndentStringBuilder, args []core.FunctionArg, retType core.PyType, conf *core.Config) error { - indentLevel := 0 - params := fmt.Sprintf("conn: %s", SQLite3Conn) - conn := "conn" - docstringConnType := SQLite3Conn - if conf.EmitClasses { - params = "self" - conn = "self._conn" - indentLevel = 1 - docstringConnType = "" - } - body.WriteIndentedString(indentLevel, fmt.Sprintf("def %s(%s", query.FuncName, params)) - body.WriteQueryFunctionArgs(args, conf) - if query.Cmd == metadata.CmdExec { - body.WriteLine(fmt.Sprintf(") -> %s:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("%s.execute(%s", conn, query.ConstantName)) - sqlite3WriteParams(query, body) - body.WriteLine(")") - } else if query.Cmd == metadata.CmdExecResult { - body.WriteLine(fmt.Sprintf(") -> %s:", "sqlite3.Cursor")) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, core.PyType{Type: "sqlite3.Cursor"}) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return %s.execute(%s", conn, query.ConstantName)) - sqlite3WriteParams(query, body) - body.WriteLine(")") - } else if query.Cmd == metadata.CmdExecRows { - body.WriteLine(fmt.Sprintf(") -> %s:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return %s.execute(%s", conn, query.ConstantName)) - sqlite3WriteParams(query, body) - body.WriteLine(").rowcount") - } else if query.Cmd == metadata.CmdExecLastId { - body.WriteLine(fmt.Sprintf(") -> %s:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return %s.execute(%s", conn, query.ConstantName)) - sqlite3WriteParams(query, body) - body.WriteLine(").lastrowid") - } else if query.Cmd == metadata.CmdOne { - body.WriteLine(fmt.Sprintf(") -> %s | None:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("row = %s.execute(%s", conn, query.ConstantName)) - sqlite3WriteParams(query, body) - body.WriteLine(").fetchone()") - body.WriteIndentedLine(indentLevel+1, "if row is None:") - body.WriteIndentedLine(indentLevel+2, "return None") - if query.Ret.IsStruct() { - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return %s(", retType.Type)) - i := 0 - for _, col := range query.Ret.Table.Columns { - if i != 0 { - body.WriteString(", ") - } - if len(col.EmbedFields) != 0 { - var inner []string - body.WriteString(fmt.Sprintf("%s=%s(", col.Name, col.Type.Type)) - for _, embedCol := range col.EmbedFields { - if embedCol.Type.DoOverride() { - inner = append(inner, fmt.Sprintf("%s=%s(row[%s])", embedCol.Name, embedCol.Type.Type, strconv.Itoa(i))) - } else { - inner = append(inner, fmt.Sprintf("%s=row[%s]", embedCol.Name, strconv.Itoa(i))) - } - i++ - } - body.WriteString(strings.Join(inner, ", ") + ")") - } else { - if col.Type.DoOverride() { - body.WriteString(fmt.Sprintf("%s=%s(row[%s])", col.Name, col.Type.Type, strconv.Itoa(i))) - } else { - body.WriteString(fmt.Sprintf("%s=row[%s]", col.Name, strconv.Itoa(i))) - } - i++ - } - } - body.WriteLine(")") - } else { - if query.Ret.Typ.DoOverride() { - body.WriteIndentedLine(indentLevel+1, fmt.Sprintf("return %s(row[0])", query.Ret.Typ.Type)) - } else { - body.WriteIndentedLine(indentLevel+1, "return row[0]") - } - } - } else if query.Cmd == metadata.CmdMany { - body.WriteLine(fmt.Sprintf(") -> QueryResults[%s]:", retType.Type)) - body.WriteQueryFunctionDocstring(indentLevel+1, query, docstringConnType, args, retType) - - decodeHook := "_decode_hook" - if !query.Ret.IsStruct() && !query.Ret.Typ.DoOverride() { - decodeHook = "operator.itemgetter(0)" - } else if !query.Ret.IsStruct() && query.Ret.Typ.DoOverride() { - body.WriteIndentedLine(indentLevel+1, fmt.Sprintf("def _decode_hook(row: %s) -> %s:", Sqlite3Result, retType.Type)) - body.WriteIndentedLine(indentLevel+2, fmt.Sprintf("return %s(row[0])", retType.Type)) - } else { - body.WriteIndentedLine(indentLevel+1, fmt.Sprintf("def _decode_hook(row: %s) -> %s:", Sqlite3Result, retType.Type)) - body.WriteIndentedString(indentLevel+2, fmt.Sprintf("return %s(", retType.Type)) - i := 0 - for _, col := range query.Ret.Table.Columns { - if i != 0 { - body.WriteString(", ") - } - if len(col.EmbedFields) != 0 { - var inner []string - body.WriteString(fmt.Sprintf("%s=%s(", col.Name, col.Type.Type)) - for _, embedCol := range col.EmbedFields { - if embedCol.Type.DoOverride() { - inner = append(inner, fmt.Sprintf("%s=%s(row[%s])", embedCol.Name, embedCol.Type.Type, strconv.Itoa(i))) - } else { - inner = append(inner, fmt.Sprintf("%s=row[%s]", embedCol.Name, strconv.Itoa(i))) - } - i++ - } - body.WriteString(strings.Join(inner, ", ") + ")") - } else { - if col.Type.DoOverride() { - body.WriteString(fmt.Sprintf("%s=%s(row[%s])", col.Name, col.Type.Type, strconv.Itoa(i))) - } else { - body.WriteString(fmt.Sprintf("%s=row[%s]", col.Name, strconv.Itoa(i))) - } - i++ - } - } - body.WriteLine(")") - } - body.WriteIndentedString(indentLevel+1, fmt.Sprintf("return QueryResults[%s](%s, %s, %s", retType.Type, conn, query.ConstantName, decodeHook)) - params := "" - for i, arg := range query.Args { - if !arg.IsEmpty() { - if i == len(query.Args)-1 { - params += fmt.Sprintf(" %s", arg.Name) - } else { - params += fmt.Sprintf(" %s,", arg.Name) - } - } - } - if params != "" { - body.WriteString("," + params) - } - body.WriteLine(")") - } - return nil -} - -func SQLite3AcceptedDriverCMDs() []string { - return []string{ - metadata.CmdExec, - metadata.CmdExecResult, - metadata.CmdExecLastId, - metadata.CmdExecRows, - metadata.CmdOne, - metadata.CmdMany, - } -} - -func sqlite3WriteParams(query *core.Query, body *builders.IndentStringBuilder) { - if len(query.Args) == 0 { - return - } - params := "(" - for i, arg := range query.Args { - if !arg.IsEmpty() { - argName := arg.Name - if arg.Typ.DoOverride() { - argName = fmt.Sprintf("%s(%s)", arg.Typ.DefaultType, argName) - } - if i == len(query.Args)-1 && i != 0 { - params += fmt.Sprintf("%s", argName) - } else { - params += fmt.Sprintf("%s, ", argName) - } - } - } - body.WriteString(", " + params + ")") -} diff --git a/internal/codegen/init.go b/internal/codegen/init.go deleted file mode 100644 index 937106d6..00000000 --- a/internal/codegen/init.go +++ /dev/null @@ -1,16 +0,0 @@ -package codegen - -import ( - "github.com/rayakame/sqlc-gen-better-python/internal/codegen/builders" - "github.com/sqlc-dev/plugin-sdk-go/plugin" -) - -func (dr *Driver) BuildInitFile() *plugin.File { - body := builders.NewIndentStringBuilder(dr.conf.IndentChar, dr.conf.CharsPerIndentLevel) - body.WriteSqlcHeader() - body.WriteInitFileModuleDocstring() - return &plugin.File{ - Name: "__init__.py", - Contents: []byte(body.String()), - } -} diff --git a/internal/codegen/queries.go b/internal/codegen/queries.go deleted file mode 100644 index 6471ce5a..00000000 --- a/internal/codegen/queries.go +++ /dev/null @@ -1,207 +0,0 @@ -package codegen - -import ( - "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/codegen/builders" - "github.com/rayakame/sqlc-gen-better-python/internal/codegen/drivers" - "github.com/rayakame/sqlc-gen-better-python/internal/core" - "github.com/sqlc-dev/plugin-sdk-go/metadata" - "github.com/sqlc-dev/plugin-sdk-go/plugin" - "sort" - "strings" -) - -func (dr *Driver) prepareFunctionHeader(query *core.Query, body *builders.IndentStringBuilder) ([]core.FunctionArg, string, []string) { - pyTableNames := make([]string, 0) - args := make([]core.FunctionArg, 0) - for _, arg := range query.Args { - if !arg.IsEmpty() { - argType := arg.Typ.Type - if arg.EmitStruct() && arg.IsStruct() { - BuildPyTabel(dr.conf.ModelType, arg.Table, body) - body.NNewLine(2) - pyTableNames = append(pyTableNames, arg.Table.Name) - if query.Cmd == metadata.CmdCopyFrom { - argType = fmt.Sprintf("collections.abc.Sequence[%s]", argType) - } - args = append(args, core.FunctionArg{ - Name: arg.Name, - Type: argType, - FunctionFormat: fmt.Sprintf("%s: %s", arg.Name, argType), - }) - } else { - if arg.Typ.IsList { - argType = fmt.Sprintf("collections.abc.Sequence[%s]", argType) - } - if arg.Typ.IsNullable { - argType = fmt.Sprintf("%s | None", argType) - } - args = append(args, core.FunctionArg{ - Name: arg.Name, - Type: argType, - FunctionFormat: fmt.Sprintf("%s: %s", arg.Name, argType), - }) - } - } - } - retType := "None" - if query.Ret.EmitStruct() && query.Ret.IsStruct() { - BuildPyTabel(dr.conf.ModelType, query.Ret.Table, body) - body.NNewLine(2) - retType = query.Ret.Table.Name - pyTableNames = append(pyTableNames, query.Ret.Table.Name) - } else if !query.Ret.IsEmpty() { - if query.Ret.IsStruct() { - retType = fmt.Sprintf("models.%s", query.Ret.Table.Name) - } else { - retType = query.Ret.Typ.Type - } - } - if query.Cmd == metadata.CmdExecLastId { - retType = "int | None" - } - if query.Cmd == metadata.CmdExecRows || query.Cmd == metadata.CmdCopyFrom { - retType = "int" - } - return args, retType, pyTableNames -} - -func (dr *Driver) BuildPyQueriesFiles(imp *core.Importer, queries []core.Query) ([]*plugin.File, error) { - files := make([]*plugin.File, 0) - fileQueries := make(map[string][]core.Query) - for _, query := range queries { - if err := dr.supportedCMD(query.Cmd); err != nil { - return nil, err - } - if val, found := fileQueries[query.SourceName]; found { - fileQueries[query.SourceName] = append(val, query) - } else { - fileQueries[query.SourceName] = []core.Query{query} - } - } - - for sourceName, queries := range fileQueries { - data, err := dr.buildPyQueriesFile(imp, queries, sourceName) - if err != nil { - return nil, err - } - files = append(files, &plugin.File{ - Name: core.SQLToPyFileName(sourceName), - Contents: data, - }) - } - - return files, nil -} - -func (dr *Driver) buildQueryHeader(query *core.Query, body *builders.IndentStringBuilder) { - body.WriteLine(fmt.Sprintf(`%s: typing.Final[str] = """-- name: %s %s`, query.ConstantName, query.MethodName, query.Cmd)) - body.WriteLine(query.SQL) - body.WriteLine(`"""`) -} - -func (dr *Driver) buildClassTemplate(sourceName string, body *builders.IndentStringBuilder) string { - className := core.SnakeToCamel(strings.ReplaceAll(sourceName, ".sql", ""), dr.conf) - body.WriteLine(fmt.Sprintf("class %s:", className)) - body.WriteQueryClassDocstring(sourceName, dr.connType) - body.WriteIndentedLine(1, `__slots__ = ("_conn",)`) - body.NewLine() - body.WriteIndentedLine(1, fmt.Sprintf(`def __init__(self, conn: %s) -> None:`, dr.connType)) - body.WriteQueryClassInitDocstring(2, dr.connType) - body.WriteIndentedLine(2, "self._conn = conn") - body.NewLine() - body.WriteIndentedLine(1, "@property") - body.WriteIndentedLine(1, fmt.Sprintf(`def conn(self) -> %s:`, dr.connType)) - body.WriteQueryClassConnDocstring(dr.connType) - body.WriteIndentedLine(2, `return self._conn`) - body.NewLine() - return className -} - -func (dr *Driver) buildPyQueriesFile(imp *core.Importer, queries []core.Query, sourceName string) ([]byte, error) { - body := builders.NewIndentStringBuilder(imp.C.IndentChar, imp.C.CharsPerIndentLevel) - body.WriteSqlcHeader() - body.WriteQueryFileModuleDocstring(sourceName) - body.WriteImportAnnotations() - - newLines := 2 - if dr.conf.EmitClasses { - newLines = 1 - } - - allNames := make([]string, 0) - funcBody := builders.NewIndentStringBuilder(imp.C.IndentChar, imp.C.CharsPerIndentLevel) - pyTableBody := builders.NewIndentStringBuilder(imp.C.IndentChar, imp.C.CharsPerIndentLevel) - for _, query := range queries { - if !dr.conf.EmitClasses { - allNames = append(allNames, query.FuncName) - } - dr.buildQueryHeader(&query, funcBody) - funcBody.NewLine() - } - if core.IsAnyQueryMany(queries) { - funcBody.NewLine() - allNames = append(allNames, dr.driverBuildQueryResults(funcBody)) - funcBody.NewLine() - } - funcBody.NewLine() - if dr.conf.EmitClasses { - allNames = append(allNames, dr.buildClassTemplate(sourceName, funcBody)) - } - for i, query := range queries { - args, retType, addedPyTableNames := dr.prepareFunctionHeader(&query, pyTableBody) - returnType := core.PyType{ - SqlType: query.Ret.Typ.SqlType, - Type: retType, - } - allNames = append(allNames, addedPyTableNames...) - err := dr.buildPyQueryFunc(&query, funcBody, args, returnType, dr.conf) - if err != nil { - return nil, err - } - if i != len(queries)-1 { - funcBody.NNewLine(newLines) - } - } - body.WriteLine("__all__: collections.abc.Sequence[str] = (") - if len(allNames) > 0 { - sort.Slice(allNames, func(i, j int) bool { return allNames[i] < allNames[j] }) - } - for _, n := range allNames { - body.WriteIndentedLine(1, fmt.Sprintf("\"%s\",", n)) - } - body.WriteLine(")") - body.NewLine() - std, tye, pkg := imp.Imports(sourceName) - tyeHook := dr.driverTypeCheckingHook() - for _, imp := range std { - body.WriteLine(imp) - } - if len(tye) != 0 || len(tyeHook) != 0 { - if len(std) != 0 { - body.NewLine() - } - body.WriteLine("if typing.TYPE_CHECKING:") - for _, imp := range tye { - body.WriteIndentedLine(1, imp) - } - for i, imp := range tyeHook { - if i == 0 && len(tye) != 0 { - body.NewLine() - } - body.WriteIndentedLine(1, imp) - } - } - body.WriteLine("") - for _, imp := range pkg { - body.WriteLine(imp) - } - body.NNewLine(2) - if dr.conf.SqlDriver == core.SQLDriverAioSQLite { - drivers.AioSQLiteBuildTypeConvFunc(queries, body, dr.conf) - } - if dr.conf.SqlDriver == core.SQLDriverSQLite { - drivers.SQLite3BuildTypeConvFunc(queries, body, dr.conf) - } - return []byte(body.String() + pyTableBody.String() + funcBody.String()), nil -} diff --git a/internal/codegen/tables.go b/internal/codegen/tables.go deleted file mode 100644 index 7cd8312c..00000000 --- a/internal/codegen/tables.go +++ /dev/null @@ -1,88 +0,0 @@ -package codegen - -import ( - "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/codegen/builders" - "github.com/rayakame/sqlc-gen-better-python/internal/core" - "github.com/sqlc-dev/plugin-sdk-go/plugin" -) - -func (dr *Driver) BuildPyTablesFile(imp *core.Importer, tables []core.Table) (*plugin.File, error) { - fileName, fileContent, err := dr.buildPyTables(imp, tables) - if err != nil { - return nil, err - } - return &plugin.File{ - Name: core.SQLToPyFileName(fileName), - Contents: fileContent, - }, nil -} - -func BuildPyTabel(modelType string, table *core.Table, body *builders.IndentStringBuilder) { - if modelType == core.ModelTypeDataclass { - body.WriteLine("@dataclasses.dataclass()") - } else if modelType == core.ModelTypeAttrs { - body.WriteLine("@attrs.define()") - } - inheritance := "" - if modelType == core.ModelTypeMsgspec { - inheritance = "(msgspec.Struct)" - } - body.WriteLine(fmt.Sprintf("class %s%s:", table.Name, inheritance)) - body.WriteModelClassDocstring(table) - for _, col := range table.Columns { - type_ := col.Type.Type - if col.Type.IsList { - type_ = "collections.abc.Sequence[" + type_ + "]" - } - if col.Type.IsNullable { - type_ = type_ + " | None" - } - body.WriteIndentedLine(1, col.Name+": "+type_) - } -} - -func (dr *Driver) buildPyTables(imp *core.Importer, tables []core.Table) (string, []byte, error) { - fileName := "models.sql" - body := builders.NewIndentStringBuilder(imp.C.IndentChar, imp.C.CharsPerIndentLevel) - body.WriteSqlcHeader() - body.WriteModelFileModuleDocstring() - body.WriteImportAnnotations() - body.WriteLine("__all__: collections.abc.Sequence[str] = (") - for _, table := range tables { - body.WriteIndentedLine(1, fmt.Sprintf("\"%s\",", table.Name)) - } - body.WriteLine(")") - body.WriteString("\n") - std, tye, pkg := imp.Imports(fileName) - for _, imp := range std { - body.WriteLine(imp) - } - if len(tye) != 0 { - if len(std) != 0 { - body.NewLine() - } - if !dr.conf.OmitTypecheckingBlock { - body.WriteLine("if typing.TYPE_CHECKING:") - for _, imp := range tye { - body.WriteIndentedLine(1, imp) - } - } else { - for _, imp := range tye { - body.WriteLine(imp) - } - } - } - for i, imp := range pkg { - if i == 0 { - body.NewLine() - } - body.WriteLine(imp) - } - for _, table := range tables { - body.WriteString("\n") - body.WriteString("\n") - BuildPyTabel(imp.C.ModelType, &table, body) - } - return fileName, []byte(body.String()), nil -} diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 00000000..d4d4ae66 --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,136 @@ +package config + +import ( + "encoding/json" + "errors" + "fmt" + + "github.com/rayakame/sqlc-gen-better-python/internal/utils" + "github.com/sqlc-dev/plugin-sdk-go/plugin" +) + +type Config struct { + Package string `json:"package" yaml:"package"` + SqlDriver SQLDriver `json:"sql_driver" yaml:"sql_driver"` + ModelType ModelType `json:"model_type" yaml:"model_type"` + Initialisms *[]string `json:"initialisms,omitempty" yaml:"initialisms,omitempty"` + EmitExactTableNames bool `json:"emit_exact_table_names" yaml:"emit_exact_table_names"` + EmitClasses bool `json:"emit_classes" yaml:"emit_classes"` + InflectionExcludeTableNames []string `json:"inflection_exclude_table_names,omitempty" yaml:"inflection_exclude_table_names,omitempty"` + OmitUnusedModels bool `json:"omit_unused_models" yaml:"omit_unused_models"` + OmitTypecheckingBlock bool `json:"omit_typechecking_block" yaml:"omit_typechecking_block"` + QueryParameterLimit *int `json:"query_parameter_limit,omitempty" yaml:"query_parameter_limit"` + OmitKwargsLimit int `json:"omit_kwargs_limit,omitempty" yaml:"omit_kwargs_limit"` + EmitInitFile *bool `json:"emit_init_file" yaml:"emit_init_file"` + EmitDocstrings DocstringConvention `json:"docstrings" yaml:"docstrings"` + EmitDocstringsSQL *bool `json:"docstrings_emit_sql" yaml:"docstrings_emit_sql"` + Speedups bool `json:"speedups" yaml:"speedups"` + Overrides []Override `json:"overrides,omitempty" yaml:"overrides,omitempty"` + + Debug bool `json:"debug" yaml:"debug"` + + IndentChar string `json:"indent_char" yaml:"indent_char"` + CharsPerIndentLevel int `json:"chars_per_indent_level" yaml:"chars_per_indent_level"` + + InitialismsMap map[string]struct{} `json:"-" yaml:"-"` +} + +func NewConfig(req *plugin.GenerateRequest) (*Config, error) { + config, err := parseConfig(req) + if err != nil { + return nil, err + } + err = validateConf(config, req.Settings.Engine) + if err != nil { + return nil, err + } + + return config, nil +} + +// IsOverQueryParameterLimit reports whether a query's parameters should be +// bundled into a Params class. This is opt-in: it only applies when +// query_parameter_limit is explicitly set to a non-negative value and the +// query has more parameters than the limit. +func (config *Config) IsOverQueryParameterLimit(num int) bool { + switch { + case config.QueryParameterLimit == nil: + return false + case *config.QueryParameterLimit < 0: + return false + case *config.QueryParameterLimit >= num: + return false + default: + return true + } +} + +func parseConfig(req *plugin.GenerateRequest) (*Config, error) { + var config Config + if len(req.PluginOptions) == 0 { + return &config, nil + } + if err := json.Unmarshal(req.PluginOptions, &config); err != nil { + return nil, fmt.Errorf("unmarshalling plugin options: %w", err) + } + + for i := range config.Overrides { + if err := config.Overrides[i].parse(req); err != nil { + return nil, err + } + } + + if config.ModelType == "" { + config.ModelType = ModelTypeDataclass + } + if config.Initialisms == nil { + config.Initialisms = utils.ToPtr([]string{"id"}) + } + if config.IndentChar == "" { + config.IndentChar = " " + } + if config.CharsPerIndentLevel <= 0 { + config.CharsPerIndentLevel = 4 + } + if config.EmitDocstrings == "" { + config.EmitDocstrings = DocstringConventionNone + } + if config.EmitDocstringsSQL == nil { + config.EmitDocstringsSQL = utils.ToPtr(true) + } + + config.InitialismsMap = map[string]struct{}{} + for _, initial := range *config.Initialisms { + config.InitialismsMap[initial] = struct{}{} + } + + return &config, nil +} + +func validateConf(conf *Config, engine string) error { + if conf.OmitKwargsLimit < 0 { + return errors.New("invalid options: omit kwarg limit must not be negative") + } + + if conf.EmitInitFile == nil { + return errors.New("invalid options: you need to specify emit_init_file") + } + + if conf.Package == "" { + return errors.New("invalid options: package must not be empty") + } + + if err := conf.SqlDriver.Validate(engine); err != nil { + return fmt.Errorf("invalid options: invalid sql driver: %w", err) + } + + if !conf.ModelType.Valid() { + return fmt.Errorf("invalid options: unknown model type: %s", conf.ModelType) + } + + if !conf.EmitDocstrings.Valid() { + return fmt.Errorf("invalid options: unknown docstring convention: %s", conf.EmitDocstrings) + } + + return nil +} diff --git a/internal/config/constants.go b/internal/config/constants.go new file mode 100644 index 00000000..b3b8ef11 --- /dev/null +++ b/internal/config/constants.go @@ -0,0 +1,71 @@ +package config + +import "fmt" + +const PluginVersion = "v0.4.6" + +type ( + SQLDriver string + DocstringConvention string + ModelType string +) + +func (dr SQLDriver) String() string { + return string(dr) +} + +const ( + SQLDriverSQLite SQLDriver = "sqlite3" + SQLDriverAioSQLite SQLDriver = "aiosqlite" + SQLDriverAsyncpg SQLDriver = "asyncpg" +) + +const ( + ModelTypeDataclass ModelType = "dataclass" + ModelTypeAttrs ModelType = "attrs" + ModelTypeMsgspec ModelType = "msgspec" + ModelTypePydantic ModelType = "pydantic" +) + +var driversEngine = map[SQLDriver]string{ + SQLDriverSQLite: "sqlite", + SQLDriverAioSQLite: "sqlite", + SQLDriverAsyncpg: "postgresql", +} + +const ( + DocstringConventionNone DocstringConvention = "none" + DocstringConventionGoogle DocstringConvention = "google" + DocstringConventionNumpy DocstringConvention = "numpy" + DocstringConventionPEP257 DocstringConvention = "pep257" +) + +func (dr SQLDriver) Validate(engine string) error { + val, found := driversEngine[dr] + if !found { + return fmt.Errorf("unknown SQL driver: %s", dr) + } + if val != engine { + return fmt.Errorf("SQL driver %s does not support %s", dr, engine) + } + + return nil +} + +func (modelType ModelType) Valid() bool { + switch modelType { + case ModelTypeDataclass, ModelTypeMsgspec, ModelTypeAttrs, ModelTypePydantic: + return true + default: + return false + } +} + +func (ds DocstringConvention) Valid() bool { + switch ds { + case DocstringConventionNone, DocstringConventionNumpy, DocstringConventionGoogle, DocstringConventionPEP257: + return true + default: + return false + } +} diff --git a/internal/config/overrides.go b/internal/config/overrides.go new file mode 100644 index 00000000..fe43c98f --- /dev/null +++ b/internal/config/overrides.go @@ -0,0 +1,137 @@ +package config + +import ( + "errors" + "fmt" + "strings" + + "github.com/sqlc-dev/plugin-sdk-go/pattern" + "github.com/sqlc-dev/plugin-sdk-go/plugin" +) + +// OverridePyType describes the Python type that replaces the default mapping. +// Import is the module to import (e.g. "collections"); Type is the type +// expression used in annotations (e.g. "UserString" or "collections.UserString"); +// Package is the name imported from Import ("from import ") - +// if empty, Import is imported as a plain module ("import "). +type OverridePyType struct { + Import string `json:"import" yaml:"import"` + Type string `json:"type" yaml:"type"` + Package string `json:"package" yaml:"package"` +} + +// Override replaces the default Python type of columns matched either by +// SQL type (DBType) or by a column pattern ("[catalog.][schema.]table.column", +// wildcards supported). +type Override struct { + PyType OverridePyType `json:"py_type" yaml:"py_type"` + + // DBType matches the SQL data type exactly, e.g. "text" or "pg_catalog.int4". + DBType string `json:"db_type" yaml:"db_type"` + + // Column matches a fully qualified column name, e.g. "authors.name". + Column string `json:"column" yaml:"column"` + + ColumnName *pattern.Match `json:"-" yaml:"-"` + TableCatalog *pattern.Match `json:"-" yaml:"-"` + TableSchema *pattern.Match `json:"-" yaml:"-"` + TableRel *pattern.Match `json:"-" yaml:"-"` +} + +// Matches reports whether the override's table pattern matches the identifier. +func (o *Override) Matches(n *plugin.Identifier, defaultSchema string) bool { + if n == nil { + return false + } + schema := n.Schema + if n.Schema == "" { + schema = defaultSchema + } + if o.TableCatalog != nil && !o.TableCatalog.MatchString(n.Catalog) { + return false + } + if o.TableSchema == nil && schema != "" { + return false + } + if o.TableSchema != nil && !o.TableSchema.MatchString(schema) { + return false + } + if o.TableRel == nil && n.Name != "" { + return false + } + if o.TableRel != nil && !o.TableRel.MatchString(n.Name) { + return false + } + + return true +} + +const ( + overrideColumnPartsTable = 2 + overrideColumnPartsSchemaTable = 3 + overrideColumnPartsCatalogSchema = 4 +) + +func (o *Override) parse(req *plugin.GenerateRequest) error { + schema := "public" + if req != nil && req.Catalog != nil { + schema = req.Catalog.DefaultSchema + } + + switch { + case o.Column != "" && o.DBType != "": + return fmt.Errorf("override specifying both `column` (%q) and `db_type` (%q) is not valid", o.Column, o.DBType) + case o.Column == "" && o.DBType == "": + return errors.New("override must specify one of either `column` or `db_type`") + } + + if o.PyType.Type == "" { + return errors.New("override must specify a `py_type` with a non-empty `type`") + } + + if o.Column != "" { + return o.parseColumnPattern(schema) + } + + return nil +} + +// parseColumnPattern compiles the "[catalog.][schema.]tablename.colname" parts +// of the Column specifier into match patterns. +func (o *Override) parseColumnPattern(defaultSchema string) error { + type target struct { + dst **pattern.Match + expr string + } + + colParts := strings.Split(o.Column, ".") + var targets []target + switch len(colParts) { + case overrideColumnPartsTable: + targets = []target{{&o.ColumnName, colParts[1]}, {&o.TableRel, colParts[0]}, {&o.TableSchema, defaultSchema}} + case overrideColumnPartsSchemaTable: + targets = []target{{&o.ColumnName, colParts[2]}, {&o.TableRel, colParts[1]}, {&o.TableSchema, colParts[0]}} + case overrideColumnPartsCatalogSchema: + targets = []target{ + {&o.ColumnName, colParts[3]}, + {&o.TableRel, colParts[2]}, + {&o.TableSchema, colParts[1]}, + {&o.TableCatalog, colParts[0]}, + } + default: + return fmt.Errorf( + "override `column` specifier %q is not the proper format, expected '[catalog.][schema.]tablename.colname'", + o.Column, + ) + } + + for _, tgt := range targets { + compiled, err := pattern.MatchCompile(tgt.expr) + if err != nil { + return err + } + *tgt.dst = compiled + } + + return nil +} diff --git a/internal/core/Column.go b/internal/core/Column.go deleted file mode 100644 index bda3f795..00000000 --- a/internal/core/Column.go +++ /dev/null @@ -1,13 +0,0 @@ -package core - -import "github.com/sqlc-dev/plugin-sdk-go/plugin" - -type Column struct { - Name string // CamelCased name for Go - DBName string // Name as used in the DB - Type PyType - Comment string - Column *plugin.Column - // EmbedFields contains the embedded fields that require scanning. - EmbedFields []Column -} diff --git a/internal/core/config.go b/internal/core/config.go deleted file mode 100644 index 34818887..00000000 --- a/internal/core/config.go +++ /dev/null @@ -1,126 +0,0 @@ -package core - -import ( - "encoding/json" - "fmt" - "github.com/sqlc-dev/plugin-sdk-go/plugin" -) - -const PluginVersion = "v0.4.5" - -type Config struct { - Package string `json:"package" yaml:"package"` - SqlDriver SQLDriverType `json:"sql_driver" yaml:"sql_driver"` - ModelType string `json:"model_type" yaml:"model_type"` - Initialisms *[]string `json:"initialisms,omitempty" yaml:"initialisms,omitempty"` - EmitExactTableNames bool `json:"emit_exact_table_names" yaml:"emit_exact_table_names"` - EmitClasses bool `json:"emit_classes" yaml:"emit_classes"` - InflectionExcludeTableNames []string `json:"inflection_exclude_table_names,omitempty" yaml:"inflection_exclude_table_names,omitempty"` - OmitUnusedModels bool `json:"omit_unused_models" yaml:"omit_unused_models"` - OmitTypecheckingBlock bool `json:"omit_typechecking_block" yaml:"omit_typechecking_block"` - QueryParameterLimit *int32 `json:"query_parameter_limit,omitempty" yaml:"query_parameter_limit"` - OmitKwargsLimit *int32 `json:"omit_kwargs_limit,omitempty" yaml:"omit_kwargs_limit"` - EmitInitFile *bool `json:"emit_init_file" yaml:"emit_init_file"` - EmitDocstrings *string `json:"docstrings" yaml:"docstrings"` - EmitDocstringsSQL *bool `json:"docstrings_emit_sql" yaml:"docstrings_emit_sql"` - Speedups bool `json:"speedups" yaml:"speedups"` - Overrides []Override `json:"overrides,omitempty" yaml:"overrides"` - - Debug bool `json:"debug" yaml:"debug"` - - IndentChar string `json:"indent_char" yaml:"indent_char"` - CharsPerIndentLevel int `json:"chars_per_indent_level" yaml:"chars_per_indent_level"` - - InitialismsMap map[string]struct{} `json:"-" yaml:"-"` - Async bool -} - -func ParseConfig(req *plugin.GenerateRequest) (*Config, error) { - var config Config - if len(req.PluginOptions) == 0 { - return &config, nil - } - if err := json.Unmarshal(req.PluginOptions, &config); err != nil { - return nil, fmt.Errorf("unmarshalling plugin options: %w", err) - } - if config.SqlDriver == "" { - return nil, fmt.Errorf("invalid options: driver must not be empty") - } - val, err := isDriverAsync(config.SqlDriver) - if err != nil { - return nil, fmt.Errorf("invalid options: %s", err) - } - config.Async = val - - for i := range config.Overrides { - if err := config.Overrides[i].parse(req); err != nil { - return nil, err - } - } - - if config.ModelType == "" { - config.ModelType = ModelTypeDataclass - } - if config.QueryParameterLimit == nil { - config.QueryParameterLimit = new(int32) - *config.QueryParameterLimit = 1 - } - if config.OmitKwargsLimit == nil { - config.OmitKwargsLimit = new(int32) - *config.OmitKwargsLimit = 0 - } - if config.Initialisms == nil { - config.Initialisms = new([]string) - *config.Initialisms = []string{"id"} - } - if config.IndentChar == "" { - config.IndentChar = " " - } - if config.CharsPerIndentLevel == 0 { - config.CharsPerIndentLevel = 4 - } - if config.EmitDocstrings == nil { - config.EmitDocstrings = new(string) - *config.EmitDocstrings = DocstringConventionNone - } - if config.EmitDocstringsSQL == nil { - config.EmitDocstringsSQL = new(bool) - *config.EmitDocstringsSQL = true - } - - config.InitialismsMap = map[string]struct{}{} - for _, initial := range *config.Initialisms { - config.InitialismsMap[initial] = struct{}{} - } - return &config, nil -} -func ValidateConf(conf *Config, engine string) error { - if *conf.QueryParameterLimit < 0 { - return fmt.Errorf("invalid options: query parameter limit must not be negative") - } - if *conf.OmitKwargsLimit < 0 { - return fmt.Errorf("invalid options: omit kwarg limit must not be negative") - } - - if conf.EmitInitFile == nil { - return fmt.Errorf("invalid options: you need to specify emit_init_file") - } - - if conf.Package == "" { - return fmt.Errorf("invalid options: package must not be empty") - } - - if err := isDriverValid(conf.SqlDriver, engine); err != nil { - return err - } - - if err := isModelTypeValid(conf.ModelType); err != nil { - return fmt.Errorf("invalid options: %s", err) - } - - if err := isDocstringValid(conf.EmitDocstrings); err != nil { - return fmt.Errorf("invalid options: %s", err) - } - - return nil -} diff --git a/internal/core/enums.go b/internal/core/enums.go deleted file mode 100644 index caf2bf87..00000000 --- a/internal/core/enums.go +++ /dev/null @@ -1,89 +0,0 @@ -package core - -import "fmt" - -type SQLDriverType string - -func (dr *SQLDriverType) String() string { - return string(*dr) -} - -const ( - SQLDriverSQLite SQLDriverType = "sqlite3" - SQLDriverAioSQLite SQLDriverType = "aiosqlite" - SQLDriverAsyncpg SQLDriverType = "asyncpg" -) - -const ( - ModelTypeDataclass = "dataclass" - ModelTypeAttrs = "attrs" - ModelTypeMsgspec = "msgspec" -) - -var asyncDrivers = map[SQLDriverType]bool{ - SQLDriverSQLite: false, - SQLDriverAioSQLite: true, - SQLDriverAsyncpg: true, -} - -var driversEngine = map[SQLDriverType]string{ - SQLDriverSQLite: "sqlite", - SQLDriverAioSQLite: "sqlite", - SQLDriverAsyncpg: "postgresql", -} - -var validModelTypes = map[string]struct{}{ - string(ModelTypeDataclass): {}, - string(ModelTypeAttrs): {}, - string(ModelTypeMsgspec): {}, -} - -const ( - DocstringConventionNone = "none" - DocstringConventionGoogle = "google" - DocstringConventionNumpy = "numpy" - DocstringConventionPEP257 = "pep257" -) - -var validDocstringConventions = map[string]struct{}{ - DocstringConventionNone: {}, - DocstringConventionGoogle: {}, - DocstringConventionNumpy: {}, - DocstringConventionPEP257: {}, -} - -func isDriverAsync(sqlDriver SQLDriverType) (bool, error) { - val, found := asyncDrivers[sqlDriver] - if !found { - return false, fmt.Errorf("unknown SQL driver: %s", sqlDriver) - } - return val, nil -} - -func isDriverValid(sqlDriver SQLDriverType, engine string) error { - val, found := driversEngine[sqlDriver] - if !found { - return fmt.Errorf("unknown SQL driver: %s", sqlDriver) - } - if val != engine { - return fmt.Errorf("SQL driver %s does not support %s", sqlDriver, engine) - } - return nil -} - -func isModelTypeValid(modelType string) error { - if _, found := validModelTypes[modelType]; !found { - return fmt.Errorf("unknown model type: %s", modelType) - } - return nil -} - -func isDocstringValid(ds *string) error { - if ds == nil { - return nil - } - if _, found := validDocstringConventions[*ds]; !found { - return fmt.Errorf("unknown docstring convention: %s", ds) - } - return nil -} diff --git a/internal/core/function.go b/internal/core/function.go deleted file mode 100644 index 691745e0..00000000 --- a/internal/core/function.go +++ /dev/null @@ -1,7 +0,0 @@ -package core - -type FunctionArg struct { - Name string - Type string - FunctionFormat string -} diff --git a/internal/core/importer.go b/internal/core/importer.go deleted file mode 100644 index 3e2ec677..00000000 --- a/internal/core/importer.go +++ /dev/null @@ -1,422 +0,0 @@ -package core - -import ( - "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/typeConversion" - "github.com/sqlc-dev/plugin-sdk-go/metadata" - "sort" - "strings" -) - -type importSpec struct { - Module string - Name string - Alias string - TypeChecking bool -} - -func (i importSpec) String() string { - if i.Alias != "" { - if i.Name == "" { - return fmt.Sprintf("import %s as %s", i.Module, i.Alias) - } - return fmt.Sprintf("from %s import %s as %s", i.Module, i.Name, i.Alias) - } - if i.Name == "" { - return "import " + i.Module - } - return fmt.Sprintf("from %s import %s", i.Module, i.Name) -} - -type Importer struct { - Tables []Table - Queries []Query - Enums []Enum - C *Config -} - -func (i *Importer) Imports(fileName string) ([]string, []string, []string) { - if fileName == "models.sql" { - return i.modelImports() - } - return i.queryImports(fileName) -} - -func TableUses(name string, s Table) (bool, PyType) { - for _, col := range s.Columns { - if col.Type.Type == name { - return true, col.Type - } - } - return false, PyType{} - -} - -func (i *Importer) getModelImportSpec() (string, importSpec, error) { - switch i.C.ModelType { - case ModelTypeAttrs: - return "attrs", importSpec{Module: "attrs"}, nil - case ModelTypeDataclass: - return "dataclasses", importSpec{Module: "dataclasses"}, nil - case ModelTypeMsgspec: - return "msgspec", importSpec{Module: "msgspec"}, nil - default: - return "", importSpec{}, fmt.Errorf("unknown model type: %s", i.C.ModelType) - } -} - -func (i *Importer) splitTypeChecking(pks map[string]importSpec) (map[string]importSpec, map[string]importSpec) { - normalImports := make(map[string]importSpec) - typeChecking := make(map[string]importSpec) - for name, val := range pks { - if val.TypeChecking { - typeChecking[name] = val - } else { - normalImports[name] = val - } - } - return normalImports, typeChecking -} - -func (i *Importer) modelImportSpecs() (map[string]importSpec, map[string]importSpec, map[string]importSpec) { - modelUses := func(name string) (bool, bool) { - for _, table := range i.Tables { - if val, _ := TableUses(name, table); val { - return true, true - } - } - return false, false - } - - std := stdImports(modelUses) - for _, override := range i.C.Overrides { - if val1, val2 := modelUses(override.PyTypeName); val1 { - std[override.PyTypeName] = importSpec{Module: override.PyImportPath, Name: override.PyPackageName, TypeChecking: val2} - } - } - std, typeChecking := i.splitTypeChecking(std) - if len(typeChecking) != 0 { - std["typing"] = importSpec{Module: "typing"} - } - modelName, modelImport, err := i.getModelImportSpec() - if err == nil { - std[modelName] = modelImport - } - if len(i.Enums) > 0 { - std["enum"] = importSpec{Module: fmt.Sprintf("from %s import enums", i.C.Package)} - } - - pkg := make(map[string]importSpec) - - return std, typeChecking, pkg -} - -func (i *Importer) queryValueUses(name string, qv QueryValue) (bool, bool) { - if !qv.IsEmpty() { - if qv.IsStruct() && qv.EmitStruct() { - if val, pyType := TableUses(name, *qv.Table); val { - if i.C.SqlDriver == SQLDriverAsyncpg { - if pyType.DoConversion(typeConversion.AsyncpgDoTypeConversion) { - return true, false - } else { - return true, true - } - } else if i.C.SqlDriver == SQLDriverAioSQLite || i.C.SqlDriver == SQLDriverSQLite { - if pyType.DoConversion(typeConversion.SqliteDoTypeConversion) { - return true, false - } else { - return true, true - } - } - return true, false - } - } else if qv.IsStruct() && (i.C.SqlDriver == SQLDriverAioSQLite || i.C.SqlDriver == SQLDriverSQLite) { - if val, pyType := TableUses(name, *qv.Table); val { - if pyType.DoConversion(typeConversion.SqliteDoTypeConversion) { - return true, false - } - } - } else { - if qv.Typ.Type == name { - if i.C.SqlDriver == SQLDriverAsyncpg { - if qv.Typ.DoConversion(typeConversion.AsyncpgDoTypeConversion) { - return true, false - } else { - return true, true - } - } else if i.C.SqlDriver == SQLDriverAioSQLite || i.C.SqlDriver == SQLDriverSQLite { - if qv.Typ.DoConversion(typeConversion.SqliteDoTypeConversion) { - return true, false - } else { - return true, true - } - } - return true, false - } - } - } - return false, false -} - -func (i *Importer) queryImportSpecs(_ string) (map[string]importSpec, map[string]importSpec, map[string]importSpec, map[string]importSpec) { - addCiso := false - queryUses := func(name string) (bool, bool) { - var uses *bool = nil - var typeChecking *bool = nil - - helper := func(val1, val2 bool) { - if uses == nil || typeChecking == nil { - uses = new(bool) - typeChecking = new(bool) - *uses = val1 - *typeChecking = val2 - } else if *typeChecking == true { - *uses = val1 - *typeChecking = val2 - } - } - for _, q := range i.Queries { - //if q.SourceName != fileName { TODO q.SourceName is the name of the sql file - // continue - //} - if val1, val2 := i.queryValueUses(name, q.Ret); val1 { - if q.Cmd == metadata.CmdMany { - helper(val1, false) - } - // if we have speedups enabled then we don't need datetime in the std imports - // we use ciso8601 for the converting and need datetime only in typechecking - if val2 == false && (i.C.SqlDriver == SQLDriverAioSQLite || i.C.SqlDriver == SQLDriverSQLite) && i.C.Speedups && (name == "datetime.datetime" || name == "datetime.date") { - helper(val1, true) - addCiso = true - } else { - helper(val1, val2) - } - } - for _, arg := range q.Args { - if val1, val2 := i.queryValueUses(name, arg); val1 { - // if we have speedups enabled then we don't need datetime in the std imports - // we use ciso8601 for the converting and need datetime only in typechecking - if val2 == false && (i.C.SqlDriver == SQLDriverAioSQLite || i.C.SqlDriver == SQLDriverSQLite) && i.C.Speedups && (name == "datetime.datetime" || name == "datetime.date") { - helper(val1, true) - addCiso = true - } else { - helper(val1, val2) - } - } - } - } - if uses == nil || typeChecking == nil { - return false, false - } - return *uses, *typeChecking - } - querySimpleReturn := func(conv typeConversion.TypeDoTypeConversion) bool { - for _, q := range i.Queries { - if !q.Ret.IsStruct() && !conv(q.Ret.Typ.SqlType) { - return true - } - } - return false - } - - std := stdImports(queryUses) - for _, override := range i.C.Overrides { - if val1, val2 := queryUses(override.PyTypeName); val1 { - std[override.PyTypeName] = importSpec{Module: override.PyImportPath, Name: override.PyPackageName, TypeChecking: val2} - } - } - std, typeChecking := i.splitTypeChecking(std) - if i.C.SqlDriver == SQLDriverAsyncpg { - typeChecking[string(SQLDriverAsyncpg)] = importSpec{Module: string(SQLDriverAsyncpg)} - - if IsAnyQueryMany(i.Queries) { - typeChecking[string(SQLDriverAsyncpg)+".cursor"] = importSpec{Module: string(SQLDriverAsyncpg) + ".cursor"} - if querySimpleReturn(typeConversion.AsyncpgDoTypeConversion) { - std["operator"] = importSpec{Module: "operator"} - } - } - } else if i.C.SqlDriver == SQLDriverAioSQLite { - // if the std mapping has exactly 2 members, these two are collections and typing, - // but if they are more than 2, we need to add type conversion and for that we - // need the aiosqlite in the normal import block, not in the type checking block - if len(std) > 2 { - std[string(SQLDriverAioSQLite)] = importSpec{Module: string(SQLDriverAioSQLite)} - } else { - typeChecking[string(SQLDriverAioSQLite)] = importSpec{Module: string(SQLDriverAioSQLite)} - } - if IsAnyQueryMany(i.Queries) { - typeChecking[string(SQLDriverSQLite)] = importSpec{Module: string(SQLDriverSQLite)} - if querySimpleReturn(typeConversion.SqliteDoTypeConversion) { - std["operator"] = importSpec{Module: "operator"} - } - } - } else if i.C.SqlDriver == SQLDriverSQLite { - // if the std mapping has exactly 2 members, these two are collections and typing, - // but if they are more than 2, we need to add type conversion and for that we - // need the aiosqlite in the normal import block, not in the type checking block - if len(std) > 2 { - std[string(SQLDriverSQLite)] = importSpec{Module: string(SQLDriverSQLite)} - } else { - typeChecking[string(SQLDriverSQLite)] = importSpec{Module: string(SQLDriverSQLite)} - } - if IsAnyQueryMany(i.Queries) { - if querySimpleReturn(typeConversion.SqliteDoTypeConversion) { - std["operator"] = importSpec{Module: "operator"} - } - } - } - if addCiso { - std["ciso8601"] = importSpec{Module: "ciso8601"} - } - - pkg := make(map[string]importSpec) - loc := make(map[string]importSpec) - - queryValueModelImports := func(qv QueryValue) { - if qv.IsStruct() && qv.EmitStruct() { - modelName, modelImport, err := i.getModelImportSpec() - if err == nil { - std[modelName] = modelImport - } - } - } - - for _, q := range i.Queries { - //if q.SourceName != fileName { TODO - // continue - //} - queryValueModelImports(q.Ret) - if q.Cmd == metadata.CmdCopyFrom { - modelName, modelImport, err := i.getModelImportSpec() - if err == nil { - std[modelName] = modelImport - } - } - } - - loc["models"] = importSpec{Module: i.C.Package, Name: "models"} - - return std, typeChecking, pkg, loc -} - -func (i *Importer) queryImports(fileName string) ([]string, []string, []string) { - std, typeCheck, pkg, loc := i.queryImportSpecs(fileName) - - importLines := make([]string, 0) - typeLines := make([]string, 0) - packageLines := make([]string, 0) - if len(std) != 0 { - importLines = append(importLines, buildImportBlock(std)...) - } - if len(typeCheck) != 0 { - typeLines = append(typeLines, buildImportBlock(typeCheck)...) - } - if IsAnyQueryMany(i.Queries) { - if len(typeCheck) != 0 { - typeLines[len(typeLines)-1] = typeLines[len(typeLines)-1] + "\n" - } - queryResultsArgsType := "QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview" - if IsInMultipleMaps("decimal", std, typeCheck) { - queryResultsArgsType += " | decimal.Decimal" - } - if IsInMultipleMaps("uuid", std, typeCheck) { - queryResultsArgsType += " | uuid.UUID" - } - if IsInMultipleMaps("datetime", std, typeCheck) { - queryResultsArgsType += " | datetime.date | datetime.time | datetime.datetime | datetime.timedelta" - } - queryResultsArgsType += " | None" - typeLines = append(typeLines, queryResultsArgsType) - } - - if len(pkg) != 0 { - packageLines = append(packageLines, buildImportBlock(pkg)...) - } - if len(loc) != 0 { - if len(packageLines) != 0 { - packageLines = append(packageLines, "") - } - packageLines = append(packageLines, buildImportBlock(loc)...) - } - return importLines, typeLines, packageLines -} - -func (i *Importer) modelImports() ([]string, []string, []string) { - std, typeCheck, pkg := i.modelImportSpecs() - importLines := make([]string, 0) - typeLines := make([]string, 0) - packageLines := make([]string, 0) - if len(std) != 0 { - importLines = append(importLines, buildImportBlock(std)...) - } - if len(typeCheck) != 0 { - typeLines = append(typeLines, buildImportBlock(typeCheck)...) - } - if len(pkg) != 0 { - packageLines = append(packageLines, buildImportBlock(pkg)...) - } - return importLines, typeLines, packageLines -} - -func buildImportBlock(pkgs map[string]importSpec) []string { - pkgImports := make([]importSpec, 0) - fromImports := make(map[string][]string) - for _, is := range pkgs { - if is.Name == "" || is.Alias != "" { - pkgImports = append(pkgImports, is) - } else { - names, ok := fromImports[is.Module] - if !ok { - names = make([]string, 0, 1) - } - names = append(names, is.Name) - fromImports[is.Module] = names - } - } - - importStrings := make([]string, 0, len(pkgImports)+len(fromImports)) - for _, is := range pkgImports { - importStrings = append(importStrings, is.String()) - } - for modName, names := range fromImports { - sort.Strings(names) - nameString := strings.Join(names, ", ") - importStrings = append(importStrings, fmt.Sprintf("from %s import %s", modName, nameString)) - } - sort.Strings(importStrings) - return importStrings -} - -// typeCheckingOverwriteProtection function that takes in importSpec map and adds/replaced imports. -// Important here is that importSpec's with TypeChecking set to false have higher priority then -// type checking imports. -func typeCheckingOverwriteProtection(std map[string]importSpec, name string, newImport importSpec) { - if val, found := std[name]; found { - if val.TypeChecking == true { - std[name] = newImport - } - } else { - std[name] = newImport - } -} - -func stdImports(uses func(name string) (bool, bool)) map[string]importSpec { - std := make(map[string]importSpec) - std["collections"] = importSpec{Module: "collections.abc", TypeChecking: true} - std["typing"] = importSpec{Module: "typing", TypeChecking: false} - add := func(name, module string) { - if use, typeChecking := uses(name); use { - typeCheckingOverwriteProtection(std, module, importSpec{Module: module, TypeChecking: typeChecking}) - } - } - - add("decimal.Decimal", "decimal") - - add("datetime.date", "datetime") - add("datetime.time", "datetime") - add("datetime.datetime", "datetime") - add("datetime.timedelta", "datetime") - - add("uuid.UUID", "uuid") - return std -} diff --git a/internal/core/models.go b/internal/core/models.go deleted file mode 100644 index 22bbbcf3..00000000 --- a/internal/core/models.go +++ /dev/null @@ -1,131 +0,0 @@ -package core - -import ( - "github.com/rayakame/sqlc-gen-better-python/internal/typeConversion" - "github.com/sqlc-dev/plugin-sdk-go/metadata" - "github.com/sqlc-dev/plugin-sdk-go/plugin" - "strings" -) - -type Table struct { - Table *plugin.Identifier - Name string - Columns []Column - Comment string -} - -type PyType struct { - SqlType string - Type string - DefaultType string - IsList bool - IsNullable bool - IsEnum bool - IsOverride bool - Override *Override -} - -func (p *PyType) DoConversion(conversion typeConversion.TypeDoTypeConversion) bool { - if p.DoOverride() { - return true - } - return conversion(p.SqlType) -} -func (p *PyType) DoOverride() bool { - return p.IsOverride && p.Override != nil -} - -type Constant struct { - Name string - Type string - Value string -} - -type Enum struct { - Name string - Comment string - Constants []Constant -} - -func enumReplacer(r rune) rune { - if strings.ContainsRune("-/:_", r) { - return '_' - } else if (r >= 'a' && r <= 'z') || - (r >= 'A' && r <= 'Z') || - (r >= '0' && r <= '9') { - return r - } else { - return -1 - } -} - -// EnumReplace removes all non ident symbols (all but letters, numbers and -// underscore) and returns valid ident name for provided name. -func EnumReplace(value string) string { - return strings.Map(enumReplacer, value) -} - -type QueryValue struct { - Emit bool - Name string - DBName string // The name of the field in the database. Only set if Struct==nil. - Table *Table - Typ PyType - - // Column is kept so late in the generation process around to differentiate - // between mysql slices and pg arrays - Column *plugin.Column -} - -func (v QueryValue) EmitStruct() bool { - return v.Emit -} - -func (v QueryValue) IsStruct() bool { - return v.Table != nil -} - -func (v QueryValue) IsEmpty() bool { - return v.Typ.Type == "" && v.Name == "" && v.Table == nil -} - -func (v QueryValue) Type() string { - if v.Typ.Type != "" { - return v.Typ.Type - } - if v.Table != nil { - return v.Table.Name - } - panic("no type for QueryValue: " + v.Name) -} - -type Query struct { - Cmd string - Comments []string - MethodName string - FuncName string - FieldName string - ConstantName string - SQL string - SourceName string - Ret QueryValue - Args []QueryValue - - // Used for :copyfrom - Table *plugin.Identifier -} - -func (q Query) HasRetType() bool { - scanned := q.Cmd == metadata.CmdOne || q.Cmd == metadata.CmdMany || - q.Cmd == metadata.CmdBatchMany || q.Cmd == metadata.CmdBatchOne - return scanned && !q.Ret.IsEmpty() -} - -func IsAnyQueryMany(queries []Query) bool { - for _, query := range queries { - if query.Cmd == metadata.CmdMany { - return true - } - } - return false -} diff --git a/internal/core/overrides.go b/internal/core/overrides.go deleted file mode 100644 index a5cfb5f7..00000000 --- a/internal/core/overrides.go +++ /dev/null @@ -1,196 +0,0 @@ -package core - -import ( - "fmt" - "github.com/sqlc-dev/plugin-sdk-go/pattern" - "github.com/sqlc-dev/plugin-sdk-go/plugin" - "go/types" - "strings" -) - -type OverridePyType struct { - Import string `json:"import" yaml:"import"` - Name string `json:"type" yaml:"type"` - Package string `json:"package" yaml:"package"` - Spec string `json:"-"` - BuiltIn bool `json:"-"` -} - -type ParsedOverridePyType struct { - ImportPath string - TypeName string - PackageName string - BasicType bool -} - -func (gt OverridePyType) parse() (*ParsedOverridePyType, error) { - var o ParsedOverridePyType - - if gt.Spec == "" { - o.ImportPath = gt.Import - o.TypeName = gt.Name - o.PackageName = gt.Package - o.BasicType = gt.Import == "" - return &o, nil - } - - input := gt.Spec - lastDot := strings.LastIndex(input, ".") - lastSlash := strings.LastIndex(input, "/") - typename := input - if lastDot == -1 && lastSlash == -1 { - // if the type name has no slash and no dot, validate that the type is a basic Go type - var found bool - for _, typ := range types.Typ { - info := typ.Info() - if info == 0 { - continue - } - if info&types.IsUntyped != 0 { - continue - } - if typename == typ.Name() { - found = true - } - } - if !found { - return nil, fmt.Errorf("Package override `go_type` specifier %q is not a Go basic type e.g. 'string'", input) - } - o.BasicType = true - } else { - // assume the type lives in a Go package - if lastDot == -1 { - return nil, fmt.Errorf("Package override `go_type` specifier %q is not the proper format, expected 'package.type', e.g. 'github.com/segmentio/ksuid.KSUID'", input) - } - typename = input[lastSlash+1:] - // a package name beginning with "go-" will give syntax errors in - // generated code. We should do the right thing and get the actual - // import name, but in lieu of that, stripping the leading "go-" may get - // us what we want. - typename = strings.TrimPrefix(typename, "go-") - typename = strings.TrimSuffix(typename, "-go") - o.ImportPath = input[:lastDot] - } - o.TypeName = typename - isPointer := input[0] == '*' - if isPointer { - o.ImportPath = o.ImportPath[1:] - o.TypeName = "*" + o.TypeName - } - return &o, nil -} - -type Override struct { - // name of the golang type to use, e.g. `github.com/segmentio/ksuid.KSUID` - PyType OverridePyType `json:"py_type" yaml:"py_type"` - - // fully qualified name of the Go type, e.g. `github.com/segmentio/ksuid.KSUID` - DBType string `json:"db_type" yaml:"db_type"` - - // fully qualified name of the column, e.g. `accounts.id` - Column string `json:"column" yaml:"column"` - - ColumnName *pattern.Match `json:"-"` - TableCatalog *pattern.Match `json:"-"` - TableSchema *pattern.Match `json:"-"` - TableRel *pattern.Match `json:"-"` - PyImportPath string `json:"-"` - PyPackageName string `json:"-"` - PyTypeName string `json:"-"` - PyBasicType bool `json:"-"` -} - -func (o *Override) Matches(n *plugin.Identifier, defaultSchema string) bool { - if n == nil { - return false - } - schema := n.Schema - if n.Schema == "" { - schema = defaultSchema - } - if o.TableCatalog != nil && !o.TableCatalog.MatchString(n.Catalog) { - return false - } - if o.TableSchema == nil && schema != "" { - return false - } - if o.TableSchema != nil && !o.TableSchema.MatchString(schema) { - return false - } - if o.TableRel == nil && n.Name != "" { - return false - } - if o.TableRel != nil && !o.TableRel.MatchString(n.Name) { - return false - } - return true -} - -func (o *Override) parse(req *plugin.GenerateRequest) (err error) { - - schema := "public" - if req != nil && req.Catalog != nil { - schema = req.Catalog.DefaultSchema - } - - // validate option combinations - switch { - case o.Column != "" && o.DBType != "": - return fmt.Errorf("Override specifying both `column` (%q) and `db_type` (%q) is not valid.", o.Column, o.DBType) - case o.Column == "" && o.DBType == "": - return fmt.Errorf("Override must specify one of either `column` or `db_type`") - } - - // validate Column - if o.Column != "" { - colParts := strings.Split(o.Column, ".") - switch len(colParts) { - case 2: - if o.ColumnName, err = pattern.MatchCompile(colParts[1]); err != nil { - return err - } - if o.TableRel, err = pattern.MatchCompile(colParts[0]); err != nil { - return err - } - if o.TableSchema, err = pattern.MatchCompile(schema); err != nil { - return err - } - case 3: - if o.ColumnName, err = pattern.MatchCompile(colParts[2]); err != nil { - return err - } - if o.TableRel, err = pattern.MatchCompile(colParts[1]); err != nil { - return err - } - if o.TableSchema, err = pattern.MatchCompile(colParts[0]); err != nil { - return err - } - case 4: - if o.ColumnName, err = pattern.MatchCompile(colParts[3]); err != nil { - return err - } - if o.TableRel, err = pattern.MatchCompile(colParts[2]); err != nil { - return err - } - if o.TableSchema, err = pattern.MatchCompile(colParts[1]); err != nil { - return err - } - if o.TableCatalog, err = pattern.MatchCompile(colParts[0]); err != nil { - return err - } - default: - return fmt.Errorf("Override `column` specifier %q is not the proper format, expected '[catalog.][schema.]tablename.colname'", o.Column) - } - } - - // validate GoType - parsed, err := o.PyType.parse() - if err != nil { - return err - } - o.PyImportPath = parsed.ImportPath - o.PyTypeName = parsed.TypeName - o.PyBasicType = parsed.BasicType - o.PyPackageName = parsed.PackageName - return nil -} diff --git a/internal/core/utils.go b/internal/core/utils.go deleted file mode 100644 index 51f0896f..00000000 --- a/internal/core/utils.go +++ /dev/null @@ -1,94 +0,0 @@ -package core - -import ( - "bufio" - "fmt" - "github.com/sqlc-dev/plugin-sdk-go/plugin" - "golang.org/x/text/cases" - "golang.org/x/text/language" - "strings" - "unicode" - "unicode/utf8" -) - -func ModelName(enumName string, schemaName string, conf *Config) string { - if schemaName != "" { - enumName = schemaName + "_" + enumName - } - return SnakeToCamel(enumName, conf) -} - -func SnakeToCamel(s string, conf *Config) string { - out := "" - s = strings.Map(func(r rune) rune { - if unicode.IsLetter(r) { - return r - } - if unicode.IsDigit(r) { - return r - } - return rune('_') - }, s) - for _, p := range strings.Split(s, "_") { - if _, found := conf.InitialismsMap[p]; found { - out += strings.ToUpper(p) - } else { - out += cases.Title(language.Und, cases.NoLower).String(p) - } - } - r, _ := utf8.DecodeRuneInString(out) - if unicode.IsDigit(r) { - return "_" + out - } else { - return out - } -} - -func ColumnName(c *plugin.Column, pos int) string { - if c.Name != "" { - return c.Name - } - return fmt.Sprintf("column_%d", pos+1) -} - -func ParamName(p *plugin.Parameter) string { - if p.Column.Name != "" { - return p.Column.Name - } - return fmt.Sprintf("dollar_%d", p.Number) -} - -func UpperSnakeCase(s string) string { - result := "" - for i, r := range s { - if unicode.IsUpper(r) && i != 0 { - result += "_" + string(r) - } else { - result += string(r) - } - } - result = strings.ToUpper(result) - return result -} - -func SQLToPyFileName(s string) string { - return strings.ReplaceAll(s, ".sql", ".py") -} - -func SplitLines(s string) []string { - var lines []string - sc := bufio.NewScanner(strings.NewReader(s)) - for sc.Scan() { - lines = append(lines, sc.Text()) - } - return lines -} - -func IsInMultipleMaps[K comparable, V any](search K, maps ...map[K]V) bool { - for _, m := range maps { - if _, found := m[search]; found { - return true - } - } - return false -} diff --git a/internal/driver/asyncpg.go b/internal/driver/asyncpg.go new file mode 100644 index 00000000..57135a65 --- /dev/null +++ b/internal/driver/asyncpg.go @@ -0,0 +1,230 @@ +package driver + +import ( + "fmt" + "strings" + + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/writer" + "github.com/sqlc-dev/plugin-sdk-go/metadata" +) + +const ( + asyncpgConnType = "ConnectionLike" + asyncpgResultType = "asyncpg.Record" +) + +// AsyncpgDriver generates Python code for the asyncpg (async PostgreSQL) driver. +type AsyncpgDriver struct { + rows *RowBuilder +} + +func newAsyncpgDriver() *AsyncpgDriver { + return &AsyncpgDriver{ + rows: newRowBuilder(asyncpgNeedsConversion), + } +} + +// Name returns "asyncpg". +func (d *AsyncpgDriver) Name() string { return "asyncpg" } + +// ConnType returns "ConnectionLike". +func (d *AsyncpgDriver) ConnType() string { return asyncpgConnType } + +// IsAsync returns true. +func (d *AsyncpgDriver) IsAsync() bool { return true } + +// NeedsConversion reports whether a SQL type needs runtime conversion for asyncpg. +func (d *AsyncpgDriver) NeedsConversion(sqlType string) bool { + return asyncpgNeedsConversion(sqlType) +} + +// ConvertsInline reports whether a SQL type is converted inline; asyncpg converts +// everything inline (no registration mechanism). +func (d *AsyncpgDriver) ConvertsInline(sqlType string) bool { + return asyncpgNeedsConversion(sqlType) +} + +// WriteConversionSetup is a no-op for asyncpg. +func (d *AsyncpgDriver) WriteConversionSetup(_ *writer.CodeWriter, _ *config.Config, _ []model.Query) bool { + return false +} + +// TypeCheckingHook returns the ConnectionLike type alias. The PEP 695 form +// is lazy by design, which matters here: asyncpg.Connection[...] is a +// stub-only generic that raises TypeError when subscripted at runtime, and +// with omit_typechecking_block the alias is emitted at module level where it +// actually executes. +func (d *AsyncpgDriver) TypeCheckingHook() []string { + return []string{ + fmt.Sprintf( + "type ConnectionLike = asyncpg.Connection[%[1]s] | asyncpg.pool.PoolConnectionProxy[%[1]s]", + asyncpgResultType, + ), + } +} + +// WriteQueryResultsClass writes the async QueryResults class for asyncpg :many queries. +func (d *AsyncpgDriver) WriteQueryResultsClass(body *writer.CodeWriter) string { + body.QueryResults.WriteQueryResultsClassHeader(asyncpgConnType, []string{ + fmt.Sprintf("self._cursor: asyncpg.cursor.CursorFactory[%s] | None = None", asyncpgResultType), + fmt.Sprintf("self._iterator: asyncpg.cursor.CursorIterator[%s] | None = None", asyncpgResultType), + }, asyncpgResultType, d.IsAsync()) + body.QueryResults.WriteQueryResultsAwaitFunction([]string{ + "result = await self._conn.fetch(self._sql, *self._args)", + "return [self._decode_hook(row) for row in result]", + }) + body.NewLine() + body.WriteIndentedLine(1, "async def __anext__(self) -> T:") + body.WriteQueryResultsNextDocstring("an asyncpg cursor", d.IsAsync()) + body.WriteIndentedLine(2, "if self._cursor is None or self._iterator is None:") + body.WriteIndentedLine(3, "self._cursor = self._conn.cursor(self._sql, *self._args)") + body.WriteIndentedLine(3, "self._iterator = self._cursor.__aiter__()") + body.WriteIndentedLine(2, "try:") + body.WriteIndentedLine(3, "record = await self._iterator.__anext__()") + body.WriteIndentedLine(2, "except StopAsyncIteration:") + body.WriteIndentedLine(3, "self._cursor = None") + body.WriteIndentedLine(3, "self._iterator = None") + body.WriteIndentedLine(3, "raise") + body.WriteIndentedLine(2, "return self._decode_hook(record)") + return "QueryResults" +} + +// SupportsCommand returns if the driver supports the command. +func (d *AsyncpgDriver) SupportsCommand(cmd string) bool { + switch cmd { + case metadata.CmdExec, + metadata.CmdExecResult, + metadata.CmdExecRows, + metadata.CmdOne, + metadata.CmdMany, + metadata.CmdCopyFrom: + return true + default: + return false + } +} + +func (d *AsyncpgDriver) WriteQueryFunc(body *writer.CodeWriter, config *config.Config, query model.Query, indent int) { + var annotation, docRetType string + switch query.Cmd { + case metadata.CmdExec: + annotation, docRetType = query.Returns.Type.Print(), "" + case metadata.CmdExecResult: + annotation, docRetType = "str", "str" + case metadata.CmdExecRows, metadata.CmdCopyFrom: + annotation, docRetType = query.Returns.Type.Print(), query.Returns.Type.Type + case metadata.CmdOne: + annotation, docRetType = query.Returns.Type.PrintOptional(), query.Returns.Type.Type + case metadata.CmdMany: + annotation, docRetType = "QueryResults["+query.Returns.Type.Print()+"]", query.Returns.Type.Print() + } + + conn := writeFuncSignature(body, d, config, indent, query, annotation) + + indent++ + writeQueryDocstring(body, d, config, query, indent, docRetType) + callArgs := append([]string{query.ConstantName}, expandParams(query)...) + switch query.Cmd { + case metadata.CmdExec: + body.WriteWrappedCall(indent, fmt.Sprintf("await %s.execute(", conn), callArgs, ")") + + case metadata.CmdExecResult: + body.WriteWrappedCall(indent, fmt.Sprintf("return await %s.execute(", conn), callArgs, ")") + + case metadata.CmdExecRows: + body.WriteWrappedCall(indent, fmt.Sprintf("r = await %s.execute(", conn), callArgs, ")") + writeExecRowsReturn(body, config, indent) + + case metadata.CmdCopyFrom: + writeCopyFromBody(body, config, query, conn, indent) + + case metadata.CmdOne: + body.WriteWrappedCall(indent, fmt.Sprintf("row = await %s.fetchrow(", conn), callArgs, ")") + body.WriteIndentedLine(indent, "if row is None:") + body.WriteIndentedLine(indent+1, "return None") + + if query.Returns.IsStruct() { + d.rows.WriteStructReturn(body, indent, query.Returns) + } else { + d.rows.WriteScalarReturn(body, indent, query.Returns) + } + + case metadata.CmdMany: + decodeHook := d.rows.WriteDecodeHook(body, indent, query, asyncpgResultType) + manyArgs := append([]string{conn, query.ConstantName, decodeHook}, expandParams(query)...) + // Deliberately unsubscripted: QueryResults[T](...) would go through + // typing's _GenericAlias.__call__ on every invocation (~10x call + // overhead) for zero benefit - the return annotation carries the type. + body.WriteWrappedCall(indent, "return QueryResults(", manyArgs, ")") + } +} + +// writeCopyFromBody writes the body for an asyncpg :copyfrom command. +func writeCopyFromBody(body *writer.CodeWriter, config *config.Config, query model.Query, conn string, indent int) { + var paramParts []string + var columnParts []string + for _, col := range query.Params[0].Table.Columns { + // Overridden columns convert back to their DefaultType here too: + // copy_records_to_table receives the raw record values, so this is + // the only place the conversion can happen for :copyfrom. + paramParts = append(paramParts, convertParamExpr(fmt.Sprintf("param.%s", col.Name), col.Type)) + columnParts = append(columnParts, fmt.Sprintf(`"%s"`, col.DBName)) + } + + paramsName := query.Params[0].Name + recordTuple := "(" + strings.Join(paramParts, ", ") + ")" + if len(paramParts) == 1 { + // A one-element tuple needs the trailing comma, otherwise the + // parentheses are just grouping and the record is a bare value. + recordTuple = "(" + paramParts[0] + ",)" + } + singleComprehension := fmt.Sprintf("records = [%s for param in %s]", recordTuple, paramsName) + switch { + case body.FitsLine(indent, singleComprehension): + body.WriteIndentedLine(indent, singleComprehension) + case body.FitsLine(indent+1, recordTuple): + body.WriteIndentedLine(indent, "records = [") + body.WriteIndentedLine(indent+1, recordTuple) + body.WriteIndentedLine(indent+1, "for param in "+paramsName) + body.WriteIndentedLine(indent, "]") + default: + body.WriteIndentedLine(indent, "records = [") + body.WriteIndentedLine(indent+1, "(") + for _, part := range paramParts { + body.WriteIndentedLine(indent+2, part+",") + } + body.WriteIndentedLine(indent+1, ")") + body.WriteIndentedLine(indent+1, "for param in "+paramsName) + body.WriteIndentedLine(indent, "]") + } + columnsArg := fmt.Sprintf("columns=[%s]", strings.Join(columnParts, ", ")) + copyArgs := []string{fmt.Sprintf(`"%s"`, query.Table.Name), columnsArg, "records=records"} + if query.Table.Schema != "" { + copyArgs = append(copyArgs, fmt.Sprintf(`schema_name="%s"`, query.Table.Schema)) + } + + head := fmt.Sprintf("r = await %s.copy_records_to_table(", conn) + single := head + strings.Join(copyArgs, ", ") + ")" + switch { + case body.FitsLine(indent, single): + body.WriteIndentedLine(indent, single) + default: + body.WriteIndentedLine(indent, head) + for _, arg := range copyArgs { + if arg == columnsArg && !body.FitsLine(indent+1, arg+",") { + body.WriteIndentedLine(indent+1, "columns=[") + for _, col := range columnParts { + body.WriteIndentedLine(indent+2, col+",") + } + body.WriteIndentedLine(indent+1, "],") + + continue + } + body.WriteIndentedLine(indent+1, arg+",") + } + body.WriteIndentedLine(indent, ")") + } + writeExecRowsReturn(body, config, indent) +} diff --git a/internal/driver/common.go b/internal/driver/common.go new file mode 100644 index 00000000..d7ea65e1 --- /dev/null +++ b/internal/driver/common.go @@ -0,0 +1,116 @@ +package driver + +import ( + "fmt" + + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/writer" + "github.com/sqlc-dev/plugin-sdk-go/metadata" +) + +func writeFuncSignature( + body *writer.CodeWriter, + d Driver, + config *config.Config, + indent int, + query model.Query, + returnAnnotation string, +) string { + conn := "conn" + first := fmt.Sprintf("conn: %s", d.ConnType()) + if config.EmitClasses { + first = "self" + conn = "self._conn" + } + asyncPrefix := "" + if d.IsAsync() && query.Cmd != metadata.CmdMany { + asyncPrefix = "async " + } + + args := []string{first} + if len(query.Params) > config.OmitKwargsLimit { + args = append(args, "*") + } + for _, param := range query.Params { + args = append(args, fmt.Sprintf("%s: %s", param.Name, param.Type.Print())) + } + body.WriteWrappedCall(indent, + fmt.Sprintf("%sdef %s(", asyncPrefix, query.FuncName), + args, + fmt.Sprintf(") -> %s:", returnAnnotation), + ) + + return conn +} + +// expandParams returns the Python argument expressions for a query's parameters. +// Bundled Params classes (query_parameter_limit) are expanded into their fields +// ("params.a, params.b") so drivers receive positional values. :copyfrom params +// are never passed through here - writeCopyFromBody builds its own records list. +func expandParams(query model.Query) []string { + parts := make([]string, 0, len(query.Params)) + for _, param := range query.Params { + if param.IsEmpty() { + continue + } + if param.EmitTable && param.Table != nil { + for _, col := range param.Table.Columns { + parts = append(parts, convertParamExpr(fmt.Sprintf("%s.%s", param.Name, col.Name), col.Type)) + } + + continue + } + parts = append(parts, convertParamExpr(param.Name, param.Type)) + } + + return parts +} + +// writeQueryDocstring writes the docstring for a generated query function. +// retType is the type shown in the Returns section (driver-specific for some +// commands); pass "" for commands without one (:exec). +func writeQueryDocstring(body *writer.CodeWriter, d Driver, cfg *config.Config, query model.Query, indent int, retType string) { + connType := "" + if !cfg.EmitClasses { + connType = d.ConnType() + } + args := make([]writer.DocArg, 0, len(query.Params)) + for _, param := range query.Params { + if param.IsEmpty() { + continue + } + extra := "" + if query.Cmd == metadata.CmdCopyFrom { + extra = "A list of params for rows that should be inserted." + } + args = append(args, writer.DocArg{Name: param.Name, Type: param.Type.Print(), Extra: extra}) + } + body.WriteQueryFunctionDocstring(indent, &query, connType, args, retType) +} + +// convertParamExpr converts an overridden argument back to the type the driver +// expects (its DefaultType) before passing it on. List values convert +// element-wise, mirroring RowBuilder.convertExpr on the return side. +func convertParamExpr(expr string, typ model.PyType) string { + if !typ.DoOverride() { + return expr + } + converted := fmt.Sprintf("%s(%s)", typ.DefaultType, expr) + if typ.IsList { + converted = fmt.Sprintf("[%s(v) for v in %s]", typ.DefaultType, expr) + } + if typ.IsNullable { + return fmt.Sprintf("%s if %s is not None else None", converted, expr) + } + + return converted +} + +func writeExecRowsReturn(body *writer.CodeWriter, config *config.Config, indent int) { + if config.Speedups { + body.WriteIndentedLine(indent, "return int(n) if (n := r.split()[-1]).isdigit() else 0") + } else { + body.WriteIndentedLine(indent, "return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0") + } +} diff --git a/internal/driver/conversion.go b/internal/driver/conversion.go new file mode 100644 index 00000000..2c375a47 --- /dev/null +++ b/internal/driver/conversion.go @@ -0,0 +1,228 @@ +package driver + +import ( + "strings" + + "github.com/rayakame/sqlc-gen-better-python/internal/model" +) + +// asyncpgConversions lists SQL types that need explicit Python-side +// type conversion when using the asyncpg driver. +var asyncpgConversions = map[string]struct{}{ + "bytea": {}, + "blob": {}, + "pg_catalog.bytea": {}, + "inet": {}, + "cidr": {}, +} + +// asyncpgNeedsConversion reports whether a SQL type needs runtime conversion for asyncpg. +func asyncpgNeedsConversion(sqlType string) bool { + _, ok := asyncpgConversions[sqlType] + return ok +} + +// sqliteConversion fully describes one sqlite type conversion: the SQL type +// names that trigger it (which double as the register_converter keys), the +// Python type, and how to emit its adapter/converter pair. Adding a new +// convertible type means adding exactly one entry here. +type sqliteConversion struct { + pyType string // Python type the adapter is registered for + suffix string // function name suffix, e.g. "date" + sqlTypes []string // SQL type names mapping to this conversion / converter keys + adaptRet string // adapter return annotation + adaptBody string // adapter body expression + convBody string // converter body expression + speedupsBody string // converter body when speedups are enabled ("" = same as convBody) +} + +// sqliteConversions is ordered: the slice order defines the emission order of +// the adapter/converter pairs in generated modules. +var sqliteConversions = []sqliteConversion{ + { + pyType: "datetime.date", + suffix: "date", + sqlTypes: []string{"date"}, + adaptRet: "str", + adaptBody: "val.isoformat()", + convBody: "datetime.date.fromisoformat(val.decode())", + speedupsBody: "ciso8601.parse_datetime(val.decode()).date()", + }, + { + pyType: "decimal.Decimal", + suffix: "decimal", + sqlTypes: []string{"decimal"}, + adaptRet: "str", + adaptBody: "str(val)", + convBody: "decimal.Decimal(val.decode())", + speedupsBody: "", + }, + { + pyType: "datetime.datetime", + suffix: "datetime", + sqlTypes: []string{"datetime", "timestamp"}, + adaptRet: "str", + adaptBody: "val.isoformat()", + convBody: "datetime.datetime.fromisoformat(val.decode())", + speedupsBody: "ciso8601.parse_datetime(val.decode())", + }, + { + pyType: "bool", + suffix: "bool", + sqlTypes: []string{"bool", "boolean"}, + adaptRet: "int", + adaptBody: "int(val)", + convBody: "bool(int(val))", + speedupsBody: "", + }, + { + pyType: "memoryview", + suffix: "memoryview", + sqlTypes: []string{"blob"}, + adaptRet: "bytes", + adaptBody: "val.tobytes()", + convBody: "memoryview(val)", + speedupsBody: "", + }, +} + +// findSqliteConversion returns the conversion spec for a SQL type, or nil. +func findSqliteConversion(sqlType string) *sqliteConversion { + for i := range sqliteConversions { + for _, name := range sqliteConversions[i].sqlTypes { + if name == sqlType { + return &sqliteConversions[i] + } + } + } + // Precision variants like "decimal(10,5)" keep their prefix; resolve them + // through the exact "decimal" key. + if strings.HasPrefix(sqlType, "decimal") { + return findSqliteConversion("decimal") + } + + return nil +} + +// sqliteNeedsConversion reports whether a SQL type needs runtime conversion for sqlite. +func sqliteNeedsConversion(sqlType string) bool { + return findSqliteConversion(sqlType) != nil +} + +// sqliteConversionUse marks which half of a conversion spec's adapter/converter +// pair the queries actually need. +type sqliteConversionUse struct { + spec *sqliteConversion + adapter bool + converter bool +} + +// SqliteConversionUsage lists the conversion specs a module's queries need, in +// canonical emission order, split by direction: parameters need a registered +// adapter (Python value -> SQL), returns need a registered converter (SQL value +// -> Python). Registering only what is needed matters because sqlite3 +// converters are global: an unnecessary register_converter would change what +// overridden return columns receive under PARSE_DECLTYPES. +type SqliteConversionUsage struct { + uses []sqliteConversionUse +} + +// Any reports whether at least one adapter or converter must be registered. +func (u SqliteConversionUsage) Any() bool { + return len(u.uses) > 0 +} + +// RuntimeModules returns the Python modules the emitted conversion setup +// references at runtime: register_adapter needs the adapted type's module, +// and converter bodies reference their type's module unless the speedups +// variant (which references only ciso8601) replaces them. Builtin types +// (bool, memoryview) need no import. +func (u SqliteConversionUsage) RuntimeModules(speedups bool) map[string]struct{} { + modules := make(map[string]struct{}) + for _, use := range u.uses { + module, _, found := strings.Cut(use.spec.pyType, ".") + if !found { + continue + } + if use.adapter || (use.converter && (!speedups || use.spec.speedupsBody == "")) { + modules[module] = struct{}{} + } + } + + return modules +} + +// SpeedupConverterUsed reports whether any needed converter has a speedups +// variant - i.e. whether the generated module references ciso8601 when the +// speedups option is enabled. +func (u SqliteConversionUsage) SpeedupConverterUsed() bool { + for _, use := range u.uses { + if use.converter && use.spec.speedupsBody != "" { + return true + } + } + + return false +} + +// SqliteConversionsUsed collects the conversion specs used by the queries. +// Overridden RETURN columns need no converter - they are converted inline with +// the override type, and registering one anyway would hand the override +// constructor an already-converted value. Overridden PARAMS do need the +// adapter: convertParamExpr converts them back to their DefaultType before +// they reach the driver. +func SqliteConversionsUsed(queries []model.Query) SqliteConversionUsage { + adapters := make(map[string]struct{}) + converters := make(map[string]struct{}) + addParam := func(typ model.PyType) { + if spec := findSqliteConversion(typ.SQLType); spec != nil { + adapters[spec.pyType] = struct{}{} + } + } + addReturn := func(typ model.PyType) { + if typ.DoOverride() { + return + } + if spec := findSqliteConversion(typ.SQLType); spec != nil { + converters[spec.pyType] = struct{}{} + } + } + collect := func(qv model.QueryValue, add func(model.PyType)) { + if qv.IsEmpty() { + return + } + if qv.IsStruct() { + for _, col := range qv.Table.Columns { + if col.Embed != nil { + for _, embedCol := range col.Embed.Columns { + add(embedCol.Type) + } + + continue + } + add(col.Type) + } + + return + } + add(qv.Type) + } + for _, query := range queries { + collect(query.Returns, addReturn) + for _, param := range query.Params { + collect(param, addParam) + } + } + + usage := SqliteConversionUsage{uses: make([]sqliteConversionUse, 0, len(adapters)+len(converters))} + for i := range sqliteConversions { + spec := &sqliteConversions[i] + _, adapter := adapters[spec.pyType] + _, converter := converters[spec.pyType] + if adapter || converter { + usage.uses = append(usage.uses, sqliteConversionUse{spec: spec, adapter: adapter, converter: converter}) + } + } + + return usage +} diff --git a/internal/driver/driver.go b/internal/driver/driver.go new file mode 100644 index 00000000..6722c9d1 --- /dev/null +++ b/internal/driver/driver.go @@ -0,0 +1,61 @@ +package driver + +import ( + "fmt" + + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/writer" +) + +type Driver interface { + // Name returns the Python module name (e.g., "asyncpg", "aiosqlite", "sqlite3"). + Name() string + + // ConnType returns the Python type annotation for the connection parameter. + ConnType() string + + // SupportsCommand returns if the driver supports the command. + SupportsCommand(cmd string) bool + + // IsAsync reports whether this driver uses async/await. + IsAsync() bool + + // NeedsConversion reports whether a SQL type needs explicit Python-side conversion, + // meaning the type's module must be imported at runtime (not TYPE_CHECKING-only). + NeedsConversion(sqlType string) bool + + // ConvertsInline reports whether values of this SQL type are converted inline in + // generated decode code. Drivers that register converters instead return false. + // Must stay in sync with the RowBuilder's conversion check. + ConvertsInline(sqlType string) bool + + // WriteConversionSetup writes module-level type conversion setup (e.g. sqlite + // adapter/converter registration) and reports whether anything was written. + WriteConversionSetup(body *writer.CodeWriter, config *config.Config, queries []model.Query) bool + + // WriteQueryFunc writes the Python function body for a single query. + WriteQueryFunc(body *writer.CodeWriter, config *config.Config, query model.Query, indent int) + + // WriteQueryResultsClass writes the QueryResults helper class for :many queries. + // Returns the class name (typically "QueryResults"). + WriteQueryResultsClass(w *writer.CodeWriter) string + + // TypeCheckingHook returns additional lines to emit in the TYPE_CHECKING + // block. The lines must also be runtime-safe: with omit_typechecking_block + // they are emitted at module level and actually execute. + TypeCheckingHook() []string +} + +func New(conf *config.Config) (Driver, error) { + switch conf.SqlDriver { + case config.SQLDriverAsyncpg: + return newAsyncpgDriver(), nil + case config.SQLDriverAioSQLite: + return newSqliteDriver("aiosqlite", true), nil + case config.SQLDriverSQLite: + return newSqliteDriver("sqlite3", false), nil + default: + return nil, fmt.Errorf("unsupported driver: %s", conf.SqlDriver) + } +} diff --git a/internal/driver/rowbuilder.go b/internal/driver/rowbuilder.go new file mode 100644 index 00000000..939e09bf --- /dev/null +++ b/internal/driver/rowbuilder.go @@ -0,0 +1,139 @@ +package driver + +import ( + "fmt" + "strconv" + "strings" + + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/writer" +) + +// RowBuilder generates Python code that constructs a model instance from a database row. +// It handles embeds, nullable conversions, and overrides uniformly across all drivers. +type RowBuilder struct { + // needsConversion checks whether a SQL type requires explicit conversion. + needsConversion func(string) bool +} + +// newRowBuilder creates a RowBuilder with the given conversion check function. +func newRowBuilder(needsConversion func(string) bool) *RowBuilder { + return &RowBuilder{needsConversion: needsConversion} +} + +// WriteStructReturn writes "return ModelType(col1=row[0], col2=row[1], ...)" +// handling embeds, nullable wrapping, and type conversions. Constructions that +// would exceed the line limit are exploded with magic trailing commas. +func (rb *RowBuilder) WriteStructReturn(body *writer.CodeWriter, indent int, ret model.QueryValue) { + head := fmt.Sprintf("return %s(", ret.Type.Type) + + args := make([]string, 0, len(ret.Table.Columns)) + idx := 0 + for _, col := range ret.Table.Columns { + if col.Embed != nil { + args = append(args, rb.formatEmbedConstruction(col, &idx)) + } else { + args = append(args, rb.formatColumnValue(col, idx)) + idx++ + } + } + + single := head + strings.Join(args, ", ") + ")" + if body.FitsLine(indent, single) { + body.WriteIndentedLine(indent, single) + + return + } + + body.WriteIndentedLine(indent, head) + idx = 0 + for _, col := range ret.Table.Columns { + if col.Embed != nil { + embedHead := fmt.Sprintf("%s=%s(", col.Name, col.Type.Type) + embedArgs := make([]string, 0, len(col.Embed.Columns)) + for _, embedCol := range col.Embed.Columns { + embedArgs = append(embedArgs, rb.formatColumnValue(embedCol, idx)) + idx++ + } + body.WriteWrappedCall(indent+1, embedHead, embedArgs, "),") + + continue + } + body.WriteIndentedLine(indent+1, rb.formatColumnValue(col, idx)+",") + idx++ + } + body.WriteIndentedLine(indent, ")") +} + +// WriteDecodeHook writes a _decode_hook function for :many queries or returns +// "operator.itemgetter(0)" for simple non-converted scalar returns. The blank +// lines around the nested def match ruff format's layout. +func (rb *RowBuilder) WriteDecodeHook(body *writer.CodeWriter, indent int, query model.Query, resultType string) string { + // Simple scalar without conversion: use itemgetter. + if !query.Returns.IsStruct() && !rb.columnNeedsConversion(query.Returns.Type) { + return "operator.itemgetter(0)" + } + + if body.DocstringsEnabled() { + body.NewLine() + } + body.WriteIndentedLine(indent, fmt.Sprintf("def _decode_hook(row: %s) -> %s:", resultType, query.Returns.Type.Print())) + if query.Returns.IsStruct() { + rb.WriteStructReturn(body, indent+1, query.Returns) + } else { + body.WriteIndentedLine(indent+1, "return "+rb.convertExpr(query.Returns.Type, "row[0]")) + } + body.NewLine() + + return "_decode_hook" +} + +// WriteScalarReturn writes the return statement for a non-struct :one query. +func (rb *RowBuilder) WriteScalarReturn(body *writer.CodeWriter, indent int, ret model.QueryValue) { + if rb.columnNeedsConversion(ret.Type) { + body.WriteIndentedLine(indent, "return "+rb.convertExpr(ret.Type, "row[0]")) + } else { + body.WriteIndentedLine(indent, "return row[0]") + } +} + +// formatEmbedConstruction returns "name=EmbedType(field1=row[i], ...)". +func (rb *RowBuilder) formatEmbedConstruction(col model.Column, idx *int) string { + inner := make([]string, 0, len(col.Embed.Columns)) + for _, embedCol := range col.Embed.Columns { + inner = append(inner, rb.formatColumnValue(embedCol, *idx)) + *idx++ + } + + return fmt.Sprintf("%s=%s(%s)", col.Name, col.Type.Type, strings.Join(inner, ", ")) +} + +// convertExpr returns the Python expression converting a raw row value into +// its target type: constructor call for scalars, an element-wise comprehension +// for lists, both guarded against None for nullable values. +func (rb *RowBuilder) convertExpr(typ model.PyType, src string) string { + if !rb.columnNeedsConversion(typ) { + return src + } + expr := fmt.Sprintf("%s(%s)", typ.Type, src) + if typ.IsList { + expr = fmt.Sprintf("[%s(v) for v in %s]", typ.Type, src) + } + if typ.IsNullable { + expr = fmt.Sprintf("%s if %s is not None else None", expr, src) + } + + return expr +} + +// columnNeedsConversion reports whether a column type needs explicit conversion. +// Enum columns always convert: the driver returns the raw value (e.g. str), +// which must be wrapped in the generated enum class. +func (rb *RowBuilder) columnNeedsConversion(typ model.PyType) bool { + return typ.DoOverride() || typ.IsEnum || rb.needsConversion(typ.SQLType) +} + +// formatColumnValue returns the Python expression for accessing a single column from a row. +func (rb *RowBuilder) formatColumnValue(col model.Column, idx int) string { + return fmt.Sprintf("%s=%s", col.Name, rb.convertExpr(col.Type, "row["+strconv.Itoa(idx)+"]")) +} diff --git a/internal/driver/sqlite_base.go b/internal/driver/sqlite_base.go new file mode 100644 index 00000000..6216fe0a --- /dev/null +++ b/internal/driver/sqlite_base.go @@ -0,0 +1,282 @@ +package driver + +import ( + "fmt" + "strings" + + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/writer" + "github.com/sqlc-dev/plugin-sdk-go/metadata" +) + +const sqliteResultType = "sqlite3.Row" + +// sqliteBase is the complete driver implementation for both sqlite modules - +// sqlite3 (sync) and aiosqlite (async). All emission differences between the +// two are derived from moduleName and the async flag. +type sqliteBase struct { + moduleName string // "sqlite3" or "aiosqlite" + async bool + rows *RowBuilder +} + +var _ Driver = (*sqliteBase)(nil) + +// newSqliteDriver creates the driver for one of the two sqlite modules. The +// RowBuilder never converts inline (except overrides/enums): registered +// converters handle the raw values, see WriteConversionSetup. +func newSqliteDriver(moduleName string, async bool) *sqliteBase { + return &sqliteBase{ + moduleName: moduleName, + async: async, + rows: newRowBuilder(func(string) bool { return false }), + } +} + +// Name returns the Python module name ("sqlite3" or "aiosqlite"). +func (sb *sqliteBase) Name() string { return sb.moduleName } + +// ConnType returns the connection type annotation, e.g. "sqlite3.Connection". +func (sb *sqliteBase) ConnType() string { return sb.moduleName + ".Connection" } + +// IsAsync reports whether this is the aiosqlite (async) driver. +func (sb *sqliteBase) IsAsync() bool { return sb.async } + +// SupportsCommand returns if the driver supports the command. +func (sb *sqliteBase) SupportsCommand(cmd string) bool { + switch cmd { + case metadata.CmdExec, + metadata.CmdExecResult, + metadata.CmdExecLastId, + metadata.CmdExecRows, + metadata.CmdOne, + metadata.CmdMany: + return true + default: + return false + } +} + +// TypeCheckingHook returns nil (no type-checking hook for sqlite drivers). +func (sb *sqliteBase) TypeCheckingHook() []string { + return nil +} + +// NeedsConversion reports whether a SQL type needs runtime conversion for sqlite. +func (sb *sqliteBase) NeedsConversion(sqlType string) bool { + return sqliteNeedsConversion(sqlType) +} + +// ConvertsInline always returns false: sqlite drivers convert via registered +// adapters/converters, not inline in decode code. +func (sb *sqliteBase) ConvertsInline(_ string) bool { + return false +} + +// WriteConversionSetup writes the adapter/converter functions and their +// registrations for every conversion type used by the given queries. +// Values written by adapters and read back by converters require the user's +// connection to be opened with detect_types=sqlite3.PARSE_DECLTYPES. +func (sb *sqliteBase) WriteConversionSetup(body *writer.CodeWriter, config *config.Config, queries []model.Query) bool { + usage := SqliteConversionsUsed(queries) + if !usage.Any() { + return false + } + + adapters := make([]string, 0, len(usage.uses)) + converters := make([]string, 0, len(usage.uses)) + for _, use := range usage.uses { + spec := use.spec + + if use.adapter { + body.WriteLine(fmt.Sprintf("def _adapt_%s(val: %s) -> %s:", spec.suffix, spec.pyType, spec.adaptRet)) + body.WriteIndentedLine(1, "return "+spec.adaptBody) + body.NNewLine(2) + adapters = append( + adapters, + fmt.Sprintf("%s.register_adapter(%s, _adapt_%s)", sb.moduleName, spec.pyType, spec.suffix), + ) + } + + if use.converter { + convBody := spec.convBody + if config.Speedups && spec.speedupsBody != "" { + convBody = spec.speedupsBody + } + body.WriteLine(fmt.Sprintf("def _convert_%s(val: bytes) -> %s:", spec.suffix, spec.pyType)) + body.WriteIndentedLine(1, "return "+convBody) + body.NNewLine(2) + for _, key := range spec.sqlTypes { + converters = append( + converters, + fmt.Sprintf(`%s.register_converter("%s", _convert_%s)`, sb.moduleName, key, spec.suffix), + ) + } + } + } + + for _, line := range adapters { + body.WriteLine(line) + } + if len(adapters) != 0 && len(converters) != 0 { + body.NewLine() + } + for _, line := range converters { + body.WriteLine(line) + } + + return true +} + +// WriteQueryResultsClass writes the QueryResults class for :many queries, +// in its sync (sqlite3) or async (aiosqlite) variant. +func (sb *sqliteBase) WriteQueryResultsClass(body *writer.CodeWriter) string { + cursorType := sb.moduleName + ".Cursor" + awaitKw, iteratorType, nextDef, iterDunder, nextDunder, stopExc, article := "", "Iterator", "def __next__", "__iter__", "__next__", "StopIteration", "a " + if sb.async { + awaitKw, iteratorType, nextDef, iterDunder, nextDunder, stopExc, article = "await ", "AsyncIterator", "async def __anext__", "__aiter__", "__anext__", "StopAsyncIteration", "an " + } + + body.QueryResults.WriteQueryResultsClassHeader(sb.ConnType(), []string{ + fmt.Sprintf("self._cursor: %s | None = None", cursorType), + fmt.Sprintf("self._iterator: collections.abc.%s[%s] | None = None", iteratorType, sqliteResultType), + }, sqliteResultType, sb.async) + if sb.async { + body.QueryResults.WriteQueryResultsAwaitFunction([]string{ + "result = await (await self._conn.execute(self._sql, self._args)).fetchall()", + "return [self._decode_hook(row) for row in result]", + }) + } else { + body.QueryResults.WriteQueryResultsCallFunction([]string{ + "result = self._conn.execute(self._sql, self._args).fetchall()", + "return [self._decode_hook(row) for row in result]", + }) + } + body.NewLine() + body.WriteIndentedLine(1, nextDef+"(self) -> T:") + body.WriteQueryResultsNextDocstring(article+sb.moduleName+" cursor", sb.async) + body.WriteIndentedLine(2, "if self._cursor is None or self._iterator is None:") + body.WriteIndentedLine( + 3, + fmt.Sprintf("self._cursor: %s | None = %sself._conn.execute(self._sql, self._args)", cursorType, awaitKw), + ) + body.WriteIndentedLine(3, fmt.Sprintf("self._iterator = self._cursor.%s()", iterDunder)) + body.WriteIndentedLine(2, "try:") + body.WriteIndentedLine(3, fmt.Sprintf("record = %sself._iterator.%s()", awaitKw, nextDunder)) + body.WriteIndentedLine(2, "except "+stopExc+":") + body.WriteIndentedLine(3, "self._cursor = None") + body.WriteIndentedLine(3, "self._iterator = None") + body.WriteIndentedLine(3, "raise") + body.WriteIndentedLine(2, "return self._decode_hook(record)") + + return "QueryResults" +} + +func (sb *sqliteBase) WriteQueryFunc(body *writer.CodeWriter, config *config.Config, query model.Query, indent int) { + cursorType := sb.moduleName + ".Cursor" + var annotation, docRetType string + switch query.Cmd { + case metadata.CmdExec: + annotation, docRetType = query.Returns.Type.Print(), "" + case metadata.CmdExecResult: + annotation, docRetType = cursorType, cursorType + case metadata.CmdExecRows, metadata.CmdExecLastId: + annotation, docRetType = query.Returns.Type.Print(), query.Returns.Type.Type + case metadata.CmdOne: + annotation, docRetType = query.Returns.Type.PrintOptional(), query.Returns.Type.Type + case metadata.CmdMany: + annotation, docRetType = "QueryResults["+query.Returns.Type.Print()+"]", query.Returns.Type.Print() + } + + conn := writeFuncSignature(body, sb, config, indent, query, annotation) + + indent++ + writeQueryDocstring(body, sb, config, query, indent, docRetType) + + // stmt builds the execute-statement head/tail with the correct await + // wrapping for the async driver: accessing an attribute or method of the + // cursor requires parenthesizing the awaited execute call. + stmt := func(prefix, attribute string) (string, string) { + base := fmt.Sprintf("%s.execute(%s", conn, query.ConstantName) + switch { + case !sb.async: + return prefix + base, ")" + attribute + case attribute == "": + return prefix + "await " + base, ")" + default: + return prefix + "(await " + base, "))" + attribute + } + } + + switch query.Cmd { + case metadata.CmdExec: + head, tail := stmt("", "") + writeSqliteCall(body, indent, query, head, tail) + + case metadata.CmdExecResult: + head, tail := stmt("return ", "") + writeSqliteCall(body, indent, query, head, tail) + + case metadata.CmdExecRows: + head, tail := stmt("return ", ".rowcount") + writeSqliteCall(body, indent, query, head, tail) + + case metadata.CmdExecLastId: + head, tail := stmt("return ", ".lastrowid") + writeSqliteCall(body, indent, query, head, tail) + + case metadata.CmdOne: + prefix := "row = " + if sb.async { + // aiosqlite's fetchone is itself a coroutine. + prefix = "row = await " + } + head, tail := stmt(prefix, ".fetchone()") + writeSqliteCall(body, indent, query, head, tail) + body.WriteIndentedLine(indent, "if row is None:") + body.WriteIndentedLine(indent+1, "return None") + + if query.Returns.IsStruct() { + sb.rows.WriteStructReturn(body, indent, query.Returns) + } else { + sb.rows.WriteScalarReturn(body, indent, query.Returns) + } + + case metadata.CmdMany: + decodeHook := sb.rows.WriteDecodeHook(body, indent, query, sqliteResultType) + manyArgs := append([]string{conn, query.ConstantName, decodeHook}, expandParams(query)...) + // Deliberately unsubscripted: QueryResults[T](...) would go through + // typing's _GenericAlias.__call__ on every invocation (~10x call + // overhead) for zero benefit - the return annotation carries the type. + body.WriteWrappedCall(indent, "return QueryResults(", manyArgs, ")") + } +} + +// writeSqliteCall writes stmtHead+argsSegment+stmtTail on one line, hoisting a +// too-long parameter tuple into a local _args variable first so the statement +// stays within the line limit. +func writeSqliteCall(body *writer.CodeWriter, indent int, query model.Query, stmtHead, stmtTail string) { + parts := expandParams(query) + segment := "" + switch { + case len(parts) == 1: + segment = fmt.Sprintf(", (%s,)", parts[0]) + case len(parts) > 1: + segment = fmt.Sprintf(", (%s)", strings.Join(parts, ", ")) + } + + stmt := stmtHead + segment + stmtTail + if body.FitsLine(indent, stmt) { + body.WriteIndentedLine(indent, stmt) + + return + } + + body.WriteIndentedLine(indent, "sql_args = (") + for _, part := range parts { + body.WriteIndentedLine(indent+1, part+",") + } + body.WriteIndentedLine(indent, ")") + body.WriteIndentedLine(indent, stmtHead+", sql_args"+stmtTail) +} diff --git a/internal/gen.go b/internal/gen.go deleted file mode 100644 index fda62d21..00000000 --- a/internal/gen.go +++ /dev/null @@ -1,175 +0,0 @@ -package internal - -import ( - "context" - "encoding/json" - "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/codegen" - "github.com/rayakame/sqlc-gen-better-python/internal/core" - "github.com/rayakame/sqlc-gen-better-python/internal/log" - "github.com/rayakame/sqlc-gen-better-python/internal/types" - "github.com/sqlc-dev/plugin-sdk-go/plugin" - "strings" -) - -type PythonGenerator struct { - req *plugin.GenerateRequest - config *core.Config - - typeConversionFunc types.TypeConversionFunc - sqlDriver *codegen.Driver -} - -func NewPythonGenerator(req *plugin.GenerateRequest) (*PythonGenerator, error) { - config, err := core.ParseConfig(req) - if err != nil { - return nil, err - } - if err = core.ValidateConf(config, req.Settings.Engine); err != nil { - return nil, err - } - var typeConversionFunc types.TypeConversionFunc - switch req.Settings.Engine { - case "postgresql": - typeConversionFunc = types.PostgresTypeToPython - case "sqlite": - typeConversionFunc = types.SqliteTypeToPython - default: - return nil, fmt.Errorf("engine %q is not supported", req.Settings.Engine) - } - - sqlDriver, err := codegen.NewDriver(config) - if err != nil { - return nil, err - } - - return &PythonGenerator{ - req: req, - config: config, - typeConversionFunc: typeConversionFunc, - sqlDriver: sqlDriver, - }, nil -} - -func (gen *PythonGenerator) Run() (*plugin.GenerateResponse, error) { - outputFiles := make([]*plugin.File, 0) - log.GlobalLogger.LogByte(gen.req.PluginOptions) - enums := gen.buildEnums() - tables := gen.buildTables() - queries, err := gen.buildQueries(tables) - if err != nil { - return nil, err - } - - jsonData, _ := json.Marshal(gen.req) - log.GlobalLogger.LogByte(jsonData) - jsonData, _ = json.Marshal(gen.config) - log.GlobalLogger.LogByte(jsonData) - jsonData, _ = json.Marshal(enums) - log.GlobalLogger.LogByte(jsonData) - jsonData, _ = json.Marshal(tables) - log.GlobalLogger.LogByte(jsonData) - jsonData, _ = json.Marshal(queries) - log.GlobalLogger.LogByte(jsonData) - - if gen.config.OmitUnusedModels { - enums, tables = filterUnusedStructs(enums, tables, queries) - } - if err := gen.validate(enums, tables); err != nil { - return nil, err - } - importer := core.Importer{ - Tables: tables, - Queries: queries, - Enums: enums, - C: gen.config, - } - if file, err := gen.sqlDriver.BuildPyTablesFile(&importer, tables); err != nil { - return nil, err - } else { - outputFiles = append(outputFiles, file) - } - if files, err := gen.sqlDriver.BuildPyQueriesFiles(&importer, queries); err != nil { - return nil, err - } else { - outputFiles = append(outputFiles, files...) - } - if *gen.config.EmitInitFile { - outputFiles = append(outputFiles, gen.sqlDriver.BuildInitFile()) - } - jsonData, _ = json.Marshal(outputFiles) - log.GlobalLogger.LogByte(jsonData) - if gen.config.Debug { - fileName, fileContent := log.GlobalLogger.Print() - outputFiles = append(outputFiles, &plugin.File{ - Name: fileName, - Contents: fileContent, - }) - } - return &plugin.GenerateResponse{Files: outputFiles}, nil -} - -func Generate(_ context.Context, req *plugin.GenerateRequest) (*plugin.GenerateResponse, error) { - pythonGenerator, err := NewPythonGenerator(req) - if err != nil { - return nil, err - } - return pythonGenerator.Run() -} - -func (gen *PythonGenerator) validate(enums []core.Enum, structs []core.Table) error { - enumNames := make(map[string]struct{}) - for _, enum := range enums { - enumNames[enum.Name] = struct{}{} - enumNames["Null"+enum.Name] = struct{}{} - } - structNames := make(map[string]struct{}) - for _, struckt := range structs { - if _, ok := enumNames[struckt.Name]; ok { - return fmt.Errorf("struct name conflicts with enum name: %s", struckt.Name) - } - structNames[struckt.Name] = struct{}{} - } - return nil -} - -func filterUnusedStructs(enums []core.Enum, tables []core.Table, queries []core.Query) ([]core.Enum, []core.Table) { - keepTypes := make(map[string]struct{}) - - for _, query := range queries { - for _, arg := range query.Args { - if !arg.IsEmpty() { - keepTypes[arg.Type()] = struct{}{} - } - } - if query.HasRetType() { - keepTypes[query.Ret.Type()] = struct{}{} - if query.Ret.IsStruct() { - for _, field := range query.Ret.Table.Columns { - keepTypes[strings.ReplaceAll(field.Type.Type, "models.", "")] = struct{}{} - for _, embedField := range field.EmbedFields { - keepTypes[strings.ReplaceAll(embedField.Type.Type, "models.", "")] = struct{}{} - } - } - } - } - } - - keepEnums := make([]core.Enum, 0, len(enums)) - for _, enum := range enums { - _, keep := keepTypes[enum.Name] - _, keepNull := keepTypes["Null"+enum.Name] - if keep || keepNull { - keepEnums = append(keepEnums, enum) - } - } - - keepStructs := make([]core.Table, 0, len(tables)) - for _, st := range tables { - if _, ok := keepTypes[st.Name]; ok { - keepStructs = append(keepStructs, st) - } - } - - return keepEnums, keepStructs -} diff --git a/internal/handler.go b/internal/handler.go new file mode 100644 index 00000000..ed5650ee --- /dev/null +++ b/internal/handler.go @@ -0,0 +1,55 @@ +package internal + +import ( + "context" + "fmt" + + configPackage "github.com/rayakame/sqlc-gen-better-python/internal/config" + driverPackage "github.com/rayakame/sqlc-gen-better-python/internal/driver" + "github.com/rayakame/sqlc-gen-better-python/internal/log" + "github.com/rayakame/sqlc-gen-better-python/internal/render" + "github.com/rayakame/sqlc-gen-better-python/internal/transform" + "github.com/rayakame/sqlc-gen-better-python/internal/types" + "github.com/sqlc-dev/plugin-sdk-go/plugin" +) + +func Handler(_ context.Context, req *plugin.GenerateRequest) (*plugin.GenerateResponse, error) { + config, err := configPackage.NewConfig(req) + if err != nil { + return nil, fmt.Errorf("error trying to parse config: %w", err) + } + + typeConversionFunc, err := types.GetTypeConversionFunc(req.Settings.Engine) + if err != nil { + return nil, fmt.Errorf("error trying to parse config: %w", err) + } + + driver, err := driverPackage.New(config) + if err != nil { + return nil, fmt.Errorf("error trying to parse config: %w", err) + } + + transformer := transform.NewTransformer(config, req, typeConversionFunc) + enums := transformer.BuildEnums() + tables := transformer.BuildTables() + queries := transformer.BuildQueries(tables) + + if config.OmitUnusedModels { + enums, tables = transform.FilterUnusedModels(enums, tables, queries) + } + + renderer := render.New(config, driver) + outputFiles, err := renderer.RenderAll(enums, tables, queries) + if err != nil { + return nil, fmt.Errorf("error building queries: %w", err) + } + if config.Debug { + fileName, fileContent := log.L().Export() + outputFiles = append(outputFiles, &plugin.File{ + Name: fileName, + Contents: fileContent, + }) + } + + return &plugin.GenerateResponse{Files: outputFiles}, nil +} diff --git a/internal/log/logger.go b/internal/log/logger.go index b672da14..bee7924b 100644 --- a/internal/log/logger.go +++ b/internal/log/logger.go @@ -1,20 +1,70 @@ package log +import ( + "encoding/json" + "fmt" + "sync" + + "github.com/rayakame/sqlc-gen-better-python/internal/utils" +) + +var ( + loggingInstance *Logger + loggingOnce sync.Once +) + type Logger struct { messages []string } +type logMessage struct { + Message string `json:"message"` +} + +type errMessage struct { + Error string `json:"error"` +} + +func L() *Logger { + loggingOnce.Do(func() { + loggingInstance = utils.ToPtr(Logger{}) + }) + + return loggingInstance +} + +func (logger *Logger) LogErr(message string, err error) { + msg := errMessage{Error: fmt.Sprintf("%s: %v", message, err)} + logger.LogAny(msg) +} func (logger *Logger) Log(message string) { - logger.messages = append(logger.messages, message) + msg := logMessage{Message: message} + logger.LogAny(msg) } -func (logger *Logger) LogByte(message []byte) { - logger.messages = append(logger.messages, string(message)) + +func (logger *Logger) LogAny(message any) { + jsonData, err := json.Marshal(message) + if err != nil { + logger.log(fmt.Sprintf(`{"error": "Error while trying to log any: %v"}`, err)) + } else { + logger.log(string(jsonData)) + } } -func (logger *Logger) Print() (string, []byte) { - var loggedMessages string - for _, message := range logger.messages { - loggedMessages += message + "\n" +func (logger *Logger) Export() (string, []byte) { + loggedMessages := "[\n" + for i, message := range logger.messages { + if i == len(logger.messages)-1 { + loggedMessages += message + "\n" + } else { + loggedMessages += message + ",\n" + } } - return "log.txt", []byte(loggedMessages) + loggedMessages += "]" + + return "log.json", []byte(loggedMessages) +} + +func (logger *Logger) log(data string) { + logger.messages = append(logger.messages, data) } diff --git a/internal/log/main.go b/internal/log/main.go deleted file mode 100644 index f3b31f07..00000000 --- a/internal/log/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package log - -var GlobalLogger Logger - -func init() { - GlobalLogger = Logger{} -} diff --git a/internal/model/naming.go b/internal/model/naming.go new file mode 100644 index 00000000..0df8e7b7 --- /dev/null +++ b/internal/model/naming.go @@ -0,0 +1,169 @@ +package model + +import ( + "fmt" + "strings" + "unicode" + "unicode/utf8" + + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/sqlc-dev/plugin-sdk-go/plugin" + "golang.org/x/text/cases" + "golang.org/x/text/language" +) + +func SnakeToCamel(conf *config.Config, s string) string { + out := "" + s = strings.Map(func(r rune) rune { + if unicode.IsLetter(r) { + return r + } + if unicode.IsDigit(r) { + return r + } + + return rune('_') + }, s) + for _, p := range strings.Split(s, "_") { + if _, found := conf.InitialismsMap[p]; found { + out += strings.ToUpper(p) + } else { + out += cases.Title(language.Und, cases.NoLower).String(p) + } + } + r, _ := utf8.DecodeRuneInString(out) + if unicode.IsDigit(r) { + return "_" + out + } else { + return out + } +} + +func UpperSnakeCase(s string) string { + result := "" + for i, r := range s { + if unicode.IsUpper(r) && i != 0 { + result += "_" + string(r) + } else { + result += string(r) + } + } + result = strings.ToUpper(result) + + return result +} + +func ColumnName(pluginColumn *plugin.Column, pos int) string { + if pluginColumn.Name != "" { + return pluginColumn.Name + } + + return fmt.Sprintf("column_%d", pos+1) +} + +func EscapedColumnName(pluginColumn *plugin.Column, pos int) string { + return Escape(ColumnName(pluginColumn, pos)) +} + +// ModelName builds the class name for a table. Singularization runs on the +// raw snake_case table name (before camel-casing) so that +// inflection_exclude_table_names entries, which users write in snake_case, +// match correctly. For non-default-schema tables exclusions match BOTH the +// bare table name ("events") and the schema-qualified form +// ("analytics_events") - v0.4.x singularized the qualified string, so +// existing configs use the qualified spelling. +func ModelName(config *config.Config, modelName string, schemaName string) string { + if !config.EmitExactTableNames && !inflectionExcluded(config, modelName, schemaName) { + modelName = Singular(SingularParams{ + Name: modelName, + Exclusions: nil, + }) + } + + return qualifiedClassName(config, modelName, schemaName) +} + +// inflectionExcluded reports whether the table name is excluded from +// singularization, matching the bare or schema-qualified form. +func inflectionExcluded(config *config.Config, modelName, schemaName string) bool { + qualified := modelName + if schemaName != "" { + qualified = schemaName + "_" + modelName + } + for _, exclusion := range config.InflectionExcludeTableNames { + if strings.EqualFold(exclusion, modelName) || strings.EqualFold(exclusion, qualified) { + return true + } + } + + return false +} + +// EnumName builds the class name for a SQL enum. Enum type names are never +// singularized - they are type names, not table names. +func EnumName(config *config.Config, enumName string, schemaName string) string { + return qualifiedClassName(config, enumName, schemaName) +} + +func qualifiedClassName(config *config.Config, name, schemaName string) string { + if schemaName != "" { + name = schemaName + "_" + name + } + + return SnakeToCamel(config, name) +} + +// EnumConstantName converts an enum value into a valid, unique Python constant +// name: non-alphanumeric characters become underscores, empty results fall +// back to VALUE_N, digit-leading names get an underscore prefix, and +// duplicates get a numeric suffix. seen tracks names across one enum. +func EnumConstantName(value string, index int, seen map[string]int) string { + var builder strings.Builder + for _, r := range value { + if unicode.IsLetter(r) || unicode.IsDigit(r) { + builder.WriteRune(unicode.ToUpper(r)) + } else { + builder.WriteRune('_') + } + } + name := builder.String() + + if strings.Trim(name, "_") == "" { + name = fmt.Sprintf("VALUE_%d", index+1) + } + if r, _ := utf8.DecodeRuneInString(name); unicode.IsDigit(r) { + name = "_" + name + } + + return DedupName(name, seen) +} + +// DedupName makes repeated Python identifiers unique by appending a numeric +// suffix ("name", "name_2", "name_3", ...). Suffixes are probed until an +// unused identifier is found, so a literal "name_2" that appeared earlier can +// never collide with a generated one. seen tracks usage counts per scope. +func DedupName(name string, seen map[string]int) string { + seen[name]++ + if seen[name] == 1 { + return name + } + for i := seen[name]; ; i++ { + candidate := fmt.Sprintf("%s_%d", name, i) + if seen[candidate] == 0 { + seen[candidate]++ + + return candidate + } + } +} + +func ParamName(p *plugin.Parameter) string { + var name string + if p.Column.GetName() != "" { + name = p.Column.Name + } else { + name = fmt.Sprintf("dollar_%d", p.GetNumber()) + } + + return Escape(name) +} diff --git a/internal/core/reserved.go b/internal/model/reserved.go similarity index 94% rename from internal/core/reserved.go rename to internal/model/reserved.go index 74f16777..dd776ac0 100644 --- a/internal/core/reserved.go +++ b/internal/model/reserved.go @@ -1,11 +1,12 @@ -// Package core Auto-generated using python; DO NOT EDIT +// Package model Auto-generated using python; DO NOT EDIT // py 3.13.1 (tags/v3.13.1:0671451, Dec 3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] -package core +package model func Escape(s string) string { if IsReserved(s) { return s + "_" } + return s } diff --git a/internal/inflection/singular.go b/internal/model/singular.go similarity index 98% rename from internal/inflection/singular.go rename to internal/model/singular.go index 64e042a6..ce9e0ac9 100644 --- a/internal/inflection/singular.go +++ b/internal/model/singular.go @@ -1,4 +1,4 @@ -package inflection +package model import ( "strings" diff --git a/internal/model/types.go b/internal/model/types.go new file mode 100644 index 00000000..81a02b38 --- /dev/null +++ b/internal/model/types.go @@ -0,0 +1,121 @@ +package model + +import ( + "fmt" + + "github.com/sqlc-dev/plugin-sdk-go/plugin" +) + +type PyType struct { + SQLType string + Type string + IsNullable bool + IsList bool + IsEnum bool + + // IsOverride marks a type replaced via the overrides config option. + IsOverride bool + // DefaultType is the Python type the column would have without the + // override. Used to convert override values before passing them to the driver. + DefaultType string +} + +func (t PyType) Print() string { + type_ := t.Type + if t.IsList { + type_ = fmt.Sprintf("collections.abc.Sequence[%s]", type_) + } + if t.IsNullable { + type_ += " | None" + } + return type_ +} + +// PrintOptional prints the type with a guaranteed "| None" suffix for values +// that may be absent at runtime (e.g. :one queries that match no row). +func (t PyType) PrintOptional() string { + if t.IsNullable { + return t.Print() + } + + return t.Print() + " | None" +} + +// DoOverride reports whether this type has an active override. +func (t PyType) DoOverride() bool { + return t.IsOverride +} + +type Enum struct { + Name string + Constants []EnumConstants +} + +type EnumConstants struct { + Name string + Value string +} + +type Table struct { + Name string + Columns []Column + + Identifier *plugin.Identifier +} + +type Column struct { + Name string // The escaped Python attribute name + DBName string // The raw database column name + Type PyType + + Embed *Embed +} + +type Query struct { + Cmd string // The command of the query: https://docs.sqlc.dev/en/latest/reference/query-annotations.html + SQL string // The raw SQL of the query + ConstantName string // The name of the constant where the raw SQL will be saved in python + FuncName string // The name of the python function + QueryName string // The original name of the query + FileName string // The original filename where the query is located + ModuleName string // The name of the python module in which the query will be implemented + + Params []QueryValue + Returns QueryValue + + Table *plugin.Identifier // The name of the table this query inserts into. Only used for :copyfrom +} + +func (q Query) EmitsTable() bool { + if q.Returns.EmitTable { + return true + } + for _, param := range q.Params { + if param.EmitTable { + return true + } + } + return false +} + +type QueryValue struct { + EmitTable bool + Table *Table + Name string + Type PyType +} + +type Embed struct { + ModelName string + Columns []Column +} + +// IsEmpty reports whether this value is unset. +func (v QueryValue) IsEmpty() bool { + return v.Type.Type == "" && v.Name == "" && v.Table == nil +} + +// IsStruct reports whether this value is a structured type (table reference). +func (v QueryValue) IsStruct() bool { + return v.Table != nil +} diff --git a/internal/render/enums.go b/internal/render/enums.go new file mode 100644 index 00000000..4b1f0000 --- /dev/null +++ b/internal/render/enums.go @@ -0,0 +1,51 @@ +package render + +import ( + "fmt" + "strconv" + + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/sqlc-dev/plugin-sdk-go/plugin" +) + +const enumFileName = "enums.py" + +func (r *Renderer) renderEnums(enums []model.Enum) *plugin.File { + fileBody := r.getCodeWriter() + fileBody.WriteSqlcHeader(nil) + fileBody.WriteEnumsFileModuleDocstring() + fileBody.WriteFutureImport() + + all := make([]string, len(enums)) + for i, enum := range enums { + all[i] = enum.Name + } + fileBody.WriteAll(all) + fileBody.NewLine() + + r.importResolver.EnumImports().Write(fileBody, r.config.OmitTypecheckingBlock, nil) + + for _, enum := range enums { + fileBody.NNewLine(2) + fileBody.WriteLine(fmt.Sprintf("class %s(enum.StrEnum):", enum.Name)) + fileBody.WriteEnumClassDocstring(enum.Name) + for _, constant := range enum.Constants { + fileBody.WriteIndentedLine(1, fmt.Sprintf(`%s = "%s"`, constant.Name, escapePyString(constant.Value))) + } + } + + return &plugin.File{ + Name: enumFileName, + Contents: fileBody.Bytes(), + } +} + +// escapePyString escapes a value for embedding in a double-quoted Python +// string literal, covering backslashes, quotes, and control characters. +// Go's Quote escaping (\", \\, \n, \t, \xNN, \uNNNN, ...) is a compatible +// subset of Python's string-literal escapes. +func escapePyString(value string) string { + quoted := strconv.Quote(value) + + return quoted[1 : len(quoted)-1] +} diff --git a/internal/render/imports.go b/internal/render/imports.go new file mode 100644 index 00000000..a24b6f10 --- /dev/null +++ b/internal/render/imports.go @@ -0,0 +1,685 @@ +package render + +import ( + "fmt" + "slices" + "sort" + "strings" + + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/driver" + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/writer" + "github.com/sqlc-dev/plugin-sdk-go/metadata" +) + +type ImportResult struct { + Std []string // Standard library imports (e.g., "import typing"). + TypeChecking []string // Imports inside "if TYPE_CHECKING:" block. + Package []string // Local package imports (e.g., "from mypackage import models"). +} + +func (r ImportResult) Write(body *writer.CodeWriter, omitTypeChecking bool, typeCheckingLines []string) { + if omitTypeChecking { + // Everything is emitted at module level. The TypeChecking slice can + // carry statements besides imports (the QueryResultsArgsType alias); + // those and the hook lines must follow ALL imports, otherwise the + // imports after them violate E402. + var statements []string + for _, line := range append(append([]string{}, r.Std...), r.TypeChecking...) { + trimmed := strings.TrimSpace(line) + if strings.HasPrefix(trimmed, "import ") || strings.HasPrefix(trimmed, "from ") { + body.WriteLine(line) + } else if trimmed != "" { + statements = append(statements, trimmed) + } + } + for i, line := range r.Package { + if i == 0 { + body.NewLine() + } + body.WriteLine(line) + } + for _, line := range append(statements, typeCheckingLines...) { + body.NewLine() + body.WriteLine(line) + } + + return + } + + for _, line := range r.Std { + body.WriteLine(line) + } + if len(r.Std) != 0 && len(r.TypeChecking) != 0 { + body.NewLine() + } + indentLevel := 0 + if len(r.TypeChecking) != 0 || len(typeCheckingLines) != 0 { + body.WriteLine("if typing.TYPE_CHECKING:") + indentLevel = 1 + } + for _, line := range r.TypeChecking { + body.WriteIndentedLine(indentLevel, line) + } + for i, line := range typeCheckingLines { + if i == 0 && len(r.TypeChecking) != 0 { + body.NewLine() + } + body.WriteIndentedLine(indentLevel, line) + } + for i, line := range r.Package { + if i == 0 { + body.NewLine() + } + body.WriteLine(line) + } +} + +// ImportResolver computes Python import statements for generated files. +// It is stateless - all data is passed as arguments. +type ImportResolver struct { + conf *config.Config + drv driver.Driver +} + +// NewImportResolver creates a new ImportResolver. +func NewImportResolver(conf *config.Config, drv driver.Driver) *ImportResolver { + return &ImportResolver{conf: conf, drv: drv} +} + +type importSpec struct { + Module string + Name string + Alias string + TypeChecking bool +} + +func (s importSpec) String() string { + if s.Alias != "" { + if s.Name == "" { + return fmt.Sprintf("import %s as %s", s.Module, s.Alias) + } + + return fmt.Sprintf("from %s import %s as %s", s.Module, s.Name, s.Alias) + } + if s.Name == "" { + return "import " + s.Module + } + + return fmt.Sprintf("from %s import %s", s.Module, s.Name) +} + +func (r *ImportResolver) ModelImports(tables []model.Table) ImportResult { + // "uses" checks whether any table column has a given Python type. + uses := func(name string) (bool, bool) { + for _, table := range tables { + for _, col := range table.Columns { + if col.Type.Type == name { + return true, true + } + } + } + + return false, false + } + + // Scan enum/list usage in a dedicated pass: the uses closure early-returns + // on the first type match, so side-effect flags inside it would miss + // columns positioned after a match. + usesEnum := false + hasList := false + for _, table := range tables { + for _, col := range table.Columns { + if col.Type.IsEnum { + usesEnum = true + } + if col.Type.IsList { + hasList = true + } + } + } + + std := r.stdImports(uses) + r.addOverrideImports(std, uses) + r.forcePydanticRuntimeImports(std, hasList) + + std, typeChecking := splitTypeChecking(std) + + // An empty models.py (all tables filtered) defines no classes, so the + // model-library import would be unused. + if len(tables) > 0 { + r.addModelImport(std) + } + + local := make(map[string]importSpec) + if usesEnum { + if r.conf.ModelType == config.ModelTypePydantic { + // pydantic evaluates field annotations when building schemas. + local["enum"] = importSpec{Module: r.conf.Package, Name: "enums", Alias: "", TypeChecking: false} + } else { + typeChecking["enums"] = importSpec{Module: r.conf.Package, Name: "enums", Alias: "", TypeChecking: true} + } + } + if r.conf.ModelType == config.ModelTypePydantic && len(typeChecking) == 0 { + // Without a TYPE_CHECKING block, typing itself is unused in models.py. + delete(std, "typing") + } + if r.conf.OmitTypecheckingBlock { + // No TYPE_CHECKING guard is emitted; typing is then only referenced + // when a column falls back to the typing.Any annotation. + if used, _ := uses("typing.Any"); !used { + delete(std, "typing") + } + } + + return buildResult(std, typeChecking, local) +} + +func (r *ImportResolver) QueryImports(queries []model.Query) ImportResult { + // "uses" checks whether any query arg/return uses a given Python type. + // Returns (isUsed, goesInTypeChecking). + uses := func(name string) (bool, bool) { + var bestUsed, bestTC *bool + + update := func(used, tc bool) { + if bestUsed == nil { + bestUsed = &used + bestTC = &tc + } else if *bestTC { + // Runtime import (tc=false) takes priority over TYPE_CHECKING. + *bestUsed = used + *bestTC = tc + } + } + + for _, query := range queries { + if used, tc := r.queryValueUses(name, query.Returns); used { + update(used, tc) + } + for _, arg := range query.Params { + if used, tc := r.queryValueUses(name, arg); used { + update(used, tc) + } + // Overridden params are converted back to their DefaultType at + // runtime (e.g. "decimal.Decimal(params.rating)"), so that + // type's module must be imported at runtime too. + if overrideDefaultTypeUses(name, arg) { + update(true, false) + } + } + } + + if bestUsed == nil { + return false, false + } + return *bestUsed, *bestTC + } + + emitsModels, hasListField := emittedModelFields(queries) + + std := r.stdImports(uses) + r.addOverrideImports(std, uses) + // pydantic evaluates FIELD annotations of emitted Params/Row classes at + // class-build time; plain function annotations stay lazy strings, so + // modules without emitted classes need no runtime forcing. + if emitsModels { + r.forcePydanticRuntimeImports(std, hasListField) + } + + std, typeChecking := splitTypeChecking(std) + + // The conversion usage decides the runtime imports below by mirroring + // exactly what WriteConversionSetup emits: the sqlite module itself + // (register_adapter/register_converter run at import time), the modules + // referenced by adapter registrations and converter bodies, and ciso8601 + // (referenced only inside speedups converter bodies). + var conversions driver.SqliteConversionUsage + if r.conf.SqlDriver == config.SQLDriverAioSQLite || r.conf.SqlDriver == config.SQLDriverSQLite { + conversions = driver.SqliteConversionsUsed(queries) + } + r.addDriverImports(std, typeChecking, queries, conversions) + + for module := range conversions.RuntimeModules(r.conf.Speedups) { + spec, ok := typeChecking[module] + if !ok { + spec, ok = std[module] + if !ok { + spec = importSpec{Module: module} + } + } + delete(typeChecking, module) + spec.TypeChecking = false + std[module] = spec + } + + if r.conf.Speedups && conversions.SpeedupConverterUsed() { + std["ciso8601"] = importSpec{Module: "ciso8601"} + } + + // Model import if any query emits a struct or uses copyfrom. + for _, query := range queries { + if (query.EmitsTable()) || query.Cmd == metadata.CmdCopyFrom { + r.addModelImport(std) + break + } + } + + // Only import models/enums when THIS module's queries actually reference + // them - a global flag would emit unused imports in multi-file projects. + // Overridden enum PARAMS count too: their annotation is the override type, + // but convertParamExpr emits an "enums.X(arg)" call at runtime. Overridden + // enum RETURNS don't - they convert via the override type only. + local := map[string]importSpec{} + if anyQueryType(queries, func(typ model.PyType) bool { return strings.HasPrefix(typ.Type, "models.") }) { + local["models"] = importSpec{Module: r.conf.Package, Name: "models"} + } + usesEnums := anyQueryType(queries, func(typ model.PyType) bool { + return typ.IsEnum || strings.HasPrefix(typ.Type, "enums.") + }) || anyParamType(queries, func(typ model.PyType) bool { + return typ.DoOverride() && strings.HasPrefix(typ.DefaultType, "enums.") + }) + if usesEnums { + local["enums"] = importSpec{Module: r.conf.Package, Name: "enums"} + } + + return r.buildQueryResult(std, typeChecking, local, queries) +} + +// queryValueMatches reports whether pred matches any Python type in the query +// value: the scalar type, row/params class columns, embed field types, and +// embed columns. +func queryValueMatches(qv model.QueryValue, pred func(model.PyType) bool) bool { + if qv.IsEmpty() { + return false + } + if pred(qv.Type) { + return true + } + if qv.Table == nil { + return false + } + for _, col := range qv.Table.Columns { + if pred(col.Type) { + return true + } + if col.Embed != nil { + for _, embedColumn := range col.Embed.Columns { + if pred(embedColumn.Type) { + return true + } + } + } + } + + return false +} + +// anyQueryType reports whether pred matches any Python type used by the +// queries, in both returns and parameters. +func anyQueryType(queries []model.Query, pred func(model.PyType) bool) bool { + for _, query := range queries { + if queryValueMatches(query.Returns, pred) { + return true + } + for _, param := range query.Params { + if queryValueMatches(param, pred) { + return true + } + } + } + + return false +} + +// emittedModelFields reports whether the module emits Params/Row model +// classes and whether any of their FIELDS (embed fields included) is a list +// type. Only class fields matter for pydantic's runtime annotation +// evaluation - the bundle value itself being a list (:copyfrom) does not. +func emittedModelFields(queries []model.Query) (bool, bool) { + var emitsModels, hasListField bool + check := func(qv model.QueryValue) { + if qv.Table == nil || !qv.EmitTable { + return + } + emitsModels = true + for _, col := range qv.Table.Columns { + if col.Type.IsList { + hasListField = true + } + if col.Embed != nil { + for _, embedColumn := range col.Embed.Columns { + if embedColumn.Type.IsList { + hasListField = true + } + } + } + } + } + for _, query := range queries { + check(query.Returns) + for _, param := range query.Params { + check(param) + } + } + + return emitsModels, hasListField +} + +// anyParamType is anyQueryType restricted to query parameters - for imports +// that only the runtime parameter conversion needs. +func anyParamType(queries []model.Query, pred func(model.PyType) bool) bool { + for _, query := range queries { + for _, param := range query.Params { + if queryValueMatches(param, pred) { + return true + } + } + } + + return false +} + +func (r *ImportResolver) EnumImports() ImportResult { + uses := func(name string) (bool, bool) { + return false, false + } + std := r.stdImports(uses) + std["enum"] = importSpec{Module: "enum", Name: "", Alias: "", TypeChecking: false} + if r.conf.OmitTypecheckingBlock { + // enums.py references typing only for the TYPE_CHECKING guard. + delete(std, "typing") + } + std, typeChecking := splitTypeChecking(std) + + return buildResult(std, typeChecking, nil) +} + +// forcePydanticRuntimeImports moves every type import to runtime for pydantic +// models: pydantic resolves field annotations when building the model schema, +// so TYPE_CHECKING-only imports would rely on pydantic's (version-dependent) +// TYPE_CHECKING-block resolution instead of plain module imports. +// collections.abc is only needed at runtime when a list field exists. +func (r *ImportResolver) forcePydanticRuntimeImports(std map[string]importSpec, hasListColumns bool) { + if r.conf.ModelType != config.ModelTypePydantic { + return + } + for key, spec := range std { + if key == "collections" && !hasListColumns { + continue + } + spec.TypeChecking = false + std[key] = spec + } +} + +// overrideDefaultTypeUses reports whether the query value contains an overridden +// type whose DefaultType is `name` - those are converted back to DefaultType at +// runtime when passed to the driver (see driver.convertParamExpr). +func overrideDefaultTypeUses(name string, qv model.QueryValue) bool { + if qv.IsEmpty() { + return false + } + if qv.IsStruct() { + for _, col := range qv.Table.Columns { + if col.Type.DoOverride() && col.Type.DefaultType == name { + return true + } + } + + return false + } + + return qv.Type.DoOverride() && qv.Type.DefaultType == name +} + +// addOverrideImports adds imports contributed by configured type overrides. +func (r *ImportResolver) addOverrideImports(std map[string]importSpec, uses func(string) (bool, bool)) { + for _, override := range r.conf.Overrides { + if override.PyType.Type == "" || override.PyType.Import == "" { + continue + } + if used, tc := uses(override.PyType.Type); used { + addWithPriority(std, override.PyType.Type, importSpec{ + Module: override.PyType.Import, Name: override.PyType.Package, Alias: "", TypeChecking: tc, + }) + } + } +} + +// addDriverImports adds driver-specific imports to the std/typeChecking maps. +// conversions is only meaningful for the sqlite drivers. +func (r *ImportResolver) addDriverImports( + std, typeChecking map[string]importSpec, + queries []model.Query, + conversions driver.SqliteConversionUsage, +) { + driverName := string(r.conf.SqlDriver) + hasMany := isAnyQueryMany(queries) + + switch r.conf.SqlDriver { + case config.SQLDriverAsyncpg: + typeChecking[driverName] = importSpec{Module: driverName} + if hasMany { + typeChecking[driverName+".cursor"] = importSpec{Module: driverName + ".cursor"} + if r.hasSimpleReturn(queries) { + std["operator"] = importSpec{Module: "operator"} + } + } + + case config.SQLDriverAioSQLite: + // register_adapter/register_converter calls need the module at runtime. + if conversions.Any() { + std[driverName] = importSpec{Module: driverName} + } else { + typeChecking[driverName] = importSpec{Module: driverName} + } + if hasMany { + typeChecking["sqlite3"] = importSpec{Module: "sqlite3"} + if r.hasSimpleReturn(queries) { + std["operator"] = importSpec{Module: "operator"} + } + } + + case config.SQLDriverSQLite: + if conversions.Any() { + std[driverName] = importSpec{Module: driverName} + } else { + typeChecking[driverName] = importSpec{Module: driverName} + } + if hasMany && r.hasSimpleReturn(queries) { + std["operator"] = importSpec{Module: "operator"} + } + } +} + +// hasSimpleReturn checks if any query has a non-struct return that doesn't need +// conversion. Must mirror RowBuilder.columnNeedsConversion: only these returns +// use operator.itemgetter instead of a _decode_hook. +func (r *ImportResolver) hasSimpleReturn(queries []model.Query) bool { + for _, query := range queries { + if query.Cmd != metadata.CmdMany { + continue + } + if query.Returns.IsStruct() || query.Returns.Type.IsEnum || query.Returns.Type.DoOverride() { + continue + } + if !r.drv.ConvertsInline(query.Returns.Type.SQLType) { + return true + } + } + return false +} + +func (r *ImportResolver) queryValueUses(name string, queryValue model.QueryValue) (bool, bool) { + if queryValue.IsEmpty() { + return false, false + } + + if queryValue.IsStruct() { + // Scan ALL columns (including embed columns): any occurrence that + // needs runtime conversion must force a runtime import, even when an + // earlier annotation-only occurrence of the same type exists. + used := false + typeChecking := true + check := func(typ model.PyType) { + if typ.Type != name { + return + } + used = true + if r.drv.ConvertsInline(typ.SQLType) || typ.DoOverride() { + typeChecking = false + } + } + for _, column := range queryValue.Table.Columns { + if column.Embed != nil { + for _, embedColumn := range column.Embed.Columns { + check(embedColumn.Type) + } + + continue + } + check(column.Type) + } + if !used { + return false, false + } + + return true, typeChecking + } + + if queryValue.Type.Type == name { + needsConv := r.drv.ConvertsInline(queryValue.Type.SQLType) || queryValue.Type.DoOverride() + return true, !needsConv + } + + return false, false +} + +func (r *ImportResolver) addModelImport(std map[string]importSpec) { + switch r.conf.ModelType { + case config.ModelTypeAttrs: + std["attrs"] = importSpec{Module: "attrs", Name: "", Alias: "", TypeChecking: false} + case config.ModelTypeDataclass: + std["dataclasses"] = importSpec{Module: "dataclasses", Name: "", Alias: "", TypeChecking: false} + case config.ModelTypeMsgspec: + std["msgspec"] = importSpec{Module: "msgspec", Name: "", Alias: "", TypeChecking: false} + case config.ModelTypePydantic: + std["pydantic"] = importSpec{Module: "pydantic", Name: "", Alias: "", TypeChecking: false} + } +} + +func buildResult(std, typeChecking, local map[string]importSpec) ImportResult { + return ImportResult{ + Std: buildImportBlock(std), + TypeChecking: buildImportBlock(typeChecking), + Package: buildImportBlock(local), + } +} + +// buildQueryResult is like buildResult but also appends QueryResultsArgsType. +func (r *ImportResolver) buildQueryResult(std, typeChecking, local map[string]importSpec, queries []model.Query) ImportResult { + result := buildResult(std, typeChecking, local) + + if isAnyQueryMany(queries) { + if len(result.TypeChecking) != 0 { + result.TypeChecking[len(result.TypeChecking)-1] += "\n" + } + members := "int | float | str | memoryview" + allSpecs := mergeMaps(std, typeChecking) + if _, ok := allSpecs["decimal"]; ok { + members += " | decimal.Decimal" + } + if _, ok := allSpecs["uuid"]; ok { + members += " | uuid.UUID" + } + if _, ok := allSpecs["datetime"]; ok { + members += " | datetime.date | datetime.time | datetime.datetime | datetime.timedelta" + } + // Array/sqlc.slice params are forwarded into QueryResults too, so the + // union needs a recursive Sequence member. The PEP 695 alias is lazy, + // so it is also safe at module level with omit_typechecking_block. + argsType := "type QueryResultsArgsType = " + members + + " | collections.abc.Sequence[QueryResultsArgsType] | None" + result.TypeChecking = append(result.TypeChecking, argsType) + } + + return result +} + +func buildImportBlock(specs map[string]importSpec) []string { + if len(specs) == 0 { + return nil + } + + lines := make([]string, 0, len(specs)) + for _, spec := range specs { + lines = append(lines, spec.String()) + } + + sort.Strings(lines) + + // Different specs can render to the same line (e.g. an override importing + // a module the std scan also imports) - drop exact duplicates. + return slices.Compact(lines) +} + +// stdImports returns the base set of standard library imports. +// The uses function should return if the type is used and if it is only +// used for typechecking or not. +func (r *ImportResolver) stdImports(uses func(string) (bool, bool)) map[string]importSpec { + std := map[string]importSpec{ + "collections": {Module: "collections.abc", TypeChecking: true, Name: "", Alias: ""}, + "typing": {Module: "typing", TypeChecking: false, Name: "", Alias: ""}, + } + + // Check which standard types are used. + for _, check := range []struct{ typeName, module string }{ + {"decimal.Decimal", "decimal"}, + {"datetime.date", "datetime"}, + {"datetime.time", "datetime"}, + {"datetime.datetime", "datetime"}, + {"datetime.timedelta", "datetime"}, + {"uuid.UUID", "uuid"}, + } { + if used, tc := uses(check.typeName); used { + addWithPriority(std, check.module, importSpec{Module: check.module, TypeChecking: tc, Name: "", Alias: ""}) + } + } + + return std +} + +// addWithPriority adds an import, but runtime imports (TypeChecking=false) +// take priority over TYPE_CHECKING imports. +func addWithPriority(m map[string]importSpec, key string, spec importSpec) { + if existing, ok := m[key]; ok && !existing.TypeChecking { + return // Existing runtime import has priority. + } + m[key] = spec +} + +// splitTypeChecking separates imports into runtime and TYPE_CHECKING groups. +func splitTypeChecking(specs map[string]importSpec) (map[string]importSpec, map[string]importSpec) { + runtime := make(map[string]importSpec) + typeChecking := make(map[string]importSpec) + for name, spec := range specs { + if spec.TypeChecking { + typeChecking[name] = spec + } else { + runtime[name] = spec + } + } + + return runtime, typeChecking +} + +func mergeMaps(maps ...map[string]importSpec) map[string]importSpec { + result := make(map[string]importSpec) + for _, m := range maps { + for k, v := range m { + result[k] = v + } + } + return result +} diff --git a/internal/render/queries.go b/internal/render/queries.go new file mode 100644 index 00000000..211620f5 --- /dev/null +++ b/internal/render/queries.go @@ -0,0 +1,113 @@ +package render + +import ( + "fmt" + "strings" + + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/utils" + "github.com/sqlc-dev/plugin-sdk-go/metadata" + "github.com/sqlc-dev/plugin-sdk-go/plugin" +) + +func (r *Renderer) renderQueriesModule(moduleName string, queries []model.Query) *plugin.File { + fileBody := r.getCodeWriter() + fileBody.WriteSqlcHeader(utils.ToPtr(queries[0])) + fileBody.WriteQueryFileModuleDocstring(queries[0].FileName) + fileBody.WriteFutureImport() + + tablesBody := r.getCodeWriter() + constantsBody := r.getCodeWriter() + functionsBody := r.getCodeWriter() + + all := make([]string, 0, len(queries)*2) //nolint:mnd + + indentLevel := 0 + newLines := 2 + + if isAnyQueryMany(queries) { + r.driver.WriteQueryResultsClass(functionsBody) + all = append(all, "QueryResults") + // In classes mode the Querier class follows directly; in functions + // mode each query already writes its own two leading blank lines. + if r.config.EmitClasses { + functionsBody.NNewLine(2) + } + } + + if r.config.EmitClasses { + newLines = 1 + indentLevel = 1 + className := model.SnakeToCamel(r.config, moduleName) + functionsBody.WriteLine(fmt.Sprintf("class %s:", className)) + functionsBody.WriteQueryClassDocstring(queries[0].FileName, r.driver.ConnType()) + functionsBody.WriteIndentedLine(1, `__slots__ = ("_conn",)`) + functionsBody.NewLine() + functionsBody.WriteIndentedLine(1, fmt.Sprintf(`def __init__(self, conn: %s) -> None:`, r.driver.ConnType())) + functionsBody.WriteQueryClassInitDocstring(2, r.driver.ConnType()) //nolint:mnd + functionsBody.WriteIndentedLine(2, "self._conn = conn") + functionsBody.NewLine() + functionsBody.WriteIndentedLine(1, "@property") + functionsBody.WriteIndentedLine(1, fmt.Sprintf(`def conn(self) -> %s:`, r.driver.ConnType())) + functionsBody.WriteQueryClassConnDocstring(r.driver.ConnType()) + functionsBody.WriteIndentedLine(2, `return self._conn`) + all = append(all, className) + } + + for _, query := range queries { + constantsBody.WriteLine( + fmt.Sprintf(`%s: typing.Final[str] = """-- name: %s %s`, query.ConstantName, query.QueryName, query.Cmd), + ) + constantsBody.WriteLine(query.SQL) + constantsBody.WriteLine(`"""`) + constantsBody.NewLine() + + if query.Returns.EmitTable { + r.renderTable(tablesBody, *query.Returns.Table) + all = append(all, query.Returns.Table.Name) + tablesBody.NNewLine(2) + } + + for _, param := range query.Params { + if !param.EmitTable { + continue + } + r.renderTable(tablesBody, *param.Table) + tablesBody.NNewLine(2) + all = append(all, param.Table.Name) + } + + if !r.config.EmitClasses { + all = append(all, query.FuncName) + } + functionsBody.NNewLine(newLines) + r.driver.WriteQueryFunc(functionsBody, r.config, query, indentLevel) + } + fileBody.WriteAll(all) + fileBody.NewLine() + r.importResolver.QueryImports(queries).Write(fileBody, r.config.OmitTypecheckingBlock, r.driver.TypeCheckingHook()) + fileBody.NNewLine(2) + conversionBody := r.getCodeWriter() + if r.driver.WriteConversionSetup(conversionBody, r.config, queries) { + fileBody.WriteString(conversionBody.String()) + fileBody.NNewLine(2) + } + fileBody.WriteString(tablesBody.String()) + fileBody.WriteString(constantsBody.String()) + fileBody.NewLine() + fileBody.WriteString(strings.TrimLeft(functionsBody.String(), "\n")) + + return &plugin.File{ + Name: moduleName + ".py", + Contents: fileBody.Bytes(), + } +} + +func isAnyQueryMany(queries []model.Query) bool { + for _, query := range queries { + if query.Cmd == metadata.CmdMany { + return true + } + } + return false +} diff --git a/internal/render/renderer.go b/internal/render/renderer.go new file mode 100644 index 00000000..368c10b1 --- /dev/null +++ b/internal/render/renderer.go @@ -0,0 +1,75 @@ +package render + +import ( + "fmt" + + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/driver" + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/writer" + "github.com/sqlc-dev/plugin-sdk-go/plugin" +) + +type Renderer struct { + config *config.Config + driver driver.Driver + importResolver *ImportResolver +} + +func New(cfg *config.Config, drv driver.Driver) *Renderer { + return &Renderer{ + config: cfg, + driver: drv, + importResolver: NewImportResolver(cfg, drv), + } +} + +func (r *Renderer) RenderAll(enums []model.Enum, tables []model.Table, queries []model.Query) ([]*plugin.File, error) { + outputFiles := make([]*plugin.File, 0) + if len(enums) > 0 { + outputFiles = append(outputFiles, r.renderEnums(enums)) + } + // models.py is emitted even when every table was filtered out: users + // import it directly, and v0.4.x always shipped it. + outputFiles = append(outputFiles, r.renderTables(tables)) + + queriesModuleMap := make(map[string][]model.Query) + for _, query := range queries { + if !r.driver.SupportsCommand(query.Cmd) { + return nil, fmt.Errorf(`unsupported cmd "%s" for driver "%s"`, query.Cmd, r.driver.Name()) + } + + innerQueries, ok := queriesModuleMap[query.ModuleName] + if ok { + queriesModuleMap[query.ModuleName] = append(innerQueries, query) + } else { + queriesModuleMap[query.ModuleName] = []model.Query{query} + } + } + + for module, innerQueries := range queriesModuleMap { + outputFiles = append(outputFiles, r.renderQueriesModule(module, innerQueries)) + } + + if r.config.EmitInitFile != nil && *r.config.EmitInitFile { + outputFiles = append(outputFiles, r.renderInitFile()) + } + + return outputFiles, nil +} + +// renderInitFile renders the package __init__.py. +func (r *Renderer) renderInitFile() *plugin.File { + fileBody := r.getCodeWriter() + fileBody.WriteSqlcHeader(nil) + fileBody.WriteInitFileModuleDocstring() + + return &plugin.File{ + Name: "__init__.py", + Contents: fileBody.Bytes(), + } +} + +func (r *Renderer) getCodeWriter() *writer.CodeWriter { + return writer.NewCodeWriter(r.config) +} diff --git a/internal/render/tables.go b/internal/render/tables.go new file mode 100644 index 00000000..490f095e --- /dev/null +++ b/internal/render/tables.go @@ -0,0 +1,64 @@ +package render + +import ( + "fmt" + + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/writer" + "github.com/sqlc-dev/plugin-sdk-go/plugin" +) + +const tableFileName = "models.py" + +func (r *Renderer) renderTable(body *writer.CodeWriter, table model.Table) { + inheritance := "" + switch r.config.ModelType { + case config.ModelTypeAttrs: + body.WriteLine("@attrs.define()") + case config.ModelTypeDataclass: + body.WriteLine("@dataclasses.dataclass()") + case config.ModelTypeMsgspec: + inheritance = "(msgspec.Struct)" + case config.ModelTypePydantic: + inheritance = "(pydantic.BaseModel)" + } + body.WriteLine(fmt.Sprintf("class %s%s:", table.Name, inheritance)) + body.WriteModelClassDocstring(&table) + if r.config.ModelType == config.ModelTypePydantic { + // Without this, class definition fails for field types pydantic has no + // core schema for (memoryview, override types); isinstance validation + // still applies to them. + body.WriteIndentedLine(1, "model_config = pydantic.ConfigDict(arbitrary_types_allowed=True)") + body.NewLine() + } + for _, column := range table.Columns { + body.WriteIndentedLine(1, column.Name+": "+column.Type.Print()) + } +} + +func (r *Renderer) renderTables(tables []model.Table) *plugin.File { + fileBody := r.getCodeWriter() + fileBody.WriteSqlcHeader(nil) + fileBody.WriteModelFileModuleDocstring() + fileBody.WriteFutureImport() + + all := make([]string, len(tables)) + for i, table := range tables { + all[i] = table.Name + } + fileBody.WriteAll(all) + fileBody.NewLine() + + r.importResolver.ModelImports(tables).Write(fileBody, r.config.OmitTypecheckingBlock, nil) + + for _, table := range tables { + fileBody.NNewLine(2) + r.renderTable(fileBody, table) + } + + return &plugin.File{ + Name: tableFileName, + Contents: fileBody.Bytes(), + } +} diff --git a/internal/transform/enums.go b/internal/transform/enums.go new file mode 100644 index 00000000..22f6759b --- /dev/null +++ b/internal/transform/enums.go @@ -0,0 +1,43 @@ +package transform + +import ( + "cmp" + "slices" + + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/utils" +) + +func (t *Transformer) BuildEnums() []model.Enum { + enums := make([]model.Enum, 0) + for _, schema := range t.req.Catalog.Schemas { + if schema.Name == utils.PgCatalog || schema.Name == utils.InformationSchema { + continue + } + for _, enum := range schema.Enums { + var schemaName string + if schema.Name != t.req.Catalog.DefaultSchema { + schemaName = schema.Name + } + + e := model.Enum{ + Name: model.EnumName(t.config, enum.Name, schemaName), + Constants: make([]model.EnumConstants, 0, len(enum.Vals)), + } + + seen := make(map[string]int, len(enum.Vals)) + for i, v := range enum.Vals { + e.Constants = append(e.Constants, model.EnumConstants{ + Name: model.EnumConstantName(v, i, seen), + Value: v, + }) + } + enums = append(enums, e) + } + } + slices.SortFunc(enums, func(a, b model.Enum) int { + return cmp.Compare(a.Name, b.Name) + }) + + return enums +} diff --git a/internal/transform/filter.go b/internal/transform/filter.go new file mode 100644 index 00000000..76c54974 --- /dev/null +++ b/internal/transform/filter.go @@ -0,0 +1,61 @@ +package transform + +import ( + "strings" + + "github.com/rayakame/sqlc-gen-better-python/internal/model" +) + +// FilterUnusedModels removes tables and enums that are not referenced by any +// query (as argument, return value, row/params class column, or embed). +// Used when the omit_unused_models option is enabled. +func FilterUnusedModels(enums []model.Enum, tables []model.Table, queries []model.Query) ([]model.Enum, []model.Table) { + keep := make(map[string]struct{}) + addType := func(typeName string) { + typeName = strings.TrimPrefix(typeName, "models.") + typeName = strings.TrimPrefix(typeName, "enums.") + keep[typeName] = struct{}{} + } + collect := func(qv model.QueryValue) { + if qv.IsEmpty() { + return + } + addType(qv.Type.Type) + if qv.Table == nil { + return + } + for _, col := range qv.Table.Columns { + if col.Embed != nil { + addType(col.Embed.ModelName) + for _, embedCol := range col.Embed.Columns { + addType(embedCol.Type.Type) + } + + continue + } + addType(col.Type.Type) + } + } + for _, query := range queries { + collect(query.Returns) + for _, param := range query.Params { + collect(param) + } + } + + keptEnums := make([]model.Enum, 0, len(enums)) + for _, enum := range enums { + if _, ok := keep[enum.Name]; ok { + keptEnums = append(keptEnums, enum) + } + } + + keptTables := make([]model.Table, 0, len(tables)) + for _, table := range tables { + if _, ok := keep[table.Name]; ok { + keptTables = append(keptTables, table) + } + } + + return keptEnums, keptTables +} diff --git a/internal/transform/queries.go b/internal/transform/queries.go new file mode 100644 index 00000000..e10dff18 --- /dev/null +++ b/internal/transform/queries.go @@ -0,0 +1,220 @@ +package transform + +import ( + "slices" + "strings" + + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/utils" + "github.com/sqlc-dev/plugin-sdk-go/metadata" + "github.com/sqlc-dev/plugin-sdk-go/plugin" +) + +func (t *Transformer) BuildQueries(tables []model.Table) []model.Query { + queries := make([]model.Query, 0, len(t.req.Queries)) + for _, pluginQuery := range t.req.Queries { + if pluginQuery.Name == "" { + continue + } + if pluginQuery.Cmd == "" { + continue + } + + constantName := model.UpperSnakeCase(pluginQuery.Name) + + moduleName := pluginQuery.Filename + lastDot := strings.LastIndex(moduleName, ".") + if lastDot != -1 { + moduleName = moduleName[:lastDot] + } + + query := model.Query{ + Cmd: pluginQuery.Cmd, + SQL: pluginQuery.Text, + ConstantName: constantName, + FuncName: strings.ToLower(constantName), + QueryName: pluginQuery.Name, + Params: make([]model.QueryValue, 0), + Returns: model.QueryValue{Type: model.PyType{Type: "None"}}, + FileName: pluginQuery.Filename, + ModuleName: moduleName, + Table: pluginQuery.InsertIntoTable, + } + + if query.Cmd == metadata.CmdCopyFrom || t.config.IsOverQueryParameterLimit(len(pluginQuery.Params)) { + columns := make([]pyColumn, 0, len(pluginQuery.Params)) + for _, param := range pluginQuery.Params { + columns = append(columns, pyColumn{ + column: param.Column, + embed: nil, + }) + } + table := t.columnsToClass(query.QueryName+"Params", columns) + query.Params = []model.QueryValue{ + { + Table: utils.ToPtr(table), + Name: "params", + Type: model.PyType{Type: table.Name, IsList: query.Cmd == metadata.CmdCopyFrom}, + EmitTable: true, + }, + } + } else { + query.Params = make([]model.QueryValue, 0, len(pluginQuery.Params)) + seen := make(map[string]int, len(pluginQuery.Params)+1) + // The implicit first argument of every generated function must + // never collide with a parameter name: a column literally named + // "conn" (or "self" in classes mode) would otherwise produce a + // duplicate argument and a SyntaxError in the generated module. + if t.config.EmitClasses { + seen["self"]++ + } else { + seen["conn"]++ + } + for _, param := range pluginQuery.Params { + query.Params = append(query.Params, model.QueryValue{ + Name: model.DedupName(model.ParamName(param), seen), + Type: t.buildPyType(param.Column), + }) + } + } + + if query.Cmd == metadata.CmdExecLastId { + query.Returns.Type = model.PyType{Type: "int", IsNullable: true} + } + if query.Cmd == metadata.CmdExecRows || query.Cmd == metadata.CmdCopyFrom { + query.Returns.Type = model.PyType{Type: "int"} + } + + if pluginQuery.Cmd != metadata.CmdOne && pluginQuery.Cmd != metadata.CmdMany { + queries = append(queries, query) + + continue + } + + if len(pluginQuery.Columns) == 1 && pluginQuery.Columns[0].EmbedTable == nil { + column := pluginQuery.Columns[0] + query.Returns = model.QueryValue{Type: t.buildPyType(column)} + queries = append(queries, query) + + continue + } + + // Precompute the query's column names/types once - they do not depend + // on the candidate table - instead of rebuilding them per candidate. + queryColumnNames := make([]string, len(pluginQuery.Columns)) + queryColumnTypes := make([]model.PyType, len(pluginQuery.Columns)) + for i, column := range pluginQuery.Columns { + queryColumnNames[i] = model.EscapedColumnName(column, i) + queryColumnTypes[i] = t.buildPyType(column) + } + + var tableFound bool + for _, table := range tables { + if len(table.Columns) != len(pluginQuery.Columns) { + continue + } + // A table only matches when EVERY column matches by name, type, + // and source table - otherwise a dedicated Row class is needed. + same := true + for i, tableColumn := range table.Columns { + queryColumn := pluginQuery.Columns[i] + + sameName := tableColumn.Name == queryColumnNames[i] + // Compare the full type semantics, not just the type name: a + // LEFT JOIN makes columns nullable, and reusing the non-null + // model class would produce wrongly typed fields. + sameType := tableColumn.Type.Type == queryColumnTypes[i].Type && + tableColumn.Type.IsNullable == queryColumnTypes[i].IsNullable && + tableColumn.Type.IsList == queryColumnTypes[i].IsList && + tableColumn.Type.IsEnum == queryColumnTypes[i].IsEnum + sameTable := utils.SameTableName(queryColumn.Table, table.Identifier, t.req.Catalog.DefaultSchema) + if !sameName || !sameType || !sameTable { + same = false + + break + } + } + if same { + query.Returns = model.QueryValue{ + Table: utils.ToPtr(table), + Type: model.PyType{Type: "models." + table.Name}, + } + tableFound = true + break + } + } + + if !tableFound { + columns := make([]pyColumn, 0, len(pluginQuery.Columns)) + for _, column := range pluginQuery.Columns { + columns = append(columns, pyColumn{ + column: column, + embed: t.newGoEmbed(column.EmbedTable, tables), + }) + } + returnTable := t.columnsToClass(query.QueryName+"Row", columns) + query.Returns = model.QueryValue{ + Table: utils.ToPtr(returnTable), + Type: model.PyType{Type: returnTable.Name}, + EmitTable: true, + } + } + + queries = append(queries, query) + } + + return queries +} + +type pyColumn struct { + column *plugin.Column + embed *model.Embed +} + +func (t *Transformer) columnsToClass(name string, columns []pyColumn) model.Table { + table := model.Table{ + Name: name, + Columns: make([]model.Column, 0, len(columns)), + Identifier: utils.ToPtr(plugin.Identifier{}), + } + seen := make(map[string]int, len(columns)) + for i, column := range columns { + columnName := model.EscapedColumnName(column.column, i) + if column.embed != nil { + // Embed fields are named after their table; use the singular + // form ("test_inner_postgres_type"), matching the model naming. + columnName = model.Singular(model.SingularParams{ + Name: columnName, + Exclusions: t.config.InflectionExcludeTableNames, + }) + } + tableColumn := model.Column{ + Name: model.DedupName(columnName, seen), + DBName: model.ColumnName(column.column, i), + } + + if column.embed == nil { + tableColumn.Type = t.buildPyType(column.column) + } else { + tableColumn.Embed = column.embed + tableColumn.Type.Type = "models." + column.embed.ModelName + } + + table.Columns = append(table.Columns, tableColumn) + } + return table +} + +func (t *Transformer) newGoEmbed(embedTable *plugin.Identifier, tables []model.Table) *model.Embed { + if embedTable == nil { + return nil + } + + for _, table := range tables { + if !utils.SameTableName(embedTable, table.Identifier, t.req.Catalog.DefaultSchema) { + continue + } + return utils.ToPtr(model.Embed{ModelName: table.Name, Columns: slices.Clone(table.Columns)}) + } + return nil +} diff --git a/internal/transform/tables.go b/internal/transform/tables.go new file mode 100644 index 00000000..f945d1f8 --- /dev/null +++ b/internal/transform/tables.go @@ -0,0 +1,53 @@ +package transform + +import ( + "cmp" + "slices" + + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/utils" + "github.com/sqlc-dev/plugin-sdk-go/plugin" +) + +func (t *Transformer) BuildTables() []model.Table { + tables := make([]model.Table, 0) + for _, schema := range t.req.Catalog.Schemas { + if schema.Name == utils.PgCatalog || schema.Name == utils.InformationSchema { + continue + } + for _, table := range schema.Tables { + tables = append(tables, t.buildTable(schema, table)) + } + } + slices.SortFunc(tables, func(a, b model.Table) int { + return cmp.Compare(a.Name, b.Name) + }) + + return tables +} + +func (t *Transformer) buildTable(pluginSchema *plugin.Schema, pluginTable *plugin.Table) model.Table { + var schemaName string + if pluginSchema.Name != t.req.Catalog.DefaultSchema { + schemaName = pluginSchema.Name + } + tableName := model.ModelName(t.config, pluginTable.Rel.Name, schemaName) + table := model.Table{ + Name: tableName, + Columns: make([]model.Column, 0, len(pluginTable.Columns)), + Identifier: utils.ToPtr(plugin.Identifier{ + Catalog: "", + Schema: pluginSchema.Name, + Name: pluginTable.Rel.Name, + }), + } + for i, column := range pluginTable.Columns { + table.Columns = append(table.Columns, model.Column{ + Name: model.EscapedColumnName(column, i), + DBName: model.ColumnName(column, i), + Type: t.buildPyType(column), + }) + } + + return table +} diff --git a/internal/transform/transformer.go b/internal/transform/transformer.go new file mode 100644 index 00000000..a4fd0760 --- /dev/null +++ b/internal/transform/transformer.go @@ -0,0 +1,17 @@ +package transform + +import ( + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/types" + "github.com/sqlc-dev/plugin-sdk-go/plugin" +) + +type Transformer struct { + typeConversionFunc types.TypeConversionFunc + config *config.Config + req *plugin.GenerateRequest +} + +func NewTransformer(conf *config.Config, req *plugin.GenerateRequest, convFunc types.TypeConversionFunc) *Transformer { + return &Transformer{typeConversionFunc: convFunc, config: conf, req: req} +} diff --git a/internal/transform/type.go b/internal/transform/type.go new file mode 100644 index 00000000..17ede06b --- /dev/null +++ b/internal/transform/type.go @@ -0,0 +1,95 @@ +package transform + +import ( + "strings" + + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/utils" + "github.com/sqlc-dev/plugin-sdk-go/plugin" + "github.com/sqlc-dev/plugin-sdk-go/sdk" +) + +func (t *Transformer) convertType(columnType *plugin.Identifier) string { + return t.typeConversionFunc(t.req, t.config, columnType) +} + +func (t *Transformer) buildPyType(pluginColumn *plugin.Column) model.PyType { + // SQL type names are matched case-insensitively everywhere downstream + // (conversion registration, docstrings): sqlite DDL keeps the author's + // casing ("DATETIME"), so normalize once here instead of in every consumer. + columnType := strings.ToLower(sdk.DataType(pluginColumn.Type)) + strType := t.convertType(pluginColumn.Type) + + isEnum := false + + // Never mutate pluginColumn: buildPyType runs repeatedly on the same + // shared columns (e.g. during table matching), and writing the default + // schema back would change sdk.DataType results on later calls. + typeSchema := pluginColumn.Type.Schema + if typeSchema == "" { + typeSchema = t.req.Catalog.DefaultSchema + } + + for _, schema := range t.req.Catalog.Schemas { + if schema.Name == utils.PgCatalog || schema.Name == utils.InformationSchema { + continue + } + if typeSchema != schema.GetName() { + continue + } + + for _, enum := range schema.Enums { + if pluginColumn.Type.Name == enum.Name { + isEnum = true + } + } + } + + if override := t.matchOverride(pluginColumn, columnType); override != nil { + return model.PyType{ + SQLType: columnType, + Type: override.PyType.Type, + IsNullable: !pluginColumn.GetNotNull(), + IsList: pluginColumn.GetIsArray() || pluginColumn.GetIsSqlcSlice(), + IsEnum: false, + IsOverride: true, + DefaultType: strType, + } + } + + return model.PyType{ + SQLType: columnType, + Type: strType, + IsNullable: !pluginColumn.GetNotNull(), + IsList: pluginColumn.GetIsArray() || pluginColumn.GetIsSqlcSlice(), + IsEnum: isEnum, + IsOverride: false, + DefaultType: strType, + } +} + +// matchOverride returns the first configured override matching the column, +// either by column pattern or by exact SQL type. +func (t *Transformer) matchOverride(pluginColumn *plugin.Column, columnType string) *config.Override { + for i := range t.config.Overrides { + override := &t.config.Overrides[i] + if override.PyType.Type == "" { + continue + } + if override.Column != "" { + columnName := pluginColumn.Name + if pluginColumn.OriginalName != "" { + columnName = pluginColumn.OriginalName + } + if override.ColumnName.MatchString(columnName) && override.Matches(pluginColumn.Table, t.req.Catalog.DefaultSchema) { + return override + } + } + if override.DBType != "" && override.DBType == columnType { + return override + } + } + + return nil +} diff --git a/internal/typeConversion/asyncpg.go b/internal/typeConversion/asyncpg.go deleted file mode 100644 index f7638c3e..00000000 --- a/internal/typeConversion/asyncpg.go +++ /dev/null @@ -1,12 +0,0 @@ -package typeConversion - -func AsyncpgDoTypeConversion(name string) bool { - _, found := map[string]struct{}{ - "bytea": {}, - "blob": {}, - "pg_catalog.bytea": {}, - "inet": {}, - "cidr": {}, - }[name] - return found -} diff --git a/internal/typeConversion/common.go b/internal/typeConversion/common.go deleted file mode 100644 index bcbca99b..00000000 --- a/internal/typeConversion/common.go +++ /dev/null @@ -1,3 +0,0 @@ -package typeConversion - -type TypeDoTypeConversion func(string) bool diff --git a/internal/typeConversion/sqlite.go b/internal/typeConversion/sqlite.go deleted file mode 100644 index dfd8221b..00000000 --- a/internal/typeConversion/sqlite.go +++ /dev/null @@ -1,27 +0,0 @@ -package typeConversion - -import "strings" - -var conversions = map[string]struct{}{ - "boolean": {}, - "bool": {}, - "date": {}, - "datetime": {}, - "timestamp": {}, - "decimal": {}, - "blob": {}, -} - -func SqliteDoTypeConversion(name string) bool { - _, found := conversions[name] - if found { - return found - } else if strings.HasPrefix(name, "decimal") { - return true - } - return false -} - -func SqliteGetConversions() map[string]struct{} { - return conversions -} diff --git a/internal/types/common.go b/internal/types/common.go index 02679334..101ff151 100644 --- a/internal/types/common.go +++ b/internal/types/common.go @@ -1,8 +1,21 @@ package types import ( - "github.com/rayakame/sqlc-gen-better-python/internal/core" + "fmt" + + "github.com/rayakame/sqlc-gen-better-python/internal/config" "github.com/sqlc-dev/plugin-sdk-go/plugin" ) -type TypeConversionFunc func(req *plugin.GenerateRequest, col *plugin.Column, conf *core.Config) string +type TypeConversionFunc func(*plugin.GenerateRequest, *config.Config, *plugin.Identifier) string + +func GetTypeConversionFunc(engine string) (TypeConversionFunc, error) { + switch engine { + case "postgresql": + return PostgresTypeToPython, nil + case "sqlite": + return SqliteTypeToPython, nil + default: + return nil, fmt.Errorf("engine %q is not supported", engine) + } +} diff --git a/internal/types/constants.go b/internal/types/constants.go new file mode 100644 index 00000000..4171e7c6 --- /dev/null +++ b/internal/types/constants.go @@ -0,0 +1,9 @@ +package types + +const ( + Bool = "bool" + Boolean = "boolean" + Str = "str" + Int = "int" + Float = "float" +) diff --git a/internal/types/postgresql.go b/internal/types/postgresql.go index 61e09a31..75203fff 100644 --- a/internal/types/postgresql.go +++ b/internal/types/postgresql.go @@ -2,29 +2,72 @@ package types import ( "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/core" - "github.com/rayakame/sqlc-gen-better-python/internal/log" + "strings" + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/log" + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/utils" "github.com/sqlc-dev/plugin-sdk-go/plugin" "github.com/sqlc-dev/plugin-sdk-go/sdk" ) -func PostgresTypeToPython(req *plugin.GenerateRequest, col *plugin.Column, conf *core.Config) string { - columnType := sdk.DataType(col.Type) +func parseIdentifierString(name string) (*plugin.Identifier, error) { + parts := strings.Split(name, ".") + switch len(parts) { + case 1: + return &plugin.Identifier{ + Name: parts[0], + }, nil + case 2: + return &plugin.Identifier{ + Schema: parts[0], + Name: parts[1], + }, nil + case 3: + return &plugin.Identifier{ + Catalog: parts[0], + Schema: parts[1], + Name: parts[2], + }, nil + default: + return nil, fmt.Errorf("invalid name: %s", name) + } +} +func PostgresTypeToPython(req *plugin.GenerateRequest, config *config.Config, pluginType *plugin.Identifier) string { + columnType := sdk.DataType(pluginType) switch columnType { - case "serial", "serial4", "pg_catalog.serial4", "bigserial", "serial8", "pg_catalog.serial8", "smallserial", "serial2", "pg_catalog.serial2", "integer", "int", "int4", "pg_catalog.int4", "bigint", "int8", "pg_catalog.int8", "smallint", "int2", "pg_catalog.int2": - return "int" - case "float", "double precision", "float8", "pg_catalog.float8", "real", "float4", "pg_catalog.float4": - return "float" + case "serial", + "serial4", + "pg_catalog.serial4", + "bigserial", + "serial8", + "pg_catalog.serial8", + "smallserial", + "serial2", + "pg_catalog.serial2", + "integer", + Int, + "int4", + "pg_catalog.int4", + "bigint", + "int8", + "pg_catalog.int8", + "smallint", + "int2", + "pg_catalog.int2": + return Int + case Float, "double precision", "float8", "pg_catalog.float8", "real", "float4", "pg_catalog.float4": + return Float case "numeric", "pg_catalog.numeric": return "decimal.Decimal" case "money": - return "str" - case "boolean", "bool", "pg_catalog.bool": - return "bool" + return Str + case Boolean, Bool, "pg_catalog.bool": + return Bool case "pg_catalog.json", "json", "jsonb": - return "str" + return Str case "bytea", "blob", "pg_catalog.bytea": return "memoryview" case "date": @@ -36,31 +79,45 @@ func PostgresTypeToPython(req *plugin.GenerateRequest, col *plugin.Column, conf case "interval", "pg_catalog.interval": return "datetime.timedelta" case "text", "pg_catalog.varchar", "bpchar", "pg_catalog.bpchar", "char", "string", "citext": - return "str" - case "uuid": + return Str + case "uuid", "pg_catalog.uuid": return "uuid.UUID" case "inet", "cidr", "macaddr", "macaddr8": // psycopg2 does have support for ipaddress objects, but it is not enabled by default // // https://www.psycopg.org/docs/extras.html#adapt-network - return "str" + return Str case "ltree", "lquery", "ltxtquery": - return "str" + return Str default: + columnRelation, err := parseIdentifierString(columnType) + if err != nil { + log.L().LogErr("error trying to parse identifier string", err) + return "typing.Any" + } + if columnRelation.Schema == "" { + columnRelation.Schema = req.Catalog.DefaultSchema + } for _, schema := range req.Catalog.Schemas { - if schema.Name == "pg_catalog" || schema.Name == "information_schema" { + if schema.Name == utils.PgCatalog || schema.Name == utils.InformationSchema { + continue + } + if schema.Name != columnRelation.Schema { continue } for _, enum := range schema.Enums { - if columnType == enum.Name { - if schema.Name == req.Catalog.DefaultSchema { - return "models." + core.ModelName(enum.Name, "", conf) - } - return "models." + core.ModelName(enum.Name, schema.Name, conf) + if columnRelation.Name != enum.Name { + continue } + if schema.Name == req.Catalog.DefaultSchema { + return "enums." + model.EnumName(config, enum.Name, "") + } + + return "enums." + model.EnumName(config, enum.Name, schema.Name) } } - log.GlobalLogger.Log(fmt.Sprintf("unknown PostgreSQL type: %s", columnType)) + log.L().Log("unknown PostgreSQL type: " + columnType) + return "typing.Any" } } diff --git a/internal/types/sqlite.go b/internal/types/sqlite.go index a15ed2af..f27d1e9c 100644 --- a/internal/types/sqlite.go +++ b/internal/types/sqlite.go @@ -1,27 +1,26 @@ package types import ( - "fmt" - "github.com/rayakame/sqlc-gen-better-python/internal/core" - "github.com/rayakame/sqlc-gen-better-python/internal/log" "strings" + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/log" "github.com/sqlc-dev/plugin-sdk-go/plugin" "github.com/sqlc-dev/plugin-sdk-go/sdk" ) -func SqliteTypeToPython(_ *plugin.GenerateRequest, col *plugin.Column, _ *core.Config) string { - columnType := strings.ToLower(sdk.DataType(col.Type)) +func SqliteTypeToPython(_ *plugin.GenerateRequest, _ *config.Config, pluginType *plugin.Identifier) string { + columnType := strings.ToLower(sdk.DataType(pluginType)) switch columnType { - case "int", "integer", "tinyint", "smallint", "mediumint", "bigint", "unsignedbigint", "int2", "int8", "bigserial": - return "int" + case Int, "integer", "tinyint", "smallint", "mediumint", "bigint", "unsignedbigint", "int2", "int8", "bigserial": + return Int case "blob": return "memoryview" - case "real", "double", "double precision", "doubleprecision", "float", "numeric": - return "float" - case "boolean", "bool": - return "bool" + case "real", "double", "double precision", "doubleprecision", Float, "numeric": + return Float + case Boolean, Bool: + return Bool case "date": return "datetime.date" case "datetime", "timestamp": @@ -40,10 +39,16 @@ func SqliteTypeToPython(_ *plugin.GenerateRequest, col *plugin.Column, _ *core.C columnType == "text", columnType == "clob", columnType == "json": - return "str" + return Str + + // Precision variants like "decimal(10,5)" keep their prefix; must agree + // with the conversion registration in driver/conversion.go. + case strings.HasPrefix(columnType, "decimal"): + return "decimal.Decimal" default: - log.GlobalLogger.Log(fmt.Sprintf("unknown SQLite type: %s", columnType)) + log.L().Log("unknown SQLite type: " + columnType) + return "typing.Any" } } diff --git a/internal/utils/common.go b/internal/utils/common.go new file mode 100644 index 00000000..b7a4fbaf --- /dev/null +++ b/internal/utils/common.go @@ -0,0 +1,23 @@ +package utils + +import ( + "github.com/sqlc-dev/plugin-sdk-go/plugin" +) + +func ToPtr[T any](t T) *T { + return &t +} + +func SameTableName(table1, table2 *plugin.Identifier, defaultSchema string) bool { + if table1 == nil || table2 == nil { + return false + } + schema1, schema2 := table1.Schema, table2.Schema + if schema1 == "" { + schema1 = defaultSchema + } + if schema2 == "" { + schema2 = defaultSchema + } + return table1.Catalog == table2.Catalog && schema1 == schema2 && table1.Name == table2.Name +} diff --git a/internal/utils/constants.go b/internal/utils/constants.go new file mode 100644 index 00000000..0805d550 --- /dev/null +++ b/internal/utils/constants.go @@ -0,0 +1,6 @@ +package utils + +const ( + InformationSchema = "information_schema" + PgCatalog = "pg_catalog" +) diff --git a/internal/writer/docstrings.go b/internal/writer/docstrings.go new file mode 100644 index 00000000..e89b014c --- /dev/null +++ b/internal/writer/docstrings.go @@ -0,0 +1,516 @@ +package writer + +import ( + "fmt" + "strings" + + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/sqlc-dev/plugin-sdk-go/metadata" +) + +// DocArg describes one function argument in a docstring. +type DocArg struct { + Name string + Type string + Extra string // optional extra description line (used by :copyfrom) +} + +// DocstringsEnabled reports whether docstring generation is active. Emitters +// use this to add the blank line ruff format requires between a docstring and +// a following nested function definition. +func (w *CodeWriter) DocstringsEnabled() bool { + return w.docstringConvention != config.DocstringConventionNone +} + +// --- Module docstrings ------------------------------------------------------ + +// WriteModelFileModuleDocstring writes the models.py module docstring. +func (w *CodeWriter) WriteModelFileModuleDocstring() { + if !w.DocstringsEnabled() { + return + } + w.WriteLine(`"""Module containing models."""`) + w.NewLine() +} + +// WriteEnumsFileModuleDocstring writes the enums.py module docstring. +func (w *CodeWriter) WriteEnumsFileModuleDocstring() { + if !w.DocstringsEnabled() { + return + } + w.WriteLine(`"""Module containing enums."""`) + w.NewLine() +} + +// WriteQueryFileModuleDocstring writes a query module docstring. +func (w *CodeWriter) WriteQueryFileModuleDocstring(sourceName string) { + if !w.DocstringsEnabled() { + return + } + w.WriteLine(fmt.Sprintf(`"""Module containing queries from file %s."""`, sourceName)) + w.NewLine() +} + +// WriteInitFileModuleDocstring writes the __init__.py module docstring. +func (w *CodeWriter) WriteInitFileModuleDocstring() { + if !w.DocstringsEnabled() { + return + } + w.WriteLine(`"""Package containing queries and models automatically generated using sqlc-gen-better-python."""`) +} + +// --- Class docstrings ------------------------------------------------------- + +// WriteModelClassDocstring writes a model/row/params class docstring with an +// attribute list, followed by a blank line. +func (w *CodeWriter) WriteModelClassDocstring(table *model.Table) { + if !w.DocstringsEnabled() { + return + } + w.WriteIndentedLine(1, `"""`+fmt.Sprintf("Model representing %s.", table.Name)) + w.NewLine() + switch w.docstringConvention { + case config.DocstringConventionNumpy: + w.WriteIndentedLine(1, "Attributes") + w.WriteIndentedLine(1, "----------") + for _, col := range table.Columns { + w.WriteIndentedLine(1, fmt.Sprintf("%s : %s", col.Name, col.Type.Print())) + } + w.NewLine() + case config.DocstringConventionGoogle: + w.WriteIndentedLine(1, "Attributes:") + for _, col := range table.Columns { + w.WriteIndentedLine(2, fmt.Sprintf("%s: %s", col.Name, col.Type.Print())) + } + case config.DocstringConventionPEP257: + w.WriteIndentedLine(1, "Attributes:") + for _, col := range table.Columns { + w.WriteIndentedLine(1, fmt.Sprintf("%s -- %s", col.Name, col.Type.Print())) + } + } + w.WriteIndentedLine(1, `"""`) + w.NewLine() +} + +// WriteEnumClassDocstring writes a one-line enum class docstring. +func (w *CodeWriter) WriteEnumClassDocstring(name string) { + if !w.DocstringsEnabled() { + return + } + w.WriteIndentedLine(1, fmt.Sprintf(`"""Enum representing %s."""`, name)) + w.NewLine() +} + +// --- Querier class docstrings ----------------------------------------------- + +// WriteQueryClassDocstring writes the Querier class docstring. +func (w *CodeWriter) WriteQueryClassDocstring(sourceName, connType string) { + if !w.DocstringsEnabled() { + return + } + w.WriteIndentedString(1, fmt.Sprintf(`"""Queries from file %s.`, sourceName)) + if w.docstringConvention == config.DocstringConventionNumpy { + w.NNewLine(2) + w.WriteIndentedLine(1, "Parameters") + w.WriteIndentedLine(1, "----------") + w.WriteIndentedLine(1, "conn : "+connType) + w.WriteIndentedLine(2, "The connection object used to execute queries.") + w.NewLine() + w.WriteIndentedLine(1, `"""`) + } else { + w.WriteLine(`"""`) + } + w.NewLine() +} + +// WriteQueryClassInitDocstring writes the Querier __init__ docstring. +func (w *CodeWriter) WriteQueryClassInitDocstring(lvl int, connType string) { + if !w.DocstringsEnabled() { + return + } + w.WriteIndentedString(lvl, `"""Initialize the instance using the connection.`) + switch w.docstringConvention { + case config.DocstringConventionNumpy: + w.WriteLine(`"""`) + case config.DocstringConventionGoogle: + w.NNewLine(2) + w.WriteIndentedLine(lvl, "Args:") + w.WriteIndentedLine(lvl+1, "conn:") + w.WriteIndentedLine(lvl+2, fmt.Sprintf("Connection object of type `%s` used to execute the query.", connType)) + w.WriteIndentedLine(lvl, `"""`) + case config.DocstringConventionPEP257: + w.NNewLine(2) + w.WriteIndentedLine(lvl, "Arguments:") + w.WriteIndentedLine(lvl, fmt.Sprintf("conn -- Connection object of type `%s` used to execute queries.", connType)) + w.WriteIndentedLine(lvl, `"""`) + } +} + +// WriteQueryClassConnDocstring writes the Querier conn property docstring. +func (w *CodeWriter) WriteQueryClassConnDocstring(connType string) { + if !w.DocstringsEnabled() { + return + } + w.WriteIndentedLine(2, `"""Connection object used to make queries.`) + w.NewLine() + switch w.docstringConvention { + case config.DocstringConventionNumpy: + w.WriteIndentedLine(2, "Returns") + w.WriteIndentedLine(2, "-------") + w.WriteIndentedLine(2, connType) + w.NewLine() + case config.DocstringConventionGoogle: + w.WriteIndentedLine(2, "Returns:") + w.WriteIndentedLine(3, fmt.Sprintf("Connection object of type `%s` used to make queries.", connType)) + case config.DocstringConventionPEP257: + w.WriteIndentedLine(2, "Returns:") + w.WriteIndentedLine(2, fmt.Sprintf("%s -- Connection object used to make queries.", connType)) + } + w.WriteIndentedLine(2, `"""`) +} + +// --- QueryResults docstrings -------------------------------------------------- + +// WriteQueryResultsClassDocstring writes the QueryResults class docstring. +func (w *CodeWriter) WriteQueryResultsClassDocstring(connType, resultType string) { + if !w.DocstringsEnabled() { + return + } + w.WriteIndentedString(1, `"""Helper class that allows both iteration and normal fetching of data from the db.`) + if w.docstringConvention == config.DocstringConventionNumpy { + w.NNewLine(2) + w.WriteIndentedLine(1, "Parameters") + w.WriteIndentedLine(1, "----------") + w.WriteIndentedLine(1, "conn") + w.WriteIndentedLine(2, fmt.Sprintf("The connection object of type `%s` used to execute queries.", connType)) + w.WriteIndentedLine(1, "sql") + w.WriteIndentedLine(2, "The SQL statement that will be executed when fetching/iterating.") + w.WriteIndentedLine(1, "decode_hook") + w.WriteIndentedLine(2, fmt.Sprintf("A callback that turns an `%s` object into `T` that will be returned.", resultType)) + w.WriteIndentedLine(1, "*args") + w.WriteIndentedLine(2, "Arguments that should be sent when executing the sql query.") + w.NewLine() + w.WriteIndentedLine(1, `"""`) + } else { + w.WriteLine(`"""`) + } + w.NewLine() +} + +// WriteQueryResultsInitDocstring writes the QueryResults __init__ docstring. +func (w *CodeWriter) WriteQueryResultsInitDocstring(connType, resultType string) { + if !w.DocstringsEnabled() { + return + } + w.WriteIndentedString(2, `"""Initialize the QueryResults instance.`) + switch w.docstringConvention { + case config.DocstringConventionNumpy: + w.WriteLine(`"""`) + case config.DocstringConventionGoogle: + w.NNewLine(2) + w.WriteIndentedLine(2, "Args:") + w.WriteIndentedLine(3, "conn:") + w.WriteIndentedLine(4, fmt.Sprintf("The connection object of type `%s` used to execute queries.", connType)) + w.WriteIndentedLine(3, "sql:") + w.WriteIndentedLine(4, "The SQL statement that will be executed when fetching/iterating.") + w.WriteIndentedLine(3, "decode_hook:") + w.WriteIndentedLine(4, fmt.Sprintf("A callback that turns an `%s` object into `T` that will be returned.", resultType)) + w.WriteIndentedLine(3, "*args:") + w.WriteIndentedLine(4, "Arguments that should be sent when executing the sql query.") + w.WriteIndentedLine(2, `"""`) + case config.DocstringConventionPEP257: + w.NNewLine(2) + w.WriteIndentedLine(2, "Arguments:") + w.WriteIndentedLine(2, fmt.Sprintf("conn -- The connection object of type `%s` used to execute queries.", connType)) + w.WriteIndentedLine(2, "sql -- The SQL statement that will be executed when fetching/iterating.") + w.WriteIndentedLine( + 2, + fmt.Sprintf("decode_hook -- A callback that turns an `%s` object into `T` that will be returned.", resultType), + ) + w.WriteIndentedLine(2, "*args -- Arguments that should be sent when executing the sql query.") + w.WriteIndentedLine(2, `"""`) + } +} + +// WriteQueryResultsIterDocstring writes the __iter__/__aiter__ docstring. +func (w *CodeWriter) WriteQueryResultsIterDocstring(async bool) { + if !w.DocstringsEnabled() { + return + } + summary := "Initialize iteration support." + returns := "Self as an iterator." + if async { + summary = "Initialize iteration support for `async for`." + returns = "Self as an asynchronous iterator." + } + w.WriteIndentedLine(2, `"""`+summary) + w.NewLine() + switch w.docstringConvention { + case config.DocstringConventionNumpy: + w.WriteIndentedLine(2, "Returns") + w.WriteIndentedLine(2, "-------") + w.WriteIndentedLine(2, "QueryResults[T]") + w.WriteIndentedLine(3, returns) + case config.DocstringConventionGoogle: + w.WriteIndentedLine(2, "Returns:") + w.WriteIndentedLine(3, returns) + case config.DocstringConventionPEP257: + w.WriteIndentedLine(2, "Returns:") + w.WriteIndentedLine(2, returns) + } + w.WriteIndentedLine(2, `"""`) +} + +// WriteQueryResultsNextDocstring writes the __next__/__anext__ docstring. +// cursorPhrase is e.g. "an asyncpg cursor" or "a sqlite3 cursor". +func (w *CodeWriter) WriteQueryResultsNextDocstring(cursorPhrase string, async bool) { + if !w.DocstringsEnabled() { + return + } + raises := "StopIteration" + if async { + raises = "StopAsyncIteration" + } + w.WriteIndentedLine(2, fmt.Sprintf(`"""Yield the next item in the query result using %s.`, cursorPhrase)) + w.NewLine() + switch w.docstringConvention { + case config.DocstringConventionNumpy: + w.WriteIndentedLine(2, "Returns") + w.WriteIndentedLine(2, "-------") + w.WriteIndentedLine(2, "T") + w.WriteIndentedLine(3, "The next decoded result.") + w.NewLine() + w.WriteIndentedLine(2, "Raises") + w.WriteIndentedLine(2, "------") + w.WriteIndentedLine(2, raises) + w.WriteIndentedLine(3, "When no more records are available.") + case config.DocstringConventionGoogle: + w.WriteIndentedLine(2, "Returns:") + w.WriteIndentedLine(3, "The next decoded result of type `T`.") + w.NewLine() + w.WriteIndentedLine(2, "Raises:") + w.WriteIndentedLine(3, raises+": When no more records are available.") + case config.DocstringConventionPEP257: + w.WriteIndentedLine(2, "Returns:") + w.WriteIndentedLine(2, "The next decoded result of type `T`.") + w.NewLine() + w.WriteIndentedLine(2, "Raises:") + w.WriteIndentedLine(2, raises+" -- When no more records are available.") + } + w.WriteIndentedLine(2, `"""`) +} + +// WriteQueryResultsFetchDocstring writes the __await__/__call__ docstring. +func (w *CodeWriter) WriteQueryResultsFetchDocstring(async bool) { + if !w.DocstringsEnabled() { + return + } + summary := "Allow calling the object to return all rows as a fully decoded sequence." + if async { + summary = "Allow `await` on the object to return all rows as a fully decoded sequence." + } + w.WriteIndentedLine(2, `"""`+summary) + w.NewLine() + switch w.docstringConvention { + case config.DocstringConventionNumpy: + w.WriteIndentedLine(2, "Returns") + w.WriteIndentedLine(2, "-------") + w.WriteIndentedLine(2, "collections.abc.Sequence[T]") + w.WriteIndentedLine(3, "A sequence of decoded objects of type `T`.") + case config.DocstringConventionGoogle: + w.WriteIndentedLine(2, "Returns:") + w.WriteIndentedLine(3, "A sequence of decoded objects of type `T`.") + case config.DocstringConventionPEP257: + w.WriteIndentedLine(2, "Returns:") + w.WriteIndentedLine(2, "A sequence of decoded objects of type `T`.") + } + w.WriteIndentedLine(2, `"""`) +} + +// --- Query function docstrings ------------------------------------------------ + +// retDoc describes the Returns section of a query function docstring. +type retDoc struct { + numpyType string // type line for numpy, e.g. "int" or "QueryResults[models.Author]" + text string // description used by numpy/pep257 + google string // full google-style description line +} + +// WriteQueryFunctionDocstring writes the docstring for a generated query +// function. retType is the return type used in the Returns section; its +// exact value is driver-specific for some commands (e.g. :execresult). +func (w *CodeWriter) WriteQueryFunctionDocstring(lvl int, query *model.Query, connType string, args []DocArg, retType string) { + if !w.DocstringsEnabled() { + return + } + + var summaryFmt string + var ret *retDoc + emitSQL := true + switch query.Cmd { + case metadata.CmdExec: + summaryFmt = "Execute SQL query with `name: %s %s`." + case metadata.CmdExecRows: + summaryFmt = "Execute SQL query with `name: %s %s` and return the number of affected rows." + // Both sqlite drivers return cursor.rowcount, which is -1 for + // non-DML statements per DB-API; only asyncpg's status-string parse + // falls back to 0. + noRows := "0" + if w.docstringDriver == config.SQLDriverAioSQLite || w.docstringDriver == config.SQLDriverSQLite { + noRows = "-1" + } + ret = &retDoc{ + numpyType: retType, + text: fmt.Sprintf("The number of affected rows. This will be %s for queries like `CREATE TABLE`.", noRows), + google: fmt.Sprintf( + "The number (`%s`) of affected rows. This will be %s for queries like `CREATE TABLE`.", + retType, + noRows, + ), + } + case metadata.CmdCopyFrom: + summaryFmt = "Execute COPY FROM query to insert rows into a table with `name: %s %s` and return the number of affected rows." + emitSQL = false + ret = &retDoc{ + numpyType: retType, + text: "The number of affected rows.", + google: fmt.Sprintf("The number (`%s`) of affected rows.", retType), + } + case metadata.CmdExecResult: + summaryFmt = "Execute and return the result of SQL query with `name: %s %s`." + ret = &retDoc{ + numpyType: retType, + text: "The result returned when executing the query.", + google: fmt.Sprintf("The result of type `%s` returned when executing the query.", retType), + } + case metadata.CmdExecLastId: + summaryFmt = "Execute SQL query with `name: %s %s` and return the id of the last affected row." + ret = &retDoc{ + numpyType: retType, + text: "The id of the last affected row. Will be `None` if no rows are affected.", + google: fmt.Sprintf("The id (`%s`) of the last affected row. Will be `None` if no rows are affected.", retType), + } + case metadata.CmdOne: + summaryFmt = "Fetch one from the db using the SQL query with `name: %s %s`." + ret = &retDoc{ + numpyType: retType, + text: "Result fetched from the db. Will be `None` if not found.", + google: fmt.Sprintf("Result of type `%s` fetched from the db. Will be `None` if not found.", retType), + } + case metadata.CmdMany: + summaryFmt = "Fetch many from the db using the SQL query with `name: %s %s`." + ret = &retDoc{ + numpyType: "QueryResults[" + retType + "]", + text: "Helper class that allows both iteration and normal fetching of data from the db.", + google: fmt.Sprintf( + "Helper class of type `QueryResults[%s]` that allows both iteration and normal fetching of data from the db.", + retType, + ), + } + default: + return + } + + w.WriteIndentedLine(lvl, `"""`+fmt.Sprintf(summaryFmt, query.QueryName, query.Cmd)) + w.NewLine() + if emitSQL && !w.docstringOmitSQL { + w.WriteIndentedLine(lvl, "```sql") + for _, line := range strings.Split(strings.ReplaceAll(query.SQL, "\r\n", "\n"), "\n") { + // Never write indentation-only lines (ruff W293). + if strings.TrimSpace(line) == "" { + w.NewLine() + } else { + w.WriteIndentedLine(lvl, line) + } + } + w.WriteIndentedLine(lvl, "```") + w.NewLine() + } + + wroteArgs := w.writeDocArgsSection(lvl, connType, args) + if ret == nil { + // Commands without a Returns section (:exec): numpy keeps a trailing + // blank line after the parameters. + if wroteArgs && w.docstringConvention == config.DocstringConventionNumpy { + w.NewLine() + } + w.WriteIndentedLine(lvl, `"""`) + + return + } + + if wroteArgs { + w.NewLine() + } + w.writeDocReturnsSection(lvl, ret) + w.WriteIndentedLine(lvl, `"""`) +} + +// writeDocArgsSection writes the Parameters/Args/Arguments section and reports +// whether anything was written. No trailing blank line is emitted. +func (w *CodeWriter) writeDocArgsSection(lvl int, connType string, args []DocArg) bool { + if connType == "" && len(args) == 0 { + return false + } + connDesc := fmt.Sprintf("Connection object of type `%s` used to execute the query.", connType) + switch w.docstringConvention { + case config.DocstringConventionNumpy: + w.WriteIndentedLine(lvl, "Parameters") + w.WriteIndentedLine(lvl, "----------") + if connType != "" { + w.WriteIndentedLine(lvl, "conn : "+connType) + w.WriteIndentedLine(lvl+1, connDesc) + } + for _, arg := range args { + w.WriteIndentedLine(lvl, fmt.Sprintf("%s : %s", arg.Name, arg.Type)) + if arg.Extra != "" { + w.WriteIndentedLine(lvl+1, arg.Extra) + } + } + case config.DocstringConventionGoogle: + w.WriteIndentedLine(lvl, "Args:") + if connType != "" { + w.WriteIndentedLine(lvl+1, "conn:") + w.WriteIndentedLine(lvl+2, connDesc) + } + for _, arg := range args { + w.WriteIndentedLine(lvl+1, fmt.Sprintf("%s: %s.", arg.Name, arg.Type)) + if arg.Extra != "" { + w.WriteIndentedLine(lvl+2, arg.Extra) + } + } + case config.DocstringConventionPEP257: + w.WriteIndentedLine(lvl, "Arguments:") + if connType != "" { + w.WriteIndentedLine(lvl, "conn -- "+connDesc) + } + for _, arg := range args { + line := fmt.Sprintf("%s -- %s.", arg.Name, arg.Type) + if arg.Extra != "" { + line += " " + arg.Extra + } + w.WriteIndentedLine(lvl, line) + } + } + + return true +} + +// writeDocReturnsSection writes the Returns section for a query function. +func (w *CodeWriter) writeDocReturnsSection(lvl int, ret *retDoc) { + switch w.docstringConvention { + case config.DocstringConventionNumpy: + w.WriteIndentedLine(lvl, "Returns") + w.WriteIndentedLine(lvl, "-------") + w.WriteIndentedLine(lvl, ret.numpyType) + w.WriteIndentedLine(lvl+1, ret.text) + w.NewLine() + case config.DocstringConventionGoogle: + w.WriteIndentedLine(lvl, "Returns:") + w.WriteIndentedLine(lvl+1, ret.google) + case config.DocstringConventionPEP257: + w.WriteIndentedLine(lvl, "Returns:") + w.WriteIndentedLine(lvl, fmt.Sprintf("%s -- %s", ret.numpyType, ret.text)) + } +} diff --git a/internal/writer/queryresults.go b/internal/writer/queryresults.go new file mode 100644 index 00000000..8ebbed5e --- /dev/null +++ b/internal/writer/queryresults.go @@ -0,0 +1,82 @@ +package writer + +import ( + "fmt" + + "github.com/rayakame/sqlc-gen-better-python/internal/utils" +) + +type QueryResultsWriter struct { + writer *CodeWriter +} + +func NewQueryResultsWriter(writer *CodeWriter) *QueryResultsWriter { + return utils.ToPtr(QueryResultsWriter{writer: writer}) +} + +func (w *QueryResultsWriter) WriteQueryResultsClassHeader( + connType string, + initFields []string, + driverReturnType string, + async bool, +) { + // PEP 695 class-scoped type parameter: no module-level TypeVar and no + // typing.Generic base needed on Python 3.12+. + w.writer.WriteLine("class QueryResults[T]:") + w.writer.WriteQueryResultsClassDocstring(connType, driverReturnType) + w.writer.WriteIndentedLine(1, `__slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql")`) + w.writer.NewLine() + w.writer.WriteIndentedLine(1, "def __init__(") + w.writer.WriteIndentedLine(2, "self,") + w.writer.WriteIndentedLine(2, fmt.Sprintf("conn: %s,", connType)) + w.writer.WriteIndentedLine(2, "sql: str,") + w.writer.WriteIndentedLine(2, fmt.Sprintf("decode_hook: collections.abc.Callable[[%s], T],", driverReturnType)) + w.writer.WriteIndentedLine(2, "*args: QueryResultsArgsType,") + w.writer.WriteIndentedLine(1, ") -> None:") + w.writer.WriteQueryResultsInitDocstring(connType, driverReturnType) + w.writer.WriteIndentedLine(2, "self._conn = conn") + w.writer.WriteIndentedLine(2, "self._sql = sql") + w.writer.WriteIndentedLine(2, "self._decode_hook = decode_hook") + w.writer.WriteIndentedLine(2, "self._args = args") + for _, line := range initFields { + w.writer.WriteIndentedLine(2, line) + } + w.writer.NewLine() + + if async { + w.writer.WriteIndentedLine(1, "def __aiter__(self) -> QueryResults[T]:") + } else { + w.writer.WriteIndentedLine(1, "def __iter__(self) -> QueryResults[T]:") + } + w.writer.WriteQueryResultsIterDocstring(async) + w.writer.WriteIndentedLine(2, "return self") + w.writer.NewLine() +} + +// WriteQueryResultsCallFunction writes the synchronous __call__ method. +func (w *QueryResultsWriter) WriteQueryResultsCallFunction(wrapperLines []string) { + w.writer.WriteIndentedLine(1, "def __call__(") + w.writer.WriteIndentedLine(2, "self,") + w.writer.WriteIndentedLine(1, ") -> collections.abc.Sequence[T]:") + w.writer.WriteQueryResultsFetchDocstring(false) + for _, line := range wrapperLines { + w.writer.WriteIndentedLine(2, line) + } +} + +// WriteQueryResultsAwaitFunction writes the async __await__ method. +func (w *QueryResultsWriter) WriteQueryResultsAwaitFunction(wrapperLines []string) { + w.writer.WriteIndentedLine(1, "def __await__(") + w.writer.WriteIndentedLine(2, "self,") + w.writer.WriteIndentedLine(1, ") -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]:") + w.writer.WriteQueryResultsFetchDocstring(true) + if w.writer.DocstringsEnabled() { + w.writer.NewLine() + } + w.writer.WriteIndentedLine(2, "async def _wrapper() -> collections.abc.Sequence[T]:") + for _, line := range wrapperLines { + w.writer.WriteIndentedLine(3, line) + } + w.writer.NewLine() + w.writer.WriteIndentedLine(2, "return _wrapper().__await__()") +} diff --git a/internal/writer/writer.go b/internal/writer/writer.go new file mode 100644 index 00000000..5116fae5 --- /dev/null +++ b/internal/writer/writer.go @@ -0,0 +1,160 @@ +package writer + +import ( + "cmp" + "fmt" + "os" + "slices" + "strings" + + "github.com/rayakame/sqlc-gen-better-python/internal/config" + "github.com/rayakame/sqlc-gen-better-python/internal/model" + "github.com/rayakame/sqlc-gen-better-python/internal/utils" +) + +type CodeWriter struct { + QueryResults *QueryResultsWriter + + builder strings.Builder + + indentChar string + charsPerIndentLevel int + + docstringOmitSQL bool + docstringConvention config.DocstringConvention + docstringDriver config.SQLDriver + + omitTypeChecking bool +} + +func NewCodeWriter( + config *config.Config, +) *CodeWriter { + w := utils.ToPtr(CodeWriter{ + builder: strings.Builder{}, + indentChar: config.IndentChar, + charsPerIndentLevel: config.CharsPerIndentLevel, + docstringConvention: config.EmitDocstrings, + docstringDriver: config.SqlDriver, + docstringOmitSQL: !*config.EmitDocstringsSQL, + omitTypeChecking: config.OmitTypecheckingBlock, + QueryResults: nil, + }) + w.QueryResults = NewQueryResultsWriter(w) + return w +} + +// WriteIndentedString writes indented text without a trailing newline. +func (w *CodeWriter) WriteIndentedString(level int, txt string) { + w.WriteString(w.indent(level) + txt) +} + +// WriteLine writes text followed by a newline. +func (w *CodeWriter) WriteLine(txt string) { + w.WriteString(txt) + w.WriteString("\n") +} + +// WriteIndentedLine writes indented text followed by a newline. +func (w *CodeWriter) WriteIndentedLine(level int, txt string) { + w.WriteIndentedString(level, txt) + w.WriteString("\n") +} + +// NewLine writes a single newline. +func (w *CodeWriter) NewLine() { + w.WriteString("\n") +} + +// NNewLine writes n newlines. +func (w *CodeWriter) NNewLine(n int) { + for range n { + w.WriteString("\n") + } +} + +// WriteSqlcHeader writes the "generated by sqlc" comment block. +func (w *CodeWriter) WriteSqlcHeader(query *model.Query) { + sqlcVersion := os.Getenv("SQLC_VERSION") + + w.WriteLine("# Code generated by sqlc. DO NOT EDIT.") + w.WriteLine("# versions:") + w.WriteLine("# sqlc " + sqlcVersion) + w.WriteLine("# sqlc-gen-better-python " + config.PluginVersion) + if query != nil { + w.WriteLine("# source file: " + query.FileName) + } +} + +// WriteFutureImport writes the future-annotations import that follows the +// header (and module docstring, if any). +func (w *CodeWriter) WriteFutureImport() { + w.WriteLine("from __future__ import annotations") + w.NewLine() +} + +func (w *CodeWriter) WriteString(txt string) { + // strings.Builder.WriteString is documented to always return a nil error. + w.builder.WriteString(txt) //nolint:errcheck // never returns an error +} + +func (w *CodeWriter) Bytes() []byte { + return []byte(w.builder.String()) +} + +func (w *CodeWriter) String() string { + return w.builder.String() +} + +func (w *CodeWriter) WriteAll(items []string) { + slices.SortFunc(items, cmp.Compare) + if len(items) == 0 { + w.WriteLine(`__all__: collections.abc.Sequence[str] = ()`) + + return + } + // A single-element tuple's trailing comma is required syntax, so ruff + // format collapses it onto one line; match that. + if len(items) == 1 { + w.WriteLine(fmt.Sprintf(`__all__: collections.abc.Sequence[str] = ("%s",)`, items[0])) + + return + } + w.WriteLine("__all__: collections.abc.Sequence[str] = (") + for _, item := range items { + w.WriteIndentedLine(1, fmt.Sprintf(`"%s",`, item)) + } + w.WriteLine(")") +} + +// MaxLineLength is the ruff line-length limit (ruff's maximum allowed value). +// Statements the generator would render longer than this are exploded with +// magic trailing commas so that ruff format leaves them untouched. +const MaxLineLength = 320 + +// FitsLine reports whether txt fits within MaxLineLength at the indent level. +func (w *CodeWriter) FitsLine(indent int, txt string) bool { + return len(w.indent(indent))+len(txt) <= MaxLineLength +} + +// WriteWrappedCall writes head+args+tail on a single line when it fits, +// otherwise one argument per line with trailing commas. head must end with +// the opening parenthesis, tail must start with the closing one. +func (w *CodeWriter) WriteWrappedCall(indent int, head string, args []string, tail string) { + single := head + strings.Join(args, ", ") + tail + if w.FitsLine(indent, single) { + w.WriteIndentedLine(indent, single) + + return + } + w.WriteIndentedLine(indent, head) + for _, arg := range args { + w.WriteIndentedLine(indent+1, arg+",") + } + w.WriteIndentedLine(indent, tail) +} + +// indent returns the indentation string for the given level. +func (w *CodeWriter) indent(level int) string { + return strings.Repeat(w.indentChar, level*w.charsPerIndentLevel) +} diff --git a/plugin/main.go b/plugin/main.go index 3abf2c95..015065ea 100644 --- a/plugin/main.go +++ b/plugin/main.go @@ -6,5 +6,5 @@ import ( ) func main() { - codegen.Run(python.Generate) + codegen.Run(python.Handler) } diff --git a/pyproject.toml b/pyproject.toml index 9903a715..e93d5654 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,13 +2,14 @@ name = "sqlc-gen-better-python" version = "0.1.0" description = "Add your description here" -requires-python = ">=3.10.0,<3.14.0" +requires-python = ">=3.12.0,<3.14.0" dependencies = [ "aiosqlite>=0.21.0", "asyncpg>=0.30.0", "attrs>=25.3.0", "ciso8601>=2.3.2", "msgspec>=0.19.0", + "pydantic>=2.9.0", ] [dependency-groups] @@ -41,7 +42,9 @@ ruff = [ ] [tool.pyright] -pythonVersion = "3.10" +# 3.12: generated code defaults to python_version 3.12 (PEP 695 type aliases). +# The 3.10-targeted fixture variants use string aliases valid under 3.12 too. +pythonVersion = "3.12" typeCheckingMode = "strict" reportUnnecessaryTypeIgnoreComment = "error" diff --git a/ruff.toml b/ruff.toml index 2f24a748..403f2ec7 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,5 +1,8 @@ -target-version = "py310" -line-length = 120 +# Generated code targets Python 3.12+ (PEP 695 type aliases and generics). +target-version = "py312" +# 320 is ruff's maximum. Generated code emits anything longer than this +# exploded with magic trailing commas, so ruff format is a no-op on it. +line-length = 320 [lint] preview = true @@ -40,6 +43,11 @@ ignore = [ "I001", # Import block is un-sorted or un-formatted "FBT001", # Boolean-typed positional argument in function definition ] +# With omit_typechecking_block the annotation-only imports are deliberately +# emitted at runtime so annotations stay introspectable. +"**/omit_tc/{classes,functions}/*.py" = [ + "TC003", # Move standard library import into a type-checking block +] "**/{msgspec}/{classes,functions}/*.py" = [ "DOC501", # Raised exception `StopIteration` missing from docstring # Ruff doesn't understand that we actually documented the exceptions raised when using pep257 @@ -53,8 +61,3 @@ force-single-line = true [lint.pydocstyle] convention = "numpy" -[format] -exclude = [ - "models.py", - "queries.py", -] \ No newline at end of file diff --git a/scripts/build/build.bat b/scripts/build/build.bat index b682aeb5..ba55bf71 100644 --- a/scripts/build/build.bat +++ b/scripts/build/build.bat @@ -1,36 +1,36 @@ @echo off setlocal EnableDelayedExpansion -REM ────────────────────────────── -REM 1) CONFIGURATION – add folders here +REM ------------------------------ +REM 1) CONFIGURATION - add folders here REM (paths are relative to repo root) -REM ────────────────────────────── +REM ------------------------------ set "TARGET_DIRS=test\driver_asyncpg test\driver_aiosqlite test\driver_sqlite3" set "SQLC_CONFIG_NAMES=sqlc.yaml" -REM ────────────────────────────── +REM ------------------------------ REM 2) BUILD THE WASM PLUGIN -REM ────────────────────────────── +REM ------------------------------ echo === Building the Go WASM plugin ================================= set GOOS=wasip1 set GOARCH=wasm go build -o sqlc-gen-better-python.wasm plugin/main.go -REM ────────────────────────────── -REM 3) CALCULATE SHA‑256 -REM ────────────────────────────── +REM ------------------------------ +REM 3) CALCULATE SHA-256 +REM ------------------------------ for /f %%i in ('certutil -hashfile sqlc-gen-better-python.wasm SHA256 ^| findstr /v "hash"') do set "SHA256_HASH=%%i" echo SHA-256: %SHA256_HASH% -REM ────────────────────────────── +REM ------------------------------ REM 4) UPDATE ROOT yaml -REM ────────────────────────────── +REM ------------------------------ powershell -Command "(Get-Content sqlc.yaml) -replace '(?<=sha256: )\S+', '%SHA256_HASH%' | Set-Content sqlc.yaml" -REM ────────────────────────────── +REM ------------------------------ REM 5) PROPAGATE TO TARGET FOLDERS -REM ────────────────────────────── +REM ------------------------------ for %%D in (%TARGET_DIRS%) do ( echo -------------------------------------------------------------- echo Processing %%D @@ -42,7 +42,7 @@ for %%D in (%TARGET_DIRS%) do ( REM Copy the plugin xcopy /Y /Q "sqlc-gen-better-python.wasm" "%%D\" - REM Patch that folder’s yaml in place + REM Patch that folder's yaml in place for %%F in (%SQLC_CONFIG_NAMES%) do ( powershell -Command "(Get-Content '%%D\\%%F') -replace '(?<=sha256: )\S+', '%SHA256_HASH%' | Set-Content '%%D\\%%F'" ) diff --git a/scripts/build/build.sh b/scripts/build/build.sh index 523b0703..bcc4a4ad 100644 --- a/scripts/build/build.sh +++ b/scripts/build/build.sh @@ -1,35 +1,35 @@ #!/bin/bash set -euo pipefail -# ────────────────────────────── +# ------------------------------ # 1) CONFIGURATION -# ────────────────────────────── -TARGET_DIRS=("test/driver_asyncpg", "test\driver_aiosqlite", "test\driver_sqlite3") +# ------------------------------ +TARGET_DIRS=("test/driver_asyncpg" "test/driver_aiosqlite" "test/driver_sqlite3") SQLC_CONFIG_NAMES=("sqlc.yaml") -# ────────────────────────────── +# ------------------------------ # 2) BUILD THE WASM PLUGIN -# ────────────────────────────── +# ------------------------------ echo "=== Building the Go WASM plugin =================================" export GOOS=wasip1 export GOARCH=wasm go build -o sqlc-gen-better-python.wasm plugin/main.go -# ────────────────────────────── -# 3) CALCULATE SHA‑256 -# ────────────────────────────── +# ------------------------------ +# 3) CALCULATE SHA-256 +# ------------------------------ SHA256_HASH=$(sha256sum sqlc-gen-better-python.wasm | awk '{print $1}') echo "SHA-256: $SHA256_HASH" -# ────────────────────────────── +# ------------------------------ # 4) UPDATE ROOT yaml -# ────────────────────────────── +# ------------------------------ echo "Patching root sqlc.yaml..." sed -i -E "s/(sha256: )\S+/\1$SHA256_HASH/" sqlc.yaml -# ────────────────────────────── +# ------------------------------ # 5) PROPAGATE TO TARGET FOLDERS -# ────────────────────────────── +# ------------------------------ for dir in "${TARGET_DIRS[@]}"; do echo "--------------------------------------------------------------" echo " Processing $dir" diff --git a/sqlc.yaml b/sqlc.yaml index a8e10ce5..e0e5216d 100644 --- a/sqlc.yaml +++ b/sqlc.yaml @@ -3,7 +3,7 @@ plugins: - name: python wasm: url: file://sqlc-gen-better-python.wasm - sha256: ee7bd0c07b784b80ea8c5853d9a6a04c51a7abbfd2663f470e9a5d2f623b967e + sha256: 0d564b87865b4733c9a41bd318277973c130fc02c32b5bfdb2a0b662f36148da sql: - schema: test/schema.sql queries: test/queries.sql @@ -20,15 +20,14 @@ sql: emit_init_file: false debug: true docstrings: numpy + omit_typechecking_block: false overrides: - - db_type: serial + - column: authors.bio py_type: - import: test - package: test_type - type: test_type.Test - - column: test_inner_postgres_types.bool_test + import: collections + package: UserString + type: UserString + - db_type: pg_catalog.numeric py_type: - import: test - package: test_type - type: test_type.Test + type: float diff --git a/test/conftest.py b/test/conftest.py index e3d70ea0..6e3d4afe 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -81,6 +81,7 @@ async def asyncpg_conn( DELETE FROM test_postgres_types; DELETE FROM test_inner_postgres_types; DELETE FROM test_copy_from; + DELETE FROM test_copy_override; """) await conn.close() @@ -95,7 +96,7 @@ def sqlite3_conn( conn.commit() yield conn - conn.executescript("""DELETE FROM test_sqlite_types;DELETE FROM test_inner_sqlite_types;""") + conn.executescript("DELETE FROM test_sqlite_types;DELETE FROM test_inner_sqlite_types;DELETE FROM test_override_conversion;DELETE FROM test_type_override;DELETE FROM test_case_sensitivity;DELETE FROM test_reserved_args;") conn.commit() conn.close() @@ -110,9 +111,7 @@ async def aiosqlite_conn( await conn.commit() yield conn - await conn.executescript( - """DELETE FROM test_sqlite_types;DELETE FROM test_inner_sqlite_types;DELETE FROM test_type_override;""" - ) + await conn.executescript("""DELETE FROM test_sqlite_types;DELETE FROM test_inner_sqlite_types;DELETE FROM test_type_override;""") await conn.commit() await conn.close() @@ -124,6 +123,7 @@ async def asyncpg_delete_all(dsn: str) -> None: DELETE FROM test_postgres_types; DELETE FROM test_inner_postgres_types; DELETE FROM test_copy_from; + DROP TABLE IF EXISTS test_copy_override; """) await conn.close() @@ -131,10 +131,17 @@ async def asyncpg_delete_all(dsn: str) -> None: async def aiosqlite_delete_all(dsn: str) -> None: conn = await aiosqlite.connect(dsn, detect_types=sqlite3.PARSE_DECLTYPES) + # DROP IF EXISTS: these tables only exist once the sqlite3 driver schema + # ran, and the schema recreates them (IF NOT EXISTS) on the next run. + # Without this an aborted run leaves the fixed-id rows behind and the next + # run fails with an IntegrityError. await conn.executescript(""" DELETE FROM test_sqlite_types; DELETE FROM test_inner_sqlite_types; DELETE FROM test_type_override; + DROP TABLE IF EXISTS test_override_conversion; + DROP TABLE IF EXISTS test_case_sensitivity; + DROP TABLE IF EXISTS test_reserved_args; """) await conn.commit() await conn.close() diff --git a/test/driver_aiosqlite/attrs/classes/__init__.py b/test/driver_aiosqlite/attrs/classes/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_aiosqlite/attrs/classes/__init__.py +++ b/test/driver_aiosqlite/attrs/classes/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_aiosqlite/attrs/classes/models.py b/test/driver_aiosqlite/attrs/classes/models.py index 36327a67..988c54ce 100644 --- a/test/driver_aiosqlite/attrs/classes/models.py +++ b/test/driver_aiosqlite/attrs/classes/models.py @@ -1,8 +1,9 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -96,7 +97,7 @@ class TestSqliteType: Attributes ---------- - id : int + id_ : int int_test : int bigint_test : int smallint_test : int @@ -128,7 +129,7 @@ class TestSqliteType: """ - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -165,10 +166,10 @@ class TestTypeOverride: Attributes ---------- - id : int + id_ : int text_test : UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_aiosqlite/attrs/classes/queries.py b/test/driver_aiosqlite/attrs/classes/queries.py index ebe8e26a..2729924f 100644 --- a/test/driver_aiosqlite/attrs/classes/queries.py +++ b/test/driver_aiosqlite/attrs/classes/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -22,7 +24,7 @@ import collections.abc import sqlite3 - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None from test.driver_aiosqlite.attrs.classes import models @@ -82,71 +84,74 @@ def _convert_memoryview(val: bytes) -> memoryview: aiosqlite.register_converter("blob", _convert_memoryview) -CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows -CREATE TABLE test_create_rows_table -( - id int PRIMARY KEY NOT NULL, - test int NOT NULL -) -""" - -DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec -DELETE FROM test_inner_sqlite_types -WHERE test_inner_sqlite_types.table_id = ? +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ -DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? """ -DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec -DELETE -FROM test_type_override -WHERE test_type_override.id = ? +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ -GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many -SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many @@ -157,67 +162,46 @@ def _convert_memoryview(val: bytes) -> memoryview: SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? """ -GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? -""" - -GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? -""" - -GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? -""" - -GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? -""" - -GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one -SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? -""" - -GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one -SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = ? +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? """ -INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -232,37 +216,19 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec -INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? """ -INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec -INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -277,7 +243,27 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -292,35 +278,48 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec INSERT INTO test_type_override ( id, text_test ) VALUES (? ,?) """ -UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? """ -UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? """ -UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? """ +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" -T = typing.TypeVar("T") +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db. Parameters @@ -373,9 +372,11 @@ def __await__( collections.abc.Sequence[T] A sequence of decoded objects of type `T`. """ + async def _wrapper() -> collections.abc.Sequence[T]: result = await (await self._conn.execute(self._sql, self._args)).fetchall() return [self._decode_hook(row) for row in result] + return _wrapper().__await__() async def __anext__(self) -> T: @@ -430,300 +431,240 @@ def conn(self) -> aiosqlite.Connection: """ return self._conn - async def create_rows_table(self) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + async def insert_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Returns - ------- - int - The number of affected rows. This will be -1 for queries like `CREATE TABLE`. - - """ - return (await self._conn.execute(CREATE_ROWS_TABLE)).rowcount - - async def delete_last_id_one_sqlite_type(self, id_: int) -> int | None: - """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - id_ : int - - Returns - ------- - int | None - The id of the last affected row. Will be `None` if no rows are affected. - - """ - return (await self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid - - async def delete_one_sqlite_type(self, id_: int) -> None: - """Execute SQL query with `name: DeleteOneSqliteType :exec`. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - id_ : int - - """ - await self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, )) - - async def delete_one_test_inner_sqlite_type(self, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. - - ```sql - DELETE FROM test_inner_sqlite_types - WHERE test_inner_sqlite_types.table_id = ? - ``` - - Parameters - ---------- - table_id : int - - """ - await self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, )) - - async def delete_result_one_sqlite_type(self, id_: int) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - id_ : int - - Returns - ------- - aiosqlite.Cursor - The result returned when executing the query. - - """ - return await self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, )) - - async def delete_rows_one_sqlite_type(self, id_: int) -> int: - """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - id_ : int - - Returns - ------- - int - The number of affected rows. This will be -1 for queries like `CREATE TABLE`. - - """ - return (await self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount - - async def delete_type_override(self, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. - - ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = ? - ``` - - Parameters - ---------- - id_ : int - - """ - await self._conn.execute(DELETE_TYPE_OVERRIDE, (id_, )) - - def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. - - ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Parameters ---------- id_ : int + int_test : int + bigint_test : int + smallint_test : int + tinyint_test : int + int2_test : int + int8_test : int + bigserial_test : int blob_test : memoryview - - Returns - ------- - QueryResults[memoryview] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[memoryview](self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) - - def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBool :many`. - - ```sql - SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? - ``` - - Parameters - ---------- - id_ : int - bool_test : bool - - Returns - ------- - QueryResults[bool] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[bool](self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) - - def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. - - ```sql - SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? - ``` - - Parameters - ---------- - id_ : int + real_test : float + double_test : float + double_precision_test : float + float_test : float + numeric_test : float + decimal_test : decimal.Decimal boolean_test : bool - - Returns - ------- - QueryResults[bool] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[bool](self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) - - def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: - """Fetch many from the db using the SQL query with `name: GetManyDate :many`. - - ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? - ``` - - Parameters - ---------- - id_ : int + bool_test : bool date_test : datetime.date - - Returns - ------- - QueryResults[datetime.date] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[datetime.date](self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) - - def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. - - ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? - ``` - - Parameters - ---------- - id_ : int datetime_test : datetime.datetime - - Returns - ------- - QueryResults[datetime.datetime] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) - - def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: - """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. - - ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? - ``` - - Parameters - ---------- - id_ : int - decimal_test : decimal.Decimal - - Returns - ------- - QueryResults[decimal.Decimal] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[decimal.Decimal](self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) - - def get_many_inner_sqlite_type(self, table_id: int) -> QueryResults[models.TestInnerSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? - ``` - - Parameters - ---------- - table_id : int - - Returns - ------- - QueryResults[models.TestInnerSqliteType] - Helper class that allows both iteration and normal fetching of data from the db. + timestamp_test : datetime.datetime + character_test : str + varchar_test : str + varyingcharacter_test : str + nchar_test : str + nativecharacter_test : str + nvarchar_test : str + text_test : str + clob_test : str + json_test : str """ - def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await self._conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) - def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. + async def insert_one_inner_sqlite_type( + self, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, + ) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Parameters ---------- table_id : int int_test : int | None - - Returns - ------- - QueryResults[models.TestInnerSqliteType] - Helper class that allows both iteration and normal fetching of data from the db. + bigint_test : int | None + smallint_test : int | None + tinyint_test : int | None + int2_test : int | None + int8_test : int | None + bigserial_test : int | None + blob_test : memoryview | None + real_test : float | None + double_test : float | None + double_precision_test : float | None + float_test : float | None + numeric_test : float | None + decimal_test : decimal.Decimal | None + boolean_test : bool | None + bool_test : bool | None + date_test : datetime.date | None + datetime_test : datetime.datetime | None + timestamp_test : datetime.datetime | None + character_test : str | None + varchar_test : str | None + varyingcharacter_test : str | None + nchar_test : str | None + nativecharacter_test : str | None + nvarchar_test : str | None + text_test : str | None + clob_test : str | None + json_test : str | None """ - def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) - def get_many_sqlite_type(self, id_: int) -> QueryResults[models.TestSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. + async def get_one_sqlite_type(self, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. ```sql SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? @@ -735,95 +676,162 @@ def get_many_sqlite_type(self, id_: int) -> QueryResults[models.TestSqliteType]: Returns ------- - QueryResults[models.TestSqliteType] - Helper class that allows both iteration and normal fetching of data from the db. + models.TestSqliteType + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestSqliteType](self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + row = await (await self._conn.execute(GET_ONE_SQLITE_TYPE, (id_,))).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) - def get_many_text_type_override(self, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + async def get_one_inner_sqlite_type(self, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Parameters ---------- - id_ : int + table_id : int Returns ------- - QueryResults[UserString] - Helper class that allows both iteration and normal fetching of data from the db. + models.TestInnerSqliteType + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> UserString: - return UserString(row[0]) - return QueryResults[UserString](self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + row = await (await self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,))).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) - def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. + async def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Parameters ---------- id_ : int - timestamp_test : datetime.datetime + date_test : datetime.date Returns ------- - QueryResults[datetime.datetime] - Helper class that allows both iteration and normal fetching of data from the db. + datetime.date + Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) + row = await (await self._conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_type_override(self, id_: int) -> QueryResults[models.TestTypeOverride]: - """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. + async def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. ```sql - SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Parameters ---------- id_ : int + datetime_test : datetime.datetime Returns ------- - QueryResults[models.TestTypeOverride] - Helper class that allows both iteration and normal fetching of data from the db. + datetime.datetime + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - return QueryResults[models.TestTypeOverride](self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + row = await (await self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() + if row is None: + return None + return row[0] - async def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. + async def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Parameters ---------- id_ : int - blob_test : memoryview + timestamp_test : datetime.datetime Returns ------- - memoryview + datetime.datetime Result fetched from the db. Will be `None` if not found. """ - row = await (await self._conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone() + row = await (await self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() if row is None: return None return row[0] @@ -874,77 +882,107 @@ async def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: return None return row[0] - async def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: - """Fetch one from the db using the SQL query with `name: GetOneDate :one`. + async def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Parameters ---------- id_ : int - date_test : datetime.date + decimal_test : decimal.Decimal Returns ------- - datetime.date + decimal.Decimal Result fetched from the db. Will be `None` if not found. """ - row = await (await self._conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() + row = await (await self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() if row is None: return None return row[0] - async def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. + async def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Parameters ---------- id_ : int - datetime_test : datetime.datetime + blob_test : memoryview Returns ------- - datetime.datetime + memoryview Result fetched from the db. Will be `None` if not found. """ - row = await (await self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() + row = await (await self._conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone() if row is None: return None return row[0] - async def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: - """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. + def get_many_sqlite_type(self, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Parameters ---------- id_ : int - decimal_test : decimal.Decimal Returns ------- - decimal.Decimal - Result fetched from the db. Will be `None` if not found. + QueryResults[models.TestSqliteType] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() - if row is None: - return None - return row[0] - async def get_one_inner_sqlite_type(self, table_id: int) -> models.TestInnerSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + + def get_many_inner_sqlite_type(self, table_id: int) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. ```sql SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? @@ -956,61 +994,142 @@ async def get_one_inner_sqlite_type(self, table_id: int) -> models.TestInnerSqli Returns ------- - models.TestInnerSqliteType - Result fetched from the db. Will be `None` if not found. + QueryResults[models.TestInnerSqliteType] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id, ))).fetchone() - if row is None: - return None - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - async def get_one_sqlite_type(self, id_: int) -> models.TestSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + + def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? + ``` + + Parameters + ---------- + table_id : int + int_test : int | None + + Returns + ------- + QueryResults[models.TestInnerSqliteType] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + + def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. + + ```sql + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Parameters ---------- id_ : int + date_test : datetime.date Returns ------- - models.TestSqliteType - Result fetched from the db. Will be `None` if not found. + QueryResults[datetime.date] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_SQLITE_TYPE, (id_, ))).fetchone() - if row is None: - return None - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) - async def get_one_text_type_override(self, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Parameters ---------- id_ : int + datetime_test : datetime.datetime Returns ------- - UserString - Result fetched from the db. Will be `None` if not found. + QueryResults[datetime.datetime] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_, ))).fetchone() - if row is None: - return None - return UserString(row[0]) + return QueryResults(self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) - async def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. + def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. ```sql SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? @@ -1023,150 +1142,157 @@ async def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime Returns ------- - datetime.datetime - Result fetched from the db. Will be `None` if not found. + QueryResults[datetime.datetime] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - async def get_one_type_override(self, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = ? + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? ``` Parameters ---------- id_ : int + bool_test : bool Returns ------- - models.TestTypeOverride - Result fetched from the db. Will be `None` if not found. + QueryResults[bool] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_, ))).fetchone() - if row is None: - return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) + return QueryResults(self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) - async def insert_last_id_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int | None: - """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. + def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. ```sql - INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? ``` Parameters ---------- id_ : int - int_test : int - bigint_test : int - smallint_test : int - tinyint_test : int - int2_test : int - int8_test : int - bigserial_test : int - blob_test : memoryview - real_test : float - double_test : float - double_precision_test : float - float_test : float - numeric_test : float - decimal_test : decimal.Decimal boolean_test : bool - bool_test : bool - date_test : datetime.date - datetime_test : datetime.datetime - timestamp_test : datetime.datetime - character_test : str - varchar_test : str - varyingcharacter_test : str - nchar_test : str - nativecharacter_test : str - nvarchar_test : str - text_test : str - clob_test : str - json_test : str Returns ------- - int | None - The id of the last affected row. Will be `None` if no rows are affected. + QueryResults[bool] + Helper class that allows both iteration and normal fetching of data from the db. """ - return (await self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test))).lastrowid + return QueryResults(self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) - async def insert_one_inner_sqlite_type(self, *, table_id: int, int_test: int | None, bigint_test: int | None, smallint_test: int | None, tinyint_test: int | None, int2_test: int | None, int8_test: int | None, bigserial_test: int | None, blob_test: memoryview | None, real_test: float | None, double_test: float | None, double_precision_test: float | None, float_test: float | None, numeric_test: float | None, decimal_test: decimal.Decimal | None, boolean_test: bool | None, bool_test: bool | None, date_test: datetime.date | None, datetime_test: datetime.datetime | None, timestamp_test: datetime.datetime | None, character_test: str | None, varchar_test: str | None, varyingcharacter_test: str | None, nchar_test: str | None, nativecharacter_test: str | None, nvarchar_test: str | None, text_test: str | None, clob_test: str | None, json_test: str | None) -> None: - """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. + def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. ```sql - INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Parameters ---------- - table_id : int - int_test : int | None - bigint_test : int | None - smallint_test : int | None - tinyint_test : int | None - int2_test : int | None - int8_test : int | None - bigserial_test : int | None - blob_test : memoryview | None - real_test : float | None - double_test : float | None - double_precision_test : float | None - float_test : float | None - numeric_test : float | None - decimal_test : decimal.Decimal | None - boolean_test : bool | None - bool_test : bool | None - date_test : datetime.date | None - datetime_test : datetime.datetime | None - timestamp_test : datetime.datetime | None - character_test : str | None - varchar_test : str | None - varyingcharacter_test : str | None - nchar_test : str | None - nativecharacter_test : str | None - nvarchar_test : str | None - text_test : str | None - clob_test : str | None - json_test : str | None + id_ : int + decimal_test : decimal.Decimal + + Returns + ------- + QueryResults[decimal.Decimal] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + return QueryResults(self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. + + ```sql + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + ``` + + Parameters + ---------- + id_ : int + blob_test : memoryview + + Returns + ------- + QueryResults[memoryview] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + return QueryResults(self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + + async def delete_one_sqlite_type(self, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int """ - await self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, (table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + await self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) - async def insert_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> None: - """Execute SQL query with `name: InsertOneSqliteType :exec`. + async def delete_one_test_inner_sqlite_type(self, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + + ```sql + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? + ``` + + Parameters + ---------- + table_id : int + + """ + await self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) + + async def insert_result_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. ```sql INSERT INTO test_sqlite_types ( @@ -1215,11 +1341,121 @@ async def insert_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: clob_test : str json_test : str + Returns + ------- + aiosqlite.Cursor + The result returned when executing the query. + """ - await self._conn.execute(INSERT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return await self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) - async def insert_result_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. + async def update_result_one_sqlite_type(self, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + aiosqlite.Cursor + The result returned when executing the query. + + """ + return await self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + async def delete_result_one_sqlite_type(self, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + aiosqlite.Cursor + The result returned when executing the query. + + """ + return await self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + async def insert_rows_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. ```sql INSERT INTO test_sqlite_types ( @@ -1270,14 +1506,138 @@ async def insert_result_one_sqlite_type(self, *, id_: int, int_test: int, bigint Returns ------- - aiosqlite.Cursor - The result returned when executing the query. + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - return await self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args)).rowcount - async def insert_rows_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int: - """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. + async def update_rows_one_sqlite_type(self, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + + """ + return (await self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + async def delete_rows_one_sqlite_type(self, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + + """ + return (await self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + async def create_rows_table(self) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Returns + ------- + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + + """ + return (await self._conn.execute(CREATE_ROWS_TABLE)).rowcount + + async def insert_last_id_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. ```sql INSERT INTO test_sqlite_types ( @@ -1329,10 +1689,83 @@ async def insert_rows_one_sqlite_type(self, *, id_: int, int_test: int, bigint_t Returns ------- int - The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + The id of the last affected row. Will be `None` if no rows are affected. + + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args)).lastrowid + + async def update_last_id_one_sqlite_type(self, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + int + The id of the last affected row. Will be `None` if no rows are affected. + + """ + return (await self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid + + async def delete_last_id_one_sqlite_type(self, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + int + The id of the last affected row. Will be `None` if no rows are affected. """ - return (await self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test))).rowcount + return (await self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid async def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: """Execute SQL query with `name: InsertTypeOverride :exec`. @@ -1349,15 +1782,13 @@ async def insert_type_override(self, *, id_: int, text_test: UserString | None) text_test : UserString | None """ - await self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test))) + await self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) - async def update_last_id_one_sqlite_type(self, id_: int) -> int | None: - """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + async def get_one_type_override(self, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE id = ? ``` Parameters @@ -1366,19 +1797,20 @@ async def update_last_id_one_sqlite_type(self, id_: int) -> int | None: Returns ------- - int | None - The id of the last affected row. Will be `None` if no rows are affected. + models.TestTypeOverride + Result fetched from the db. Will be `None` if not found. """ - return (await self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid + row = await (await self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - async def update_result_one_sqlite_type(self, id_: int) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + def get_many_type_override(self, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? ``` Parameters @@ -1387,19 +1819,21 @@ async def update_result_one_sqlite_type(self, id_: int) -> aiosqlite.Cursor: Returns ------- - aiosqlite.Cursor - The result returned when executing the query. + QueryResults[models.TestTypeOverride] + Helper class that allows both iteration and normal fetching of data from the db. """ - return await self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_, )) - async def update_rows_one_sqlite_type(self, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + async def get_one_text_type_override(self, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? ``` Parameters @@ -1408,8 +1842,50 @@ async def update_rows_one_sqlite_type(self, id_: int) -> int: Returns ------- - int - The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + UserString + Result fetched from the db. Will be `None` if not found. + + """ + row = await (await self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + def get_many_text_type_override(self, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + QueryResults[UserString | None] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + async def delete_type_override(self, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Parameters + ---------- + id_ : int """ - return (await self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount + await self._conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_aiosqlite/attrs/functions/__init__.py b/test/driver_aiosqlite/attrs/functions/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_aiosqlite/attrs/functions/__init__.py +++ b/test/driver_aiosqlite/attrs/functions/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_aiosqlite/attrs/functions/models.py b/test/driver_aiosqlite/attrs/functions/models.py index 36327a67..988c54ce 100644 --- a/test/driver_aiosqlite/attrs/functions/models.py +++ b/test/driver_aiosqlite/attrs/functions/models.py @@ -1,8 +1,9 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -96,7 +97,7 @@ class TestSqliteType: Attributes ---------- - id : int + id_ : int int_test : int bigint_test : int smallint_test : int @@ -128,7 +129,7 @@ class TestSqliteType: """ - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -165,10 +166,10 @@ class TestTypeOverride: Attributes ---------- - id : int + id_ : int text_test : UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_aiosqlite/attrs/functions/queries.py b/test/driver_aiosqlite/attrs/functions/queries.py index 3860631e..bc72c6bd 100644 --- a/test/driver_aiosqlite/attrs/functions/queries.py +++ b/test/driver_aiosqlite/attrs/functions/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -59,7 +61,7 @@ import collections.abc import sqlite3 - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None from test.driver_aiosqlite.attrs.functions import models @@ -119,71 +121,74 @@ def _convert_memoryview(val: bytes) -> memoryview: aiosqlite.register_converter("blob", _convert_memoryview) -CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows -CREATE TABLE test_create_rows_table -( - id int PRIMARY KEY NOT NULL, - test int NOT NULL -) -""" - -DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec -DELETE FROM test_inner_sqlite_types -WHERE test_inner_sqlite_types.table_id = ? +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ -DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? """ -DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec -DELETE -FROM test_type_override -WHERE test_type_override.id = ? +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ -GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many -SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many @@ -194,67 +199,46 @@ def _convert_memoryview(val: bytes) -> memoryview: SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? """ -GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? -""" - -GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? -""" - -GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? -""" - -GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? -""" - -GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one -SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? -""" - -GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one -SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = ? +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? """ -INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -269,37 +253,19 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec -INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? """ -INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec -INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -314,7 +280,27 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -329,35 +315,48 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec INSERT INTO test_type_override ( id, text_test ) VALUES (? ,?) """ -UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? """ -UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? """ -UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? """ +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" -T = typing.TypeVar("T") +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db. Parameters @@ -410,9 +409,11 @@ def __await__( collections.abc.Sequence[T] A sequence of decoded objects of type `T`. """ + async def _wrapper() -> collections.abc.Sequence[T]: result = await (await self._conn.execute(self._sql, self._args)).fetchall() return [self._decode_hook(row) for row in result] + return _wrapper().__await__() async def __anext__(self) -> T: @@ -440,62 +441,54 @@ async def __anext__(self) -> T: return self._decode_hook(record) -async def create_rows_table(conn: aiosqlite.Connection) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. +async def insert_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Parameters - ---------- - conn : aiosqlite.Connection - Connection object of type `aiosqlite.Connection` used to execute the query. - - Returns - ------- - int - The number of affected rows. This will be -1 for queries like `CREATE TABLE`. - - """ - return (await conn.execute(CREATE_ROWS_TABLE)).rowcount - - -async def delete_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: - """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - conn : aiosqlite.Connection - Connection object of type `aiosqlite.Connection` used to execute the query. - id_ : int - - Returns - ------- - int | None - The id of the last affected row. Will be `None` if no rows are affected. - - """ - return (await conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid - - -async def delete_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneSqliteType :exec`. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Parameters @@ -503,17 +496,118 @@ async def delete_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> Non conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int + int_test : int + bigint_test : int + smallint_test : int + tinyint_test : int + int2_test : int + int8_test : int + bigserial_test : int + blob_test : memoryview + real_test : float + double_test : float + double_precision_test : float + float_test : float + numeric_test : float + decimal_test : decimal.Decimal + boolean_test : bool + bool_test : bool + date_test : datetime.date + datetime_test : datetime.datetime + timestamp_test : datetime.datetime + character_test : str + varchar_test : str + varyingcharacter_test : str + nchar_test : str + nativecharacter_test : str + nvarchar_test : str + text_test : str + clob_test : str + json_test : str """ - await conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, )) - - -async def delete_one_test_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) + + +async def insert_one_inner_sqlite_type( + conn: aiosqlite.Connection, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, +) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. ```sql - DELETE FROM test_inner_sqlite_types - WHERE test_inner_sqlite_types.table_id = ? + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Parameters @@ -521,106 +615,75 @@ async def delete_one_test_inner_sqlite_type(conn: aiosqlite.Connection, *, table conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. table_id : int + int_test : int | None + bigint_test : int | None + smallint_test : int | None + tinyint_test : int | None + int2_test : int | None + int8_test : int | None + bigserial_test : int | None + blob_test : memoryview | None + real_test : float | None + double_test : float | None + double_precision_test : float | None + float_test : float | None + numeric_test : float | None + decimal_test : decimal.Decimal | None + boolean_test : bool | None + bool_test : bool | None + date_test : datetime.date | None + datetime_test : datetime.datetime | None + timestamp_test : datetime.datetime | None + character_test : str | None + varchar_test : str | None + varyingcharacter_test : str | None + nchar_test : str | None + nativecharacter_test : str | None + nvarchar_test : str | None + text_test : str | None + clob_test : str | None + json_test : str | None """ - await conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, )) - - -async def delete_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - conn : aiosqlite.Connection - Connection object of type `aiosqlite.Connection` used to execute the query. - id_ : int - - Returns - ------- - aiosqlite.Cursor - The result returned when executing the query. - - """ - return await conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, )) - - -async def delete_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: - """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - conn : aiosqlite.Connection - Connection object of type `aiosqlite.Connection` used to execute the query. - id_ : int - - Returns - ------- - int - The number of affected rows. This will be -1 for queries like `CREATE TABLE`. - - """ - return (await conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount - - -async def delete_type_override(conn: aiosqlite.Connection, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. - - ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = ? - ``` - - Parameters - ---------- - conn : aiosqlite.Connection - Connection object of type `aiosqlite.Connection` used to execute the query. - id_ : int - - """ - await conn.execute(DELETE_TYPE_OVERRIDE, (id_, )) - - -def get_many_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. - - ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? - ``` - - Parameters - ---------- - conn : aiosqlite.Connection - Connection object of type `aiosqlite.Connection` used to execute the query. - id_ : int - blob_test : memoryview - - Returns - ------- - QueryResults[memoryview] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[memoryview](conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) -def get_many_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBool :many`. +async def get_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. ```sql - SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Parameters @@ -628,42 +691,106 @@ def get_many_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> Q conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int - bool_test : bool Returns ------- - QueryResults[bool] - Helper class that allows both iteration and normal fetching of data from the db. + models.TestSqliteType + Result fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + row = await (await conn.execute(GET_ONE_SQLITE_TYPE, (id_,))).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) -def get_many_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. +async def get_one_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. ```sql - SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Parameters ---------- conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. - id_ : int - boolean_test : bool + table_id : int Returns ------- - QueryResults[bool] - Helper class that allows both iteration and normal fetching of data from the db. + models.TestInnerSqliteType + Result fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + row = await (await conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,))).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) -def get_many_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: - """Fetch many from the db using the SQL query with `name: GetManyDate :many`. +async def get_one_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. ```sql SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? @@ -678,15 +805,18 @@ def get_many_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.d Returns ------- - QueryResults[datetime.date] - Helper class that allows both iteration and normal fetching of data from the db. + datetime.date + Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.date](conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + row = await (await conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() + if row is None: + return None + return row[0] -def get_many_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. +async def get_one_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. ```sql SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? @@ -701,90 +831,21 @@ def get_many_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: da Returns ------- - QueryResults[datetime.datetime] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[datetime.datetime](conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) - - -def get_many_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: - """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. - - ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? - ``` - - Parameters - ---------- - conn : aiosqlite.Connection - Connection object of type `aiosqlite.Connection` used to execute the query. - id_ : int - decimal_test : decimal.Decimal - - Returns - ------- - QueryResults[decimal.Decimal] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[decimal.Decimal](conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) - - -def get_many_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? - ``` - - Parameters - ---------- - conn : aiosqlite.Connection - Connection object of type `aiosqlite.Connection` used to execute the query. - table_id : int - - Returns - ------- - QueryResults[models.TestInnerSqliteType] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) - - -def get_many_nullable_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? - ``` - - Parameters - ---------- - conn : aiosqlite.Connection - Connection object of type `aiosqlite.Connection` used to execute the query. - table_id : int - int_test : int | None - - Returns - ------- - QueryResults[models.TestInnerSqliteType] - Helper class that allows both iteration and normal fetching of data from the db. + datetime.datetime + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + row = await (await conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() + if row is None: + return None + return row[0] -def get_many_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. +async def get_one_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Parameters @@ -792,23 +853,25 @@ def get_many_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> QueryResult conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int + timestamp_test : datetime.datetime Returns ------- - QueryResults[models.TestSqliteType] - Helper class that allows both iteration and normal fetching of data from the db. + datetime.datetime + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestSqliteType](conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + row = await (await conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() + if row is None: + return None + return row[0] -def get_many_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. +async def get_one_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? ``` Parameters @@ -816,23 +879,25 @@ def get_many_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> Quer conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int + bool_test : bool Returns ------- - QueryResults[UserString] - Helper class that allows both iteration and normal fetching of data from the db. + bool + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> UserString: - return UserString(row[0]) - return QueryResults[UserString](conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + row = await (await conn.execute(GET_ONE_BOOL, (id_, bool_test))).fetchone() + if row is None: + return None + return row[0] -def get_many_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. +async def get_one_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? ``` Parameters @@ -840,22 +905,25 @@ def get_many_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int - timestamp_test : datetime.datetime + boolean_test : bool Returns ------- - QueryResults[datetime.datetime] - Helper class that allows both iteration and normal fetching of data from the db. + bool + Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.datetime](conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) + row = await (await conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test))).fetchone() + if row is None: + return None + return row[0] -def get_many_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: - """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. +async def get_one_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. ```sql - SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Parameters @@ -863,16 +931,18 @@ def get_many_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResu conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int + decimal_test : decimal.Decimal Returns ------- - QueryResults[models.TestTypeOverride] - Helper class that allows both iteration and normal fetching of data from the db. + decimal.Decimal + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - return QueryResults[models.TestTypeOverride](conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + row = await (await conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() + if row is None: + return None + return row[0] async def get_one_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: @@ -901,11 +971,11 @@ async def get_one_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memor return row[0] -async def get_one_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBool :one`. +def get_many_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. ```sql - SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Parameters @@ -913,48 +983,165 @@ async def get_one_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int - bool_test : bool Returns ------- - bool - Result fetched from the db. Will be `None` if not found. + QueryResults[models.TestSqliteType] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_BOOL, (id_, bool_test))).fetchone() - if row is None: - return None - return row[0] + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) -async def get_one_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. + +def get_many_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. ```sql - SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Parameters ---------- conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. - id_ : int - boolean_test : bool + table_id : int Returns ------- - bool - Result fetched from the db. Will be `None` if not found. + QueryResults[models.TestInnerSqliteType] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test))).fetchone() - if row is None: - return None - return row[0] + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) -async def get_one_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: - """Fetch one from the db using the SQL query with `name: GetOneDate :one`. +def get_many_nullable_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? + ``` + + Parameters + ---------- + conn : aiosqlite.Connection + Connection object of type `aiosqlite.Connection` used to execute the query. + table_id : int + int_test : int | None + + Returns + ------- + QueryResults[models.TestInnerSqliteType] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + + +def get_many_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. ```sql SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? @@ -969,18 +1156,15 @@ async def get_one_date(conn: aiosqlite.Connection, *, id_: int, date_test: datet Returns ------- - datetime.date - Result fetched from the db. Will be `None` if not found. + QueryResults[datetime.date] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) -async def get_one_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. +def get_many_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. ```sql SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? @@ -995,21 +1179,18 @@ async def get_one_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_tes Returns ------- - datetime.datetime - Result fetched from the db. Will be `None` if not found. + QueryResults[datetime.datetime] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) -async def get_one_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: - """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. +def get_many_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Parameters @@ -1017,50 +1198,45 @@ async def get_one_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int - decimal_test : decimal.Decimal + timestamp_test : datetime.datetime Returns ------- - decimal.Decimal - Result fetched from the db. Will be `None` if not found. + QueryResults[datetime.datetime] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) -async def get_one_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. +def get_many_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? ``` Parameters ---------- conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. - table_id : int + id_ : int + bool_test : bool Returns ------- - models.TestInnerSqliteType - Result fetched from the db. Will be `None` if not found. + QueryResults[bool] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id, ))).fetchone() - if row is None: - return None - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) -async def get_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> models.TestSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. +def get_many_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? ``` Parameters @@ -1068,24 +1244,22 @@ async def get_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> models conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int + boolean_test : bool Returns ------- - models.TestSqliteType - Result fetched from the db. Will be `None` if not found. + QueryResults[bool] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_SQLITE_TYPE, (id_, ))).fetchone() - if row is None: - return None - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) -async def get_one_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. +def get_many_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Parameters @@ -1093,24 +1267,22 @@ async def get_one_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int + decimal_test : decimal.Decimal Returns ------- - UserString - Result fetched from the db. Will be `None` if not found. + QueryResults[decimal.Decimal] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_, ))).fetchone() - if row is None: - return None - return UserString(row[0]) + return QueryResults(conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) -async def get_one_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. +def get_many_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Parameters @@ -1118,25 +1290,24 @@ async def get_one_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_t conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int - timestamp_test : datetime.datetime + blob_test : memoryview Returns ------- - datetime.datetime - Result fetched from the db. Will be `None` if not found. + QueryResults[memoryview] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) -async def get_one_type_override(conn: aiosqlite.Connection, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. +async def delete_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = ? + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? ``` Parameters @@ -1145,20 +1316,62 @@ async def get_one_type_override(conn: aiosqlite.Connection, *, id_: int) -> mode Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int - Returns - ------- - models.TestTypeOverride - Result fetched from the db. Will be `None` if not found. - """ - row = await (await conn.execute(GET_ONE_TYPE_OVERRIDE, (id_, ))).fetchone() - if row is None: - return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) + await conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) -async def insert_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int | None: - """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. +async def delete_one_test_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + + ```sql + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? + ``` + + Parameters + ---------- + conn : aiosqlite.Connection + Connection object of type `aiosqlite.Connection` used to execute the query. + table_id : int + + """ + await conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) + + +async def insert_result_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. ```sql INSERT INTO test_sqlite_types ( @@ -1211,71 +1424,126 @@ async def insert_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int Returns ------- - int | None - The id of the last affected row. Will be `None` if no rows are affected. + aiosqlite.Cursor + The result returned when executing the query. """ - return (await conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test))).lastrowid + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return await conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) -async def insert_one_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int, int_test: int | None, bigint_test: int | None, smallint_test: int | None, tinyint_test: int | None, int2_test: int | None, int8_test: int | None, bigserial_test: int | None, blob_test: memoryview | None, real_test: float | None, double_test: float | None, double_precision_test: float | None, float_test: float | None, numeric_test: float | None, decimal_test: decimal.Decimal | None, boolean_test: bool | None, bool_test: bool | None, date_test: datetime.date | None, datetime_test: datetime.datetime | None, timestamp_test: datetime.datetime | None, character_test: str | None, varchar_test: str | None, varyingcharacter_test: str | None, nchar_test: str | None, nativecharacter_test: str | None, nvarchar_test: str | None, text_test: str | None, clob_test: str | None, json_test: str | None) -> None: - """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. +async def update_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. ```sql - INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? ``` Parameters ---------- conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. - table_id : int - int_test : int | None - bigint_test : int | None - smallint_test : int | None - tinyint_test : int | None - int2_test : int | None - int8_test : int | None - bigserial_test : int | None - blob_test : memoryview | None - real_test : float | None - double_test : float | None - double_precision_test : float | None - float_test : float | None - numeric_test : float | None - decimal_test : decimal.Decimal | None - boolean_test : bool | None - bool_test : bool | None - date_test : datetime.date | None - datetime_test : datetime.datetime | None - timestamp_test : datetime.datetime | None - character_test : str | None - varchar_test : str | None - varyingcharacter_test : str | None - nchar_test : str | None - nativecharacter_test : str | None - nvarchar_test : str | None - text_test : str | None - clob_test : str | None - json_test : str | None + id_ : int + + Returns + ------- + aiosqlite.Cursor + The result returned when executing the query. + + """ + return await conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +async def delete_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. - """ - await conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, (table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + Parameters + ---------- + conn : aiosqlite.Connection + Connection object of type `aiosqlite.Connection` used to execute the query. + id_ : int -async def insert_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> None: - """Execute SQL query with `name: InsertOneSqliteType :exec`. + Returns + ------- + aiosqlite.Cursor + The result returned when executing the query. + + """ + return await conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +async def insert_rows_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. ```sql INSERT INTO test_sqlite_types ( @@ -1326,26 +1594,53 @@ async def insert_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_te clob_test : str json_test : str + Returns + ------- + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ - await conn.execute(INSERT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args)).rowcount -async def insert_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. +async def update_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. ```sql - INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? ``` Parameters @@ -1353,46 +1648,99 @@ async def insert_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, conn : aiosqlite.Connection Connection object of type `aiosqlite.Connection` used to execute the query. id_ : int - int_test : int - bigint_test : int - smallint_test : int - tinyint_test : int - int2_test : int - int8_test : int - bigserial_test : int - blob_test : memoryview - real_test : float - double_test : float - double_precision_test : float - float_test : float - numeric_test : float - decimal_test : decimal.Decimal - boolean_test : bool - bool_test : bool - date_test : datetime.date - datetime_test : datetime.datetime - timestamp_test : datetime.datetime - character_test : str - varchar_test : str - varyingcharacter_test : str - nchar_test : str - nativecharacter_test : str - nvarchar_test : str - text_test : str - clob_test : str - json_test : str Returns ------- - aiosqlite.Cursor - The result returned when executing the query. + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - return await conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + return (await conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount -async def insert_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int: - """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. +async def delete_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + conn : aiosqlite.Connection + Connection object of type `aiosqlite.Connection` used to execute the query. + id_ : int + + Returns + ------- + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + + """ + return (await conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + +async def create_rows_table(conn: aiosqlite.Connection) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Parameters + ---------- + conn : aiosqlite.Connection + Connection object of type `aiosqlite.Connection` used to execute the query. + + Returns + ------- + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + + """ + return (await conn.execute(CREATE_ROWS_TABLE)).rowcount + + +async def insert_last_id_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. ```sql INSERT INTO test_sqlite_types ( @@ -1446,10 +1794,89 @@ async def insert_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, i Returns ------- int - The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + The id of the last affected row. Will be `None` if no rows are affected. """ - return (await conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test))).rowcount + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args)).lastrowid + + +async def update_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + conn : aiosqlite.Connection + Connection object of type `aiosqlite.Connection` used to execute the query. + id_ : int + + Returns + ------- + int + The id of the last affected row. Will be `None` if no rows are affected. + + """ + return (await conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid + + +async def delete_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + conn : aiosqlite.Connection + Connection object of type `aiosqlite.Connection` used to execute the query. + id_ : int + + Returns + ------- + int + The id of the last affected row. Will be `None` if no rows are affected. + + """ + return (await conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid async def insert_type_override(conn: aiosqlite.Connection, *, id_: int, text_test: UserString | None) -> None: @@ -1469,16 +1896,14 @@ async def insert_type_override(conn: aiosqlite.Connection, *, id_: int, text_tes text_test : UserString | None """ - await conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test))) + await conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) -async def update_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: - """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. +async def get_one_type_override(conn: aiosqlite.Connection, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE id = ? ``` Parameters @@ -1489,20 +1914,21 @@ async def update_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int Returns ------- - int | None - The id of the last affected row. Will be `None` if no rows are affected. + models.TestTypeOverride + Result fetched from the db. Will be `None` if not found. """ - return (await conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid + row = await (await conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) -async def update_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. +def get_many_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? ``` Parameters @@ -1513,20 +1939,22 @@ async def update_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) Returns ------- - aiosqlite.Cursor - The result returned when executing the query. + QueryResults[models.TestTypeOverride] + Helper class that allows both iteration and normal fetching of data from the db. """ - return await conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_, )) + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) -async def update_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + +async def get_one_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? ``` Parameters @@ -1537,8 +1965,56 @@ async def update_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) - Returns ------- - int - The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + UserString + Result fetched from the db. Will be `None` if not found. + + """ + row = await (await conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + +def get_many_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Parameters + ---------- + conn : aiosqlite.Connection + Connection object of type `aiosqlite.Connection` used to execute the query. + id_ : int + + Returns + ------- + QueryResults[UserString | None] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + +async def delete_type_override(conn: aiosqlite.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Parameters + ---------- + conn : aiosqlite.Connection + Connection object of type `aiosqlite.Connection` used to execute the query. + id_ : int """ - return (await conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount + await conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_aiosqlite/attrs/test_aiosqlite_attrs_classes.py b/test/driver_aiosqlite/attrs/test_aiosqlite_attrs_classes.py index b1898ea5..a57e1ea0 100644 --- a/test/driver_aiosqlite/attrs/test_aiosqlite_attrs_classes.py +++ b/test/driver_aiosqlite/attrs/test_aiosqlite_attrs_classes.py @@ -39,12 +39,12 @@ class TestAttrsClasses: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestSqliteType: return models.TestSqliteType( - id=random.randint(1, 10000000), + id_=random.randint(1, 10000000), int_test=42, bigint_test=9_007_199_254_740_991, smallint_test=32_767, @@ -78,7 +78,7 @@ def model(self) -> models.TestSqliteType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: return models.TestInnerSqliteType( - table_id=model.id, + table_id=model.id_, int_test=None, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -125,7 +125,7 @@ async def test_insert( model: models.TestSqliteType, ) -> None: await queries_obj.insert_one_sqlite_type( - id_=model.id, + id_=model.id_, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -157,9 +157,7 @@ async def test_insert( ) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::inner_insert", depends=["AiosqliteTestAttrsClasses::insert"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::inner_insert", depends=["AiosqliteTestAttrsClasses::insert"]) async def test_inner_insert( self, queries_obj: queries.Queries, @@ -198,15 +196,13 @@ async def test_inner_insert( ) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_one", depends=["AiosqliteTestAttrsClasses::inner_insert"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_one", depends=["AiosqliteTestAttrsClasses::inner_insert"]) async def test_get_one( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_sqlite_type(id_=model.id) + result = await queries_obj.get_one_sqlite_type(id_=model.id_) assert result is not None @@ -215,9 +211,7 @@ async def test_get_one( assert result == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_one_none", depends=["AiosqliteTestAttrsClasses::get_one"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_one_none", depends=["AiosqliteTestAttrsClasses::get_one"]) async def test_get_one_none( self, queries_obj: queries.Queries, @@ -227,9 +221,7 @@ async def test_get_one_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_one_inner", depends=["AiosqliteTestAttrsClasses::get_one_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_one_inner", depends=["AiosqliteTestAttrsClasses::get_one_none"]) async def test_get_one_inner( self, queries_obj: queries.Queries, @@ -243,9 +235,7 @@ async def test_get_one_inner( assert result == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_one_inner_none", depends=["AiosqliteTestAttrsClasses::get_one_inner"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_one_inner_none", depends=["AiosqliteTestAttrsClasses::get_one_inner"]) async def test_get_one_inner_none( self, queries_obj: queries.Queries, @@ -255,15 +245,13 @@ async def test_get_one_inner_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_date", depends=["AiosqliteTestAttrsClasses::get_one_inner_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_date", depends=["AiosqliteTestAttrsClasses::get_one_inner_none"]) async def test_get_date( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_date(id_=model.id, date_test=model.date_test) + result = await queries_obj.get_one_date(id_=model.id_, date_test=model.date_test) assert result is not None @@ -271,9 +259,7 @@ async def test_get_date( assert result == model.date_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_date_none", depends=["AiosqliteTestAttrsClasses::get_date"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_date_none", depends=["AiosqliteTestAttrsClasses::get_date"]) async def test_get_date_none( self, queries_obj: queries.Queries, @@ -283,15 +269,13 @@ async def test_get_date_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_datetime", depends=["AiosqliteTestAttrsClasses::get_date_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_datetime", depends=["AiosqliteTestAttrsClasses::get_date_none"]) async def test_get_datetime( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_datetime(id_=model.id, datetime_test=model.datetime_test) + result = await queries_obj.get_one_datetime(id_=model.id_, datetime_test=model.datetime_test) assert result is not None @@ -299,9 +283,7 @@ async def test_get_datetime( assert result == model.datetime_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_datetime_none", depends=["AiosqliteTestAttrsClasses::get_datetime"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_datetime_none", depends=["AiosqliteTestAttrsClasses::get_datetime"]) async def test_get_datetime_none( self, queries_obj: queries.Queries, @@ -311,15 +293,13 @@ async def test_get_datetime_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_timestamp", depends=["AiosqliteTestAttrsClasses::get_datetime_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_timestamp", depends=["AiosqliteTestAttrsClasses::get_datetime_none"]) async def test_get_timestamp( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_timestamp(id_=model.id, timestamp_test=model.timestamp_test) + result = await queries_obj.get_one_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None @@ -327,9 +307,7 @@ async def test_get_timestamp( assert result == model.timestamp_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_timestamp_none", depends=["AiosqliteTestAttrsClasses::get_timestamp"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_timestamp_none", depends=["AiosqliteTestAttrsClasses::get_timestamp"]) async def test_get_timestamp_none( self, queries_obj: queries.Queries, @@ -339,15 +317,13 @@ async def test_get_timestamp_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_bool", depends=["AiosqliteTestAttrsClasses::get_timestamp_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_bool", depends=["AiosqliteTestAttrsClasses::get_timestamp_none"]) async def test_get_bool( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_bool(id_=model.id, bool_test=model.bool_test) + result = await queries_obj.get_one_bool(id_=model.id_, bool_test=model.bool_test) assert result is not None @@ -355,9 +331,7 @@ async def test_get_bool( assert result == model.bool_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_bool_none", depends=["AiosqliteTestAttrsClasses::get_bool"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_bool_none", depends=["AiosqliteTestAttrsClasses::get_bool"]) async def test_get_bool_none( self, queries_obj: queries.Queries, @@ -367,15 +341,13 @@ async def test_get_bool_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_boolean", depends=["AiosqliteTestAttrsClasses::get_bool_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_boolean", depends=["AiosqliteTestAttrsClasses::get_bool_none"]) async def test_get_boolean( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_boolean(id_=model.id, boolean_test=model.boolean_test) + result = await queries_obj.get_one_boolean(id_=model.id_, boolean_test=model.boolean_test) assert result is not None @@ -383,9 +355,7 @@ async def test_get_boolean( assert result == model.boolean_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_boolean_none", depends=["AiosqliteTestAttrsClasses::get_boolean"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_boolean_none", depends=["AiosqliteTestAttrsClasses::get_boolean"]) async def test_get_boolean_none( self, queries_obj: queries.Queries, @@ -395,15 +365,13 @@ async def test_get_boolean_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_decimal", depends=["AiosqliteTestAttrsClasses::get_boolean_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_decimal", depends=["AiosqliteTestAttrsClasses::get_boolean_none"]) async def test_get_decimal( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_decimal(id_=model.id, decimal_test=model.decimal_test) + result = await queries_obj.get_one_decimal(id_=model.id_, decimal_test=model.decimal_test) assert result is not None @@ -411,9 +379,7 @@ async def test_get_decimal( assert result == model.decimal_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_decimal_none", depends=["AiosqliteTestAttrsClasses::get_decimal"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_decimal_none", depends=["AiosqliteTestAttrsClasses::get_decimal"]) async def test_get_decimal_none( self, queries_obj: queries.Queries, @@ -423,15 +389,13 @@ async def test_get_decimal_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_blob", depends=["AiosqliteTestAttrsClasses::get_decimal_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_blob", depends=["AiosqliteTestAttrsClasses::get_decimal_none"]) async def test_get_blob( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_blob(id_=model.id, blob_test=model.blob_test) + result = await queries_obj.get_one_blob(id_=model.id_, blob_test=model.blob_test) assert result is not None @@ -439,9 +403,7 @@ async def test_get_blob( assert result == model.blob_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_blob_none", depends=["AiosqliteTestAttrsClasses::get_blob"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_blob_none", depends=["AiosqliteTestAttrsClasses::get_blob"]) async def test_get_blob_none( self, queries_obj: queries.Queries, @@ -451,11 +413,9 @@ async def test_get_blob_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many", depends=["AiosqliteTestAttrsClasses::get_blob_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many", depends=["AiosqliteTestAttrsClasses::get_blob_none"]) async def test_get_many(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_sqlite_type(id_=model.id) + result = await queries_obj.get_many_sqlite_type(id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -464,20 +424,16 @@ async def test_get_many(self, queries_obj: queries.Queries, model: models.TestSq assert result[0] == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_iter", depends=["AiosqliteTestAttrsClasses::get_many"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_iter", depends=["AiosqliteTestAttrsClasses::get_many"]) async def test_get_many_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_sqlite_type(id_=model.id): + async for result in queries_obj.get_many_sqlite_type(id_=model.id_): assert result is not None assert isinstance(result, models.TestSqliteType) assert result == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_inner", depends=["AiosqliteTestAttrsClasses::get_many_iter"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_inner", depends=["AiosqliteTestAttrsClasses::get_many_iter"]) async def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: result = await queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id) @@ -488,12 +444,8 @@ async def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: m assert result[0] == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_inner_iter", depends=["AiosqliteTestAttrsClasses::get_many_inner"] - ) - async def test_get_many_inner_iter( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_inner_iter", depends=["AiosqliteTestAttrsClasses::get_many_inner"]) + async def test_get_many_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: async for result in queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -505,12 +457,8 @@ async def test_get_many_inner_iter( name="AiosqliteTestAttrsClasses::get_many_nullable_inner", depends=["AiosqliteTestAttrsClasses::get_many_inner_iter"], ) - async def test_get_many_nullable_inner( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: - result = await queries_obj.get_many_nullable_inner_sqlite_type( - table_id=inner_model.table_id, int_test=inner_model.int_test - ) + async def test_get_many_nullable_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + result = await queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -523,12 +471,8 @@ async def test_get_many_nullable_inner( name="AiosqliteTestAttrsClasses::get_many_nullable_inner_iter", depends=["AiosqliteTestAttrsClasses::get_many_nullable_inner"], ) - async def test_get_many_nullable_inner_iter( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: - async for result in queries_obj.get_many_nullable_inner_sqlite_type( - table_id=inner_model.table_id, int_test=inner_model.int_test - ): + async def test_get_many_nullable_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + async for result in queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -540,7 +484,7 @@ async def test_get_many_nullable_inner_iter( depends=["AiosqliteTestAttrsClasses::get_many_nullable_inner_iter"], ) async def test_get_many_date(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_date(id_=model.id, date_test=model.date_test) + result = await queries_obj.get_many_date(id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -549,22 +493,18 @@ async def test_get_many_date(self, queries_obj: queries.Queries, model: models.T assert result[0] == model.date_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_date_iter", depends=["AiosqliteTestAttrsClasses::get_many_date"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_date_iter", depends=["AiosqliteTestAttrsClasses::get_many_date"]) async def test_get_many_date_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_date(id_=model.id, date_test=model.date_test): + async for result in queries_obj.get_many_date(id_=model.id_, date_test=model.date_test): assert result is not None assert isinstance(result, datetime.date) assert result == model.date_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_datetime", depends=["AiosqliteTestAttrsClasses::get_many_date_iter"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_datetime", depends=["AiosqliteTestAttrsClasses::get_many_date_iter"]) async def test_get_many_datetime(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_datetime(id_=model.id, datetime_test=model.datetime_test) + result = await queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -578,7 +518,7 @@ async def test_get_many_datetime(self, queries_obj: queries.Queries, model: mode depends=["AiosqliteTestAttrsClasses::get_many_datetime"], ) async def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_datetime(id_=model.id, datetime_test=model.datetime_test): + async for result in queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -590,7 +530,7 @@ async def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: depends=["AiosqliteTestAttrsClasses::get_many_datetime_iter"], ) async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_timestamp(id_=model.id, timestamp_test=model.timestamp_test) + result = await queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -604,18 +544,16 @@ async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: mod depends=["AiosqliteTestAttrsClasses::get_many_timestamp"], ) async def test_get_many_timestamp_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_timestamp(id_=model.id, timestamp_test=model.timestamp_test): + async for result in queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test): assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_bool", depends=["AiosqliteTestAttrsClasses::get_many_timestamp_iter"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_bool", depends=["AiosqliteTestAttrsClasses::get_many_timestamp_iter"]) async def test_get_many_bool(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_bool(id_=model.id, bool_test=model.bool_test) + result = await queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -624,22 +562,18 @@ async def test_get_many_bool(self, queries_obj: queries.Queries, model: models.T assert result[0] == model.bool_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_bool_iter", depends=["AiosqliteTestAttrsClasses::get_many_bool"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_bool_iter", depends=["AiosqliteTestAttrsClasses::get_many_bool"]) async def test_get_many_bool_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_bool(id_=model.id, bool_test=model.bool_test): + async for result in queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test): assert result is not None assert isinstance(result, bool) assert result == model.bool_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_boolean", depends=["AiosqliteTestAttrsClasses::get_many_bool_iter"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_boolean", depends=["AiosqliteTestAttrsClasses::get_many_bool_iter"]) async def test_get_many_boolean(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_boolean(id_=model.id, boolean_test=model.boolean_test) + result = await queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -648,22 +582,18 @@ async def test_get_many_boolean(self, queries_obj: queries.Queries, model: model assert result[0] == model.boolean_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_boolean_iter", depends=["AiosqliteTestAttrsClasses::get_many_boolean"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_boolean_iter", depends=["AiosqliteTestAttrsClasses::get_many_boolean"]) async def test_get_many_boolean_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_boolean(id_=model.id, boolean_test=model.boolean_test): + async for result in queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test): assert result is not None assert isinstance(result, bool) assert result == model.boolean_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_decimal", depends=["AiosqliteTestAttrsClasses::get_many_boolean_iter"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_decimal", depends=["AiosqliteTestAttrsClasses::get_many_boolean_iter"]) async def test_get_many_decimal(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_decimal(id_=model.id, decimal_test=model.decimal_test) + result = await queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -672,22 +602,18 @@ async def test_get_many_decimal(self, queries_obj: queries.Queries, model: model assert result[0] == model.decimal_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_decimal_iter", depends=["AiosqliteTestAttrsClasses::get_many_decimal"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_decimal_iter", depends=["AiosqliteTestAttrsClasses::get_many_decimal"]) async def test_get_many_decimal_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_decimal(id_=model.id, decimal_test=model.decimal_test): + async for result in queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test): assert result is not None assert isinstance(result, decimal.Decimal) assert result == model.decimal_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_blob", depends=["AiosqliteTestAttrsClasses::get_many_decimal_iter"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_blob", depends=["AiosqliteTestAttrsClasses::get_many_decimal_iter"]) async def test_get_many_blob(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_blob(id_=model.id, blob_test=model.blob_test) + result = await queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -696,27 +622,23 @@ async def test_get_many_blob(self, queries_obj: queries.Queries, model: models.T assert result[0] == model.blob_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::get_many_blob_iter", depends=["AiosqliteTestAttrsClasses::get_many_blob"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::get_many_blob_iter", depends=["AiosqliteTestAttrsClasses::get_many_blob"]) async def test_get_many_blob_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_blob(id_=model.id, blob_test=model.blob_test): + async for result in queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test): assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::insert_result", depends=["AiosqliteTestAttrsClasses::get_many_blob_iter"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::insert_result", depends=["AiosqliteTestAttrsClasses::get_many_blob_iter"]) async def test_insert_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = await queries_obj.insert_result_one_sqlite_type( - id_=model.id + 1, + id_=model.id_ + 1, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -749,40 +671,34 @@ async def test_insert_result( assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::update_result", depends=["AiosqliteTestAttrsClasses::insert_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::update_result", depends=["AiosqliteTestAttrsClasses::insert_result"]) async def test_update_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.update_result_one_sqlite_type(id_=model.id + 1) + result = await queries_obj.update_result_one_sqlite_type(id_=model.id_ + 1) assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::delete_result", depends=["AiosqliteTestAttrsClasses::update_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::delete_result", depends=["AiosqliteTestAttrsClasses::update_result"]) async def test_delete_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.delete_result_one_sqlite_type(id_=model.id + 1) + result = await queries_obj.delete_result_one_sqlite_type(id_=model.id_ + 1) assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::insert_rows", depends=["AiosqliteTestAttrsClasses::delete_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::insert_rows", depends=["AiosqliteTestAttrsClasses::delete_result"]) async def test_insert_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = await queries_obj.insert_rows_one_sqlite_type( - id_=model.id + 2, + id_=model.id_ + 2, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -816,35 +732,29 @@ async def test_insert_rows( assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::update_rows", depends=["AiosqliteTestAttrsClasses::insert_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::update_rows", depends=["AiosqliteTestAttrsClasses::insert_rows"]) async def test_update_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.update_rows_one_sqlite_type(id_=model.id + 2) + result = await queries_obj.update_rows_one_sqlite_type(id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::delete_rows", depends=["AiosqliteTestAttrsClasses::update_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::delete_rows", depends=["AiosqliteTestAttrsClasses::update_rows"]) async def test_delete_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.delete_rows_one_sqlite_type(id_=model.id + 2) + result = await queries_obj.delete_rows_one_sqlite_type(id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::create_table_rows", depends=["AiosqliteTestAttrsClasses::delete_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::create_table_rows", depends=["AiosqliteTestAttrsClasses::delete_rows"]) async def test_create_table_rows( self, queries_obj: queries.Queries, @@ -857,16 +767,14 @@ async def test_create_table_rows( assert result == -1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::insert_last_id", depends=["AiosqliteTestAttrsClasses::create_table_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::insert_last_id", depends=["AiosqliteTestAttrsClasses::create_table_rows"]) async def test_insert_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = await queries_obj.insert_last_id_one_sqlite_type( - id_=model.id + 3, + id_=model.id_ + 3, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -897,69 +805,57 @@ async def test_insert_last_id( json_test=model.json_test, ) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::update_last_id", depends=["AiosqliteTestAttrsClasses::insert_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::update_last_id", depends=["AiosqliteTestAttrsClasses::insert_last_id"]) async def test_update_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.update_last_id_one_sqlite_type(id_=model.id + 3) + result = await queries_obj.update_last_id_one_sqlite_type(id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::delete_last_id", depends=["AiosqliteTestAttrsClasses::update_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::delete_last_id", depends=["AiosqliteTestAttrsClasses::update_last_id"]) async def test_delete_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.delete_last_id_one_sqlite_type(id_=model.id + 3) + result = await queries_obj.delete_last_id_one_sqlite_type(id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsClasses::delete_sqlite_type", depends=["AiosqliteTestAttrsClasses::delete_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsClasses::delete_sqlite_type", depends=["AiosqliteTestAttrsClasses::delete_last_id"]) async def test_delete_sqlite_type(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - await queries_obj.delete_one_sqlite_type(id_=model.id) + await queries_obj.delete_one_sqlite_type(id_=model.id_) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestAttrsClasses::delete_inner_sqlite_type", depends=["AiosqliteTestAttrsClasses::delete_sqlite_type"], ) - async def test_delete_inner_sqlite_type( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: + async def test_delete_inner_sqlite_type(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: await queries_obj.delete_one_test_inner_sqlite_type(table_id=inner_model.table_id) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestAttrsClasses::insert_type_override", ) - async def test_insert_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - await queries_obj.insert_type_override(id_=override_model.id, text_test=override_model.text_test) + async def test_insert_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.insert_type_override(id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestAttrsClasses::get_one_type_override", depends=["AiosqliteTestAttrsClasses::insert_type_override"], ) - async def test_get_one_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_type_override(id_=override_model.id) + async def test_get_one_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_) assert result is not None assert result == override_model @@ -968,10 +864,8 @@ async def test_get_one_type_override( name="AiosqliteTestAttrsClasses::get_one_type_override_none", depends=["AiosqliteTestAttrsClasses::get_one_type_override"], ) - async def test_get_one_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_type_override(id_=override_model.id - 1) + async def test_get_one_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -979,10 +873,8 @@ async def test_get_one_type_override_none( name="AiosqliteTestAttrsClasses::get_many_type_override", depends=["AiosqliteTestAttrsClasses::get_one_type_override_none"], ) - async def test_get_many_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_many_type_override(id_=override_model.id) + async def test_get_many_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_type_override(id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model @@ -991,10 +883,8 @@ async def test_get_many_type_override( name="AiosqliteTestAttrsClasses::get_one_text_type_override", depends=["AiosqliteTestAttrsClasses::get_many_type_override"], ) - async def test_get_one_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_text_type_override(id_=override_model.id) + async def test_get_one_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -1003,10 +893,8 @@ async def test_get_one_text_type_override( name="AiosqliteTestAttrsClasses::get_one_text_type_override_none", depends=["AiosqliteTestAttrsClasses::get_one_text_type_override"], ) - async def test_get_one_text_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_text_type_override(id_=override_model.id - 1) + async def test_get_one_text_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -1014,10 +902,8 @@ async def test_get_one_text_type_override_none( name="AiosqliteTestAttrsClasses::get_many_text_type_override", depends=["AiosqliteTestAttrsClasses::get_one_text_type_override_none"], ) - async def test_get_many_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_many_text_type_override(id_=override_model.id) + async def test_get_many_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_text_type_override(id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model.text_test @@ -1026,7 +912,5 @@ async def test_get_many_text_type_override( name="AiosqliteTestAttrsClasses::delete_type_override", depends=["AiosqliteTestAttrsClasses::get_many_text_type_override"], ) - async def test_delete_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - await queries_obj.delete_type_override(id_=override_model.id) + async def test_delete_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.delete_type_override(id_=override_model.id_) diff --git a/test/driver_aiosqlite/attrs/test_aiosqlite_attrs_functions.py b/test/driver_aiosqlite/attrs/test_aiosqlite_attrs_functions.py index d0623d7d..a61f2d8b 100644 --- a/test/driver_aiosqlite/attrs/test_aiosqlite_attrs_functions.py +++ b/test/driver_aiosqlite/attrs/test_aiosqlite_attrs_functions.py @@ -38,12 +38,12 @@ class TestAttrsFunctions: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestSqliteType: return models.TestSqliteType( - id=random.randint(1, 10000000), + id_=random.randint(1, 10000000), int_test=42, bigint_test=9_007_199_254_740_991, smallint_test=32_767, @@ -77,7 +77,7 @@ def model(self) -> models.TestSqliteType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: return models.TestInnerSqliteType( - table_id=model.id, + table_id=model.id_, int_test=None, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -117,7 +117,7 @@ async def test_insert( ) -> None: await queries.insert_one_sqlite_type( conn=aiosqlite_conn, - id_=model.id, + id_=model.id_, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -149,9 +149,7 @@ async def test_insert( ) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::inner_insert", depends=["AiosqliteTestAttrsFunctions::insert"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::inner_insert", depends=["AiosqliteTestAttrsFunctions::insert"]) async def test_inner_insert( self, aiosqlite_conn: aiosqlite.Connection, @@ -191,15 +189,13 @@ async def test_inner_insert( ) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_one", depends=["AiosqliteTestAttrsFunctions::inner_insert"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_one", depends=["AiosqliteTestAttrsFunctions::inner_insert"]) async def test_get_one( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_sqlite_type(conn=aiosqlite_conn, id_=model.id) + result = await queries.get_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_) assert result is not None @@ -208,9 +204,7 @@ async def test_get_one( assert result == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_one_none", depends=["AiosqliteTestAttrsFunctions::get_one"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_one_none", depends=["AiosqliteTestAttrsFunctions::get_one"]) async def test_get_one_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -220,9 +214,7 @@ async def test_get_one_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_one_inner", depends=["AiosqliteTestAttrsFunctions::get_one_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_one_inner", depends=["AiosqliteTestAttrsFunctions::get_one_none"]) async def test_get_one_inner( self, aiosqlite_conn: aiosqlite.Connection, @@ -236,9 +228,7 @@ async def test_get_one_inner( assert result == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_one_inner_none", depends=["AiosqliteTestAttrsFunctions::get_one_inner"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_one_inner_none", depends=["AiosqliteTestAttrsFunctions::get_one_inner"]) async def test_get_one_inner_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -248,15 +238,13 @@ async def test_get_one_inner_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_date", depends=["AiosqliteTestAttrsFunctions::get_one_inner_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_date", depends=["AiosqliteTestAttrsFunctions::get_one_inner_none"]) async def test_get_date( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_date(conn=aiosqlite_conn, id_=model.id, date_test=model.date_test) + result = await queries.get_one_date(conn=aiosqlite_conn, id_=model.id_, date_test=model.date_test) assert result is not None @@ -264,9 +252,7 @@ async def test_get_date( assert result == model.date_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_date_none", depends=["AiosqliteTestAttrsFunctions::get_date"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_date_none", depends=["AiosqliteTestAttrsFunctions::get_date"]) async def test_get_date_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -276,15 +262,13 @@ async def test_get_date_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_datetime", depends=["AiosqliteTestAttrsFunctions::get_date_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_datetime", depends=["AiosqliteTestAttrsFunctions::get_date_none"]) async def test_get_datetime( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_datetime(conn=aiosqlite_conn, id_=model.id, datetime_test=model.datetime_test) + result = await queries.get_one_datetime(conn=aiosqlite_conn, id_=model.id_, datetime_test=model.datetime_test) assert result is not None @@ -292,9 +276,7 @@ async def test_get_datetime( assert result == model.datetime_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_datetime_none", depends=["AiosqliteTestAttrsFunctions::get_datetime"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_datetime_none", depends=["AiosqliteTestAttrsFunctions::get_datetime"]) async def test_get_datetime_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -304,15 +286,13 @@ async def test_get_datetime_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_timestamp", depends=["AiosqliteTestAttrsFunctions::get_datetime_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_timestamp", depends=["AiosqliteTestAttrsFunctions::get_datetime_none"]) async def test_get_timestamp( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_timestamp(conn=aiosqlite_conn, id_=model.id, timestamp_test=model.timestamp_test) + result = await queries.get_one_timestamp(conn=aiosqlite_conn, id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None @@ -320,9 +300,7 @@ async def test_get_timestamp( assert result == model.timestamp_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_timestamp_none", depends=["AiosqliteTestAttrsFunctions::get_timestamp"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_timestamp_none", depends=["AiosqliteTestAttrsFunctions::get_timestamp"]) async def test_get_timestamp_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -332,15 +310,13 @@ async def test_get_timestamp_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_bool", depends=["AiosqliteTestAttrsFunctions::get_timestamp_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_bool", depends=["AiosqliteTestAttrsFunctions::get_timestamp_none"]) async def test_get_bool( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_bool(conn=aiosqlite_conn, id_=model.id, bool_test=model.bool_test) + result = await queries.get_one_bool(conn=aiosqlite_conn, id_=model.id_, bool_test=model.bool_test) assert result is not None @@ -348,9 +324,7 @@ async def test_get_bool( assert result == model.bool_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_bool_none", depends=["AiosqliteTestAttrsFunctions::get_bool"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_bool_none", depends=["AiosqliteTestAttrsFunctions::get_bool"]) async def test_get_bool_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -360,15 +334,13 @@ async def test_get_bool_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_boolean", depends=["AiosqliteTestAttrsFunctions::get_bool_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_boolean", depends=["AiosqliteTestAttrsFunctions::get_bool_none"]) async def test_get_boolean( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_boolean(conn=aiosqlite_conn, id_=model.id, boolean_test=model.boolean_test) + result = await queries.get_one_boolean(conn=aiosqlite_conn, id_=model.id_, boolean_test=model.boolean_test) assert result is not None @@ -376,9 +348,7 @@ async def test_get_boolean( assert result == model.boolean_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_boolean_none", depends=["AiosqliteTestAttrsFunctions::get_boolean"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_boolean_none", depends=["AiosqliteTestAttrsFunctions::get_boolean"]) async def test_get_boolean_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -388,15 +358,13 @@ async def test_get_boolean_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_decimal", depends=["AiosqliteTestAttrsFunctions::get_boolean_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_decimal", depends=["AiosqliteTestAttrsFunctions::get_boolean_none"]) async def test_get_decimal( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_decimal(conn=aiosqlite_conn, id_=model.id, decimal_test=model.decimal_test) + result = await queries.get_one_decimal(conn=aiosqlite_conn, id_=model.id_, decimal_test=model.decimal_test) assert result is not None @@ -404,9 +372,7 @@ async def test_get_decimal( assert result == model.decimal_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_decimal_none", depends=["AiosqliteTestAttrsFunctions::get_decimal"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_decimal_none", depends=["AiosqliteTestAttrsFunctions::get_decimal"]) async def test_get_decimal_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -416,15 +382,13 @@ async def test_get_decimal_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_blob", depends=["AiosqliteTestAttrsFunctions::get_decimal_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_blob", depends=["AiosqliteTestAttrsFunctions::get_decimal_none"]) async def test_get_blob( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_blob(conn=aiosqlite_conn, id_=model.id, blob_test=model.blob_test) + result = await queries.get_one_blob(conn=aiosqlite_conn, id_=model.id_, blob_test=model.blob_test) assert result is not None @@ -432,9 +396,7 @@ async def test_get_blob( assert result == model.blob_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_blob_none", depends=["AiosqliteTestAttrsFunctions::get_blob"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_blob_none", depends=["AiosqliteTestAttrsFunctions::get_blob"]) async def test_get_blob_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -444,11 +406,9 @@ async def test_get_blob_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_many", depends=["AiosqliteTestAttrsFunctions::get_blob_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_many", depends=["AiosqliteTestAttrsFunctions::get_blob_none"]) async def test_get_many(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id) + result = await queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -457,23 +417,17 @@ async def test_get_many(self, aiosqlite_conn: aiosqlite.Connection, model: model assert result[0] == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_many_iter", depends=["AiosqliteTestAttrsFunctions::get_many"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_many_iter", depends=["AiosqliteTestAttrsFunctions::get_many"]) async def test_get_many_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - async for result in queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id): + async for result in queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id_): assert result is not None assert isinstance(result, models.TestSqliteType) assert result == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_many_inner", depends=["AiosqliteTestAttrsFunctions::get_many_iter"] - ) - async def test_get_many_inner( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_many_inner", depends=["AiosqliteTestAttrsFunctions::get_many_iter"]) + async def test_get_many_inner(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: result = await queries.get_many_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id) assert result is not None @@ -483,12 +437,8 @@ async def test_get_many_inner( assert result[0] == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_many_inner_iter", depends=["AiosqliteTestAttrsFunctions::get_many_inner"] - ) - async def test_get_many_inner_iter( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_many_inner_iter", depends=["AiosqliteTestAttrsFunctions::get_many_inner"]) + async def test_get_many_inner_iter(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: async for result in queries.get_many_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -500,12 +450,8 @@ async def test_get_many_inner_iter( name="AiosqliteTestAttrsFunctions::get_many_nullable_inner", depends=["AiosqliteTestAttrsFunctions::get_many_inner_iter"], ) - async def test_get_many_nullable_inner( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: - result = await queries.get_many_nullable_inner_sqlite_type( - conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test - ) + async def test_get_many_nullable_inner(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: + result = await queries.get_many_nullable_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -518,12 +464,8 @@ async def test_get_many_nullable_inner( name="AiosqliteTestAttrsFunctions::get_many_nullable_inner_iter", depends=["AiosqliteTestAttrsFunctions::get_many_nullable_inner"], ) - async def test_get_many_nullable_inner_iter( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: - async for result in queries.get_many_nullable_inner_sqlite_type( - conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test - ): + async def test_get_many_nullable_inner_iter(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: + async for result in queries.get_many_nullable_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -535,7 +477,7 @@ async def test_get_many_nullable_inner_iter( depends=["AiosqliteTestAttrsFunctions::get_many_nullable_inner_iter"], ) async def test_get_many_date(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_date(conn=aiosqlite_conn, id_=model.id, date_test=model.date_test) + result = await queries.get_many_date(conn=aiosqlite_conn, id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -544,11 +486,9 @@ async def test_get_many_date(self, aiosqlite_conn: aiosqlite.Connection, model: assert result[0] == model.date_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_many_date_iter", depends=["AiosqliteTestAttrsFunctions::get_many_date"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_many_date_iter", depends=["AiosqliteTestAttrsFunctions::get_many_date"]) async def test_get_many_date_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - async for result in queries.get_many_date(conn=aiosqlite_conn, id_=model.id, date_test=model.date_test): + async for result in queries.get_many_date(conn=aiosqlite_conn, id_=model.id_, date_test=model.date_test): assert result is not None assert isinstance(result, datetime.date) @@ -560,7 +500,7 @@ async def test_get_many_date_iter(self, aiosqlite_conn: aiosqlite.Connection, mo depends=["AiosqliteTestAttrsFunctions::get_many_date_iter"], ) async def test_get_many_datetime(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_datetime(conn=aiosqlite_conn, id_=model.id, datetime_test=model.datetime_test) + result = await queries.get_many_datetime(conn=aiosqlite_conn, id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -573,12 +513,8 @@ async def test_get_many_datetime(self, aiosqlite_conn: aiosqlite.Connection, mod name="AiosqliteTestAttrsFunctions::get_many_datetime_iter", depends=["AiosqliteTestAttrsFunctions::get_many_datetime"], ) - async def test_get_many_datetime_iter( - self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType - ) -> None: - async for result in queries.get_many_datetime( - conn=aiosqlite_conn, id_=model.id, datetime_test=model.datetime_test - ): + async def test_get_many_datetime_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_datetime(conn=aiosqlite_conn, id_=model.id_, datetime_test=model.datetime_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -590,9 +526,7 @@ async def test_get_many_datetime_iter( depends=["AiosqliteTestAttrsFunctions::get_many_datetime_iter"], ) async def test_get_many_timestamp(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_timestamp( - conn=aiosqlite_conn, id_=model.id, timestamp_test=model.timestamp_test - ) + result = await queries.get_many_timestamp(conn=aiosqlite_conn, id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -605,12 +539,8 @@ async def test_get_many_timestamp(self, aiosqlite_conn: aiosqlite.Connection, mo name="AiosqliteTestAttrsFunctions::get_many_timestamp_iter", depends=["AiosqliteTestAttrsFunctions::get_many_timestamp"], ) - async def test_get_many_timestamp_iter( - self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType - ) -> None: - async for result in queries.get_many_timestamp( - conn=aiosqlite_conn, id_=model.id, timestamp_test=model.timestamp_test - ): + async def test_get_many_timestamp_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_timestamp(conn=aiosqlite_conn, id_=model.id_, timestamp_test=model.timestamp_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -622,7 +552,7 @@ async def test_get_many_timestamp_iter( depends=["AiosqliteTestAttrsFunctions::get_many_timestamp_iter"], ) async def test_get_many_bool(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_bool(conn=aiosqlite_conn, id_=model.id, bool_test=model.bool_test) + result = await queries.get_many_bool(conn=aiosqlite_conn, id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -631,11 +561,9 @@ async def test_get_many_bool(self, aiosqlite_conn: aiosqlite.Connection, model: assert result[0] == model.bool_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_many_bool_iter", depends=["AiosqliteTestAttrsFunctions::get_many_bool"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_many_bool_iter", depends=["AiosqliteTestAttrsFunctions::get_many_bool"]) async def test_get_many_bool_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - async for result in queries.get_many_bool(conn=aiosqlite_conn, id_=model.id, bool_test=model.bool_test): + async for result in queries.get_many_bool(conn=aiosqlite_conn, id_=model.id_, bool_test=model.bool_test): assert result is not None assert isinstance(result, bool) @@ -647,7 +575,7 @@ async def test_get_many_bool_iter(self, aiosqlite_conn: aiosqlite.Connection, mo depends=["AiosqliteTestAttrsFunctions::get_many_bool_iter"], ) async def test_get_many_boolean(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_boolean(conn=aiosqlite_conn, id_=model.id, boolean_test=model.boolean_test) + result = await queries.get_many_boolean(conn=aiosqlite_conn, id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -660,12 +588,8 @@ async def test_get_many_boolean(self, aiosqlite_conn: aiosqlite.Connection, mode name="AiosqliteTestAttrsFunctions::get_many_boolean_iter", depends=["AiosqliteTestAttrsFunctions::get_many_boolean"], ) - async def test_get_many_boolean_iter( - self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType - ) -> None: - async for result in queries.get_many_boolean( - conn=aiosqlite_conn, id_=model.id, boolean_test=model.boolean_test - ): + async def test_get_many_boolean_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_boolean(conn=aiosqlite_conn, id_=model.id_, boolean_test=model.boolean_test): assert result is not None assert isinstance(result, bool) @@ -677,7 +601,7 @@ async def test_get_many_boolean_iter( depends=["AiosqliteTestAttrsFunctions::get_many_boolean_iter"], ) async def test_get_many_decimal(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_decimal(conn=aiosqlite_conn, id_=model.id, decimal_test=model.decimal_test) + result = await queries.get_many_decimal(conn=aiosqlite_conn, id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -690,12 +614,8 @@ async def test_get_many_decimal(self, aiosqlite_conn: aiosqlite.Connection, mode name="AiosqliteTestAttrsFunctions::get_many_decimal_iter", depends=["AiosqliteTestAttrsFunctions::get_many_decimal"], ) - async def test_get_many_decimal_iter( - self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType - ) -> None: - async for result in queries.get_many_decimal( - conn=aiosqlite_conn, id_=model.id, decimal_test=model.decimal_test - ): + async def test_get_many_decimal_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_decimal(conn=aiosqlite_conn, id_=model.id_, decimal_test=model.decimal_test): assert result is not None assert isinstance(result, decimal.Decimal) @@ -707,7 +627,7 @@ async def test_get_many_decimal_iter( depends=["AiosqliteTestAttrsFunctions::get_many_decimal_iter"], ) async def test_get_many_blob(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_blob(conn=aiosqlite_conn, id_=model.id, blob_test=model.blob_test) + result = await queries.get_many_blob(conn=aiosqlite_conn, id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -716,20 +636,16 @@ async def test_get_many_blob(self, aiosqlite_conn: aiosqlite.Connection, model: assert result[0] == model.blob_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::get_many_blob_iter", depends=["AiosqliteTestAttrsFunctions::get_many_blob"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::get_many_blob_iter", depends=["AiosqliteTestAttrsFunctions::get_many_blob"]) async def test_get_many_blob_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - async for result in queries.get_many_blob(conn=aiosqlite_conn, id_=model.id, blob_test=model.blob_test): + async for result in queries.get_many_blob(conn=aiosqlite_conn, id_=model.id_, blob_test=model.blob_test): assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::insert_result", depends=["AiosqliteTestAttrsFunctions::get_many_blob_iter"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::insert_result", depends=["AiosqliteTestAttrsFunctions::get_many_blob_iter"]) async def test_insert_result( self, aiosqlite_conn: aiosqlite.Connection, @@ -737,7 +653,7 @@ async def test_insert_result( ) -> None: result = await queries.insert_result_one_sqlite_type( conn=aiosqlite_conn, - id_=model.id + 1, + id_=model.id_ + 1, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -770,33 +686,27 @@ async def test_insert_result( assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::update_result", depends=["AiosqliteTestAttrsFunctions::insert_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::update_result", depends=["AiosqliteTestAttrsFunctions::insert_result"]) async def test_update_result( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.update_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 1) + result = await queries.update_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 1) assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::delete_result", depends=["AiosqliteTestAttrsFunctions::update_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::delete_result", depends=["AiosqliteTestAttrsFunctions::update_result"]) async def test_delete_result( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.delete_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 1) + result = await queries.delete_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 1) assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::insert_rows", depends=["AiosqliteTestAttrsFunctions::delete_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::insert_rows", depends=["AiosqliteTestAttrsFunctions::delete_result"]) async def test_insert_rows( self, aiosqlite_conn: aiosqlite.Connection, @@ -804,7 +714,7 @@ async def test_insert_rows( ) -> None: result = await queries.insert_rows_one_sqlite_type( conn=aiosqlite_conn, - id_=model.id + 2, + id_=model.id_ + 2, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -838,35 +748,29 @@ async def test_insert_rows( assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::update_rows", depends=["AiosqliteTestAttrsFunctions::insert_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::update_rows", depends=["AiosqliteTestAttrsFunctions::insert_rows"]) async def test_update_rows( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.update_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 2) + result = await queries.update_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::delete_rows", depends=["AiosqliteTestAttrsFunctions::update_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::delete_rows", depends=["AiosqliteTestAttrsFunctions::update_rows"]) async def test_delete_rows( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.delete_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 2) + result = await queries.delete_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::create_table_rows", depends=["AiosqliteTestAttrsFunctions::delete_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::create_table_rows", depends=["AiosqliteTestAttrsFunctions::delete_rows"]) async def test_create_table_rows( self, aiosqlite_conn: aiosqlite.Connection, @@ -878,9 +782,7 @@ async def test_create_table_rows( assert result == -1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::insert_last_id", depends=["AiosqliteTestAttrsFunctions::create_table_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::insert_last_id", depends=["AiosqliteTestAttrsFunctions::create_table_rows"]) async def test_insert_last_id( self, aiosqlite_conn: aiosqlite.Connection, @@ -888,7 +790,7 @@ async def test_insert_last_id( ) -> None: result = await queries.insert_last_id_one_sqlite_type( conn=aiosqlite_conn, - id_=model.id + 3, + id_=model.id_ + 3, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -919,71 +821,57 @@ async def test_insert_last_id( json_test=model.json_test, ) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::update_last_id", depends=["AiosqliteTestAttrsFunctions::insert_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::update_last_id", depends=["AiosqliteTestAttrsFunctions::insert_last_id"]) async def test_update_last_id( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.update_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 3) + result = await queries.update_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::delete_last_id", depends=["AiosqliteTestAttrsFunctions::update_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::delete_last_id", depends=["AiosqliteTestAttrsFunctions::update_last_id"]) async def test_delete_last_id( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.delete_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 3) + result = await queries.delete_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestAttrsFunctions::delete_sqlite_type", depends=["AiosqliteTestAttrsFunctions::delete_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestAttrsFunctions::delete_sqlite_type", depends=["AiosqliteTestAttrsFunctions::delete_last_id"]) async def test_delete_sqlite_type(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - await queries.delete_one_sqlite_type(conn=aiosqlite_conn, id_=model.id) + await queries.delete_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestAttrsFunctions::delete_inner_sqlite_type", depends=["AiosqliteTestAttrsFunctions::delete_sqlite_type"], ) - async def test_delete_inner_sqlite_type( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + async def test_delete_inner_sqlite_type(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: await queries.delete_one_test_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestAttrsFunctions::insert_type_override", ) - async def test_insert_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - await queries.insert_type_override( - conn=aiosqlite_conn, id_=override_model.id, text_test=override_model.text_test - ) + async def test_insert_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + await queries.insert_type_override(conn=aiosqlite_conn, id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestAttrsFunctions::get_one_type_override", depends=["AiosqliteTestAttrsFunctions::insert_type_override"], ) - async def test_get_one_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_get_one_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id_) assert result is not None assert result == override_model @@ -992,10 +880,8 @@ async def test_get_one_type_override( name="AiosqliteTestAttrsFunctions::get_one_type_override_none", depends=["AiosqliteTestAttrsFunctions::get_one_type_override"], ) - async def test_get_one_type_override_none( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id - 1) + async def test_get_one_type_override_none(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -1003,10 +889,8 @@ async def test_get_one_type_override_none( name="AiosqliteTestAttrsFunctions::get_many_type_override", depends=["AiosqliteTestAttrsFunctions::get_one_type_override_none"], ) - async def test_get_many_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_many_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_get_many_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_type_override(conn=aiosqlite_conn, id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model @@ -1015,10 +899,8 @@ async def test_get_many_type_override( name="AiosqliteTestAttrsFunctions::get_one_text_type_override", depends=["AiosqliteTestAttrsFunctions::get_many_type_override"], ) - async def test_get_one_text_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_get_one_text_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -1027,10 +909,8 @@ async def test_get_one_text_type_override( name="AiosqliteTestAttrsFunctions::get_one_text_type_override_none", depends=["AiosqliteTestAttrsFunctions::get_one_text_type_override"], ) - async def test_get_one_text_type_override_none( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id - 1) + async def test_get_one_text_type_override_none(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -1038,10 +918,8 @@ async def test_get_one_text_type_override_none( name="AiosqliteTestAttrsFunctions::get_many_text_type_override", depends=["AiosqliteTestAttrsFunctions::get_one_text_type_override_none"], ) - async def test_get_many_text_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_many_text_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_get_many_text_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_text_type_override(conn=aiosqlite_conn, id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model.text_test @@ -1050,7 +928,5 @@ async def test_get_many_text_type_override( name="AiosqliteTestAttrsFunctions::delete_type_override", depends=["AiosqliteTestAttrsFunctions::get_many_text_type_override"], ) - async def test_delete_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - await queries.delete_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_delete_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + await queries.delete_type_override(conn=aiosqlite_conn, id_=override_model.id_) diff --git a/test/driver_aiosqlite/dataclass/classes/__init__.py b/test/driver_aiosqlite/dataclass/classes/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_aiosqlite/dataclass/classes/__init__.py +++ b/test/driver_aiosqlite/dataclass/classes/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_aiosqlite/dataclass/classes/models.py b/test/driver_aiosqlite/dataclass/classes/models.py index 086490f6..42ec832a 100644 --- a/test/driver_aiosqlite/dataclass/classes/models.py +++ b/test/driver_aiosqlite/dataclass/classes/models.py @@ -1,8 +1,9 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -93,7 +94,7 @@ class TestSqliteType: """Model representing TestSqliteType. Attributes: - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -124,7 +125,7 @@ class TestSqliteType: json_test: str """ - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -160,9 +161,9 @@ class TestTypeOverride: """Model representing TestTypeOverride. Attributes: - id: int + id_: int text_test: UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_aiosqlite/dataclass/classes/queries.py b/test/driver_aiosqlite/dataclass/classes/queries.py index da4a5d74..4311f059 100644 --- a/test/driver_aiosqlite/dataclass/classes/queries.py +++ b/test/driver_aiosqlite/dataclass/classes/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -21,7 +23,7 @@ import collections.abc import sqlite3 - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None from test.driver_aiosqlite.dataclass.classes import models @@ -81,71 +83,74 @@ def _convert_memoryview(val: bytes) -> memoryview: aiosqlite.register_converter("blob", _convert_memoryview) -CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows -CREATE TABLE test_create_rows_table -( - id int PRIMARY KEY NOT NULL, - test int NOT NULL -) -""" - -DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec -DELETE FROM test_inner_sqlite_types -WHERE test_inner_sqlite_types.table_id = ? +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ -DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? """ -DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec -DELETE -FROM test_type_override -WHERE test_type_override.id = ? +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ -GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many -SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many @@ -156,67 +161,46 @@ def _convert_memoryview(val: bytes) -> memoryview: SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? """ -GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? -""" - -GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? -""" - -GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? -""" - -GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? -""" - -GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one -SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? -""" - -GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one -SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = ? +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? """ -INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -231,37 +215,19 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec -INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? """ -INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec -INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -276,7 +242,27 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -291,35 +277,48 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec INSERT INTO test_type_override ( id, text_test ) VALUES (? ,?) """ -UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? """ -UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? """ -UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? """ +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" -T = typing.TypeVar("T") +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db.""" __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") @@ -366,9 +365,11 @@ def __await__( Returns: A sequence of decoded objects of type `T`. """ + async def _wrapper() -> collections.abc.Sequence[T]: result = await (await self._conn.execute(self._sql, self._args)).fetchall() return [self._decode_hook(row) for row in result] + return _wrapper().__await__() async def __anext__(self) -> T: @@ -415,132 +416,389 @@ def conn(self) -> aiosqlite.Connection: """ return self._conn - async def create_rows_table(self) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + async def insert_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Returns: - The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. - """ - return (await self._conn.execute(CREATE_ROWS_TABLE)).rowcount - - async def delete_last_id_one_sqlite_type(self, *, id_: int) -> int | None: - """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Args: id_: int. - - Returns: - The id (`int | None`) of the last affected row. Will be `None` if no rows are affected. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. """ - return (await self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await self._conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) - async def delete_one_sqlite_type(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneSqliteType :exec`. + async def insert_one_inner_sqlite_type( + self, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, + ) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Args: - id_: int. + table_id: int. + int_test: int | None. + bigint_test: int | None. + smallint_test: int | None. + tinyint_test: int | None. + int2_test: int | None. + int8_test: int | None. + bigserial_test: int | None. + blob_test: memoryview | None. + real_test: float | None. + double_test: float | None. + double_precision_test: float | None. + float_test: float | None. + numeric_test: float | None. + decimal_test: decimal.Decimal | None. + boolean_test: bool | None. + bool_test: bool | None. + date_test: datetime.date | None. + datetime_test: datetime.datetime | None. + timestamp_test: datetime.datetime | None. + character_test: str | None. + varchar_test: str | None. + varyingcharacter_test: str | None. + nchar_test: str | None. + nativecharacter_test: str | None. + nvarchar_test: str | None. + text_test: str | None. + clob_test: str | None. + json_test: str | None. """ - await self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, )) + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) - async def delete_one_test_inner_sqlite_type(self, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + async def get_one_sqlite_type(self, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. ```sql - DELETE FROM test_inner_sqlite_types - WHERE test_inner_sqlite_types.table_id = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Args: - table_id: int. + id_: int. + + Returns: + Result of type `models.TestSqliteType` fetched from the db. Will be `None` if not found. """ - await self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, )) + row = await (await self._conn.execute(GET_ONE_SQLITE_TYPE, (id_,))).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) - async def delete_result_one_sqlite_type(self, *, id_: int) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + async def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Args: - id_: int. + table_id: int. Returns: - The result of type `aiosqlite.Cursor` returned when executing the query. + Result of type `models.TestInnerSqliteType` fetched from the db. Will be `None` if not found. """ - return await self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, )) + row = await (await self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,))).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) - async def delete_rows_one_sqlite_type(self, *, id_: int) -> int: - """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + async def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Args: id_: int. + date_test: datetime.date. Returns: - The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + Result of type `datetime.date` fetched from the db. Will be `None` if not found. """ - return (await self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount + row = await (await self._conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() + if row is None: + return None + return row[0] - async def delete_type_override(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. + async def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Args: id_: int. + datetime_test: datetime.datetime. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. """ - await self._conn.execute(DELETE_TYPE_OVERRIDE, (id_, )) + row = await (await self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. + async def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Args: id_: int. - blob_test: memoryview. + timestamp_test: datetime.datetime. Returns: - Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. """ - return QueryResults[memoryview](self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + row = await (await self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBool :many`. + async def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -551,12 +809,15 @@ def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: bool_test: bool. Returns: - Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + Result of type `bool` fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + row = await (await self._conn.execute(GET_ONE_BOOL, (id_, bool_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. + async def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -567,57 +828,99 @@ def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool boolean_test: bool. Returns: - Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + Result of type `bool` fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + row = await (await self._conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: - """Fetch many from the db using the SQL query with `name: GetManyDate :many`. + async def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Args: id_: int. - date_test: datetime.date. + decimal_test: decimal.Decimal. Returns: - Helper class of type `QueryResults[datetime.date]` that allows both iteration and normal fetching of data from the db. + Result of type `decimal.Decimal` fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.date](self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + row = await (await self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. + async def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Args: id_: int. - datetime_test: datetime.datetime. + blob_test: memoryview. Returns: - Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + Result of type `memoryview` fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) + row = await (await self._conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: - """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. + def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Args: id_: int. - decimal_test: decimal.Decimal. Returns: - Helper class of type `QueryResults[decimal.Decimal]` that allows both iteration and normal fetching of data from the db. + Helper class of type `QueryResults[models.TestSqliteType]` that allows both iteration and normal fetching of data from the db. """ - return QueryResults[decimal.Decimal](self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) def get_many_inner_sqlite_type(self, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. @@ -632,9 +935,41 @@ def get_many_inner_sqlite_type(self, *, table_id: int) -> QueryResults[models.Te Returns: Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. @@ -650,43 +985,73 @@ def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | Returns: Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) - def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. + def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Args: id_: int. + date_test: datetime.date. Returns: - Helper class of type `QueryResults[models.TestSqliteType]` that allows both iteration and normal fetching of data from the db. + Helper class of type `QueryResults[datetime.date]` that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestSqliteType](self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + return QueryResults(self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) - def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Args: id_: int. + datetime_test: datetime.datetime. Returns: - Helper class of type `QueryResults[UserString]` that allows both iteration and normal fetching of data from the db. + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> UserString: - return UserString(row[0]) - return QueryResults[UserString](self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + return QueryResults(self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. @@ -702,46 +1067,10 @@ def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> Returns: Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - - def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: - """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. - - ```sql - SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? - ``` - - Args: - id_: int. - - Returns: - Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. - """ - def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - return QueryResults[models.TestTypeOverride](self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) - - async def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. - - ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? - ``` - - Args: - id_: int. - blob_test: memoryview. - - Returns: - Result of type `memoryview` fetched from the db. Will be `None` if not found. - """ - row = await (await self._conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - async def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBool :one`. + def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -752,15 +1081,12 @@ async def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: bool_test: bool. Returns: - Result of type `bool` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_BOOL, (id_, bool_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) - async def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. + def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -771,53 +1097,12 @@ async def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: boolean_test: bool. Returns: - Result of type `bool` fetched from the db. Will be `None` if not found. - """ - row = await (await self._conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test))).fetchone() - if row is None: - return None - return row[0] - - async def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: - """Fetch one from the db using the SQL query with `name: GetOneDate :one`. - - ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? - ``` - - Args: - id_: int. - date_test: datetime.date. - - Returns: - Result of type `datetime.date` fetched from the db. Will be `None` if not found. - """ - row = await (await self._conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() - if row is None: - return None - return row[0] - - async def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. - - ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? - ``` - - Args: - id_: int. - datetime_test: datetime.datetime. - - Returns: - Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) - async def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: - """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. + def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. ```sql SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? @@ -828,106 +1113,87 @@ async def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> d decimal_test: decimal.Decimal. Returns: - Result of type `decimal.Decimal` fetched from the db. Will be `None` if not found. - """ - row = await (await self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() - if row is None: - return None - return row[0] - - async def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? - ``` - - Args: - table_id: int. - - Returns: - Result of type `models.TestInnerSqliteType` fetched from the db. Will be `None` if not found. - """ - row = await (await self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id, ))).fetchone() - if row is None: - return None - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - - async def get_one_sqlite_type(self, *, id_: int) -> models.TestSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. - - ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? - ``` - - Args: - id_: int. - - Returns: - Result of type `models.TestSqliteType` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[decimal.Decimal]` that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_SQLITE_TYPE, (id_, ))).fetchone() - if row is None: - return None - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) - async def get_one_text_type_override(self, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Args: id_: int. + blob_test: memoryview. Returns: - Result of type `UserString` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_, ))).fetchone() - if row is None: - return None - return UserString(row[0]) + return QueryResults(self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) - async def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. + async def delete_one_sqlite_type(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? ``` Args: id_: int. - timestamp_test: datetime.datetime. - - Returns: - Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. """ - row = await (await self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() - if row is None: - return None - return row[0] + await self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) - async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + async def delete_one_test_inner_sqlite_type(self, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = ? + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? ``` Args: - id_: int. - - Returns: - Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. + table_id: int. """ - row = await (await self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_, ))).fetchone() - if row is None: - return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) + await self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) - async def insert_last_id_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int | None: - """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. + async def insert_result_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. ```sql INSERT INTO test_sqlite_types ( @@ -976,114 +1242,109 @@ async def insert_last_id_one_sqlite_type(self, *, id_: int, int_test: int, bigin json_test: str. Returns: - The id (`int | None`) of the last affected row. Will be `None` if no rows are affected. + The result of type `aiosqlite.Cursor` returned when executing the query. """ - return (await self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test))).lastrowid + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return await self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) - async def insert_one_inner_sqlite_type(self, *, table_id: int, int_test: int | None, bigint_test: int | None, smallint_test: int | None, tinyint_test: int | None, int2_test: int | None, int8_test: int | None, bigserial_test: int | None, blob_test: memoryview | None, real_test: float | None, double_test: float | None, double_precision_test: float | None, float_test: float | None, numeric_test: float | None, decimal_test: decimal.Decimal | None, boolean_test: bool | None, bool_test: bool | None, date_test: datetime.date | None, datetime_test: datetime.datetime | None, timestamp_test: datetime.datetime | None, character_test: str | None, varchar_test: str | None, varyingcharacter_test: str | None, nchar_test: str | None, nativecharacter_test: str | None, nvarchar_test: str | None, text_test: str | None, clob_test: str | None, json_test: str | None) -> None: - """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. + async def update_result_one_sqlite_type(self, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. ```sql - INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? ``` Args: - table_id: int. - int_test: int | None. - bigint_test: int | None. - smallint_test: int | None. - tinyint_test: int | None. - int2_test: int | None. - int8_test: int | None. - bigserial_test: int | None. - blob_test: memoryview | None. - real_test: float | None. - double_test: float | None. - double_precision_test: float | None. - float_test: float | None. - numeric_test: float | None. - decimal_test: decimal.Decimal | None. - boolean_test: bool | None. - bool_test: bool | None. - date_test: datetime.date | None. - datetime_test: datetime.datetime | None. - timestamp_test: datetime.datetime | None. - character_test: str | None. - varchar_test: str | None. - varyingcharacter_test: str | None. - nchar_test: str | None. - nativecharacter_test: str | None. - nvarchar_test: str | None. - text_test: str | None. - clob_test: str | None. - json_test: str | None. + id_: int. + + Returns: + The result of type `aiosqlite.Cursor` returned when executing the query. """ - await self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, (table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + return await self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) - async def insert_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> None: - """Execute SQL query with `name: InsertOneSqliteType :exec`. + async def delete_result_one_sqlite_type(self, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. ```sql - INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? ``` Args: id_: int. - int_test: int. - bigint_test: int. - smallint_test: int. - tinyint_test: int. - int2_test: int. - int8_test: int. - bigserial_test: int. - blob_test: memoryview. - real_test: float. - double_test: float. - double_precision_test: float. - float_test: float. - numeric_test: float. - decimal_test: decimal.Decimal. - boolean_test: bool. - bool_test: bool. - date_test: datetime.date. - datetime_test: datetime.datetime. - timestamp_test: datetime.datetime. - character_test: str. - varchar_test: str. - varyingcharacter_test: str. - nchar_test: str. - nativecharacter_test: str. - nvarchar_test: str. - text_test: str. - clob_test: str. - json_test: str. + + Returns: + The result of type `aiosqlite.Cursor` returned when executing the query. """ - await self._conn.execute(INSERT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + return await self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) - async def insert_result_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. + async def insert_rows_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. ```sql INSERT INTO test_sqlite_types ( @@ -1132,12 +1393,125 @@ async def insert_result_one_sqlite_type(self, *, id_: int, int_test: int, bigint json_test: str. Returns: - The result of type `aiosqlite.Cursor` returned when executing the query. + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - return await self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args)).rowcount - async def insert_rows_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int: - """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. + async def update_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + async def delete_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + async def create_rows_table(self) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await self._conn.execute(CREATE_ROWS_TABLE)).rowcount + + async def insert_last_id_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. ```sql INSERT INTO test_sqlite_types ( @@ -1186,9 +1560,74 @@ async def insert_rows_one_sqlite_type(self, *, id_: int, int_test: int, bigint_t json_test: str. Returns: - The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args)).lastrowid + + async def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + return (await self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid + + async def delete_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. """ - return (await self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test))).rowcount + return (await self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid async def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: """Execute SQL query with `name: InsertTypeOverride :exec`. @@ -1203,55 +1642,92 @@ async def insert_type_override(self, *, id_: int, text_test: UserString | None) id_: int. text_test: UserString | None. """ - await self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test))) + await self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) - async def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: - """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE id = ? ``` Args: id_: int. Returns: - The id (`int | None`) of the last affected row. Will be `None` if no rows are affected. + Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. """ - return (await self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid + row = await (await self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - async def update_result_one_sqlite_type(self, *, id_: int) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? ``` Args: id_: int. Returns: - The result of type `aiosqlite.Cursor` returned when executing the query. + Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. """ - return await self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_, )) - async def update_rows_one_sqlite_type(self, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + async def get_one_text_type_override(self, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? ``` Args: id_: int. Returns: - The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + Result of type `UserString` fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[UserString | None]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + async def delete_type_override(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Args: + id_: int. """ - return (await self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount + await self._conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_aiosqlite/dataclass/functions/__init__.py b/test/driver_aiosqlite/dataclass/functions/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_aiosqlite/dataclass/functions/__init__.py +++ b/test/driver_aiosqlite/dataclass/functions/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_aiosqlite/dataclass/functions/models.py b/test/driver_aiosqlite/dataclass/functions/models.py index 086490f6..42ec832a 100644 --- a/test/driver_aiosqlite/dataclass/functions/models.py +++ b/test/driver_aiosqlite/dataclass/functions/models.py @@ -1,8 +1,9 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -93,7 +94,7 @@ class TestSqliteType: """Model representing TestSqliteType. Attributes: - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -124,7 +125,7 @@ class TestSqliteType: json_test: str """ - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -160,9 +161,9 @@ class TestTypeOverride: """Model representing TestTypeOverride. Attributes: - id: int + id_: int text_test: UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_aiosqlite/dataclass/functions/queries.py b/test/driver_aiosqlite/dataclass/functions/queries.py index 511af5c0..bffe0156 100644 --- a/test/driver_aiosqlite/dataclass/functions/queries.py +++ b/test/driver_aiosqlite/dataclass/functions/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -59,7 +61,7 @@ import collections.abc import sqlite3 - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None from test.driver_aiosqlite.dataclass.functions import models @@ -119,71 +121,74 @@ def _convert_memoryview(val: bytes) -> memoryview: aiosqlite.register_converter("blob", _convert_memoryview) -CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows -CREATE TABLE test_create_rows_table -( - id int PRIMARY KEY NOT NULL, - test int NOT NULL -) -""" - -DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec -DELETE FROM test_inner_sqlite_types -WHERE test_inner_sqlite_types.table_id = ? +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ -DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? """ -DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec -DELETE -FROM test_type_override -WHERE test_type_override.id = ? +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ -GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many -SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many @@ -194,67 +199,46 @@ def _convert_memoryview(val: bytes) -> memoryview: SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? """ -GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? -""" - -GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? -""" - -GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? -""" - -GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? -""" - -GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one -SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? -""" - -GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one -SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = ? +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? """ -INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -269,37 +253,19 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec -INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? """ -INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec -INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -314,7 +280,27 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -329,35 +315,48 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec INSERT INTO test_type_override ( id, text_test ) VALUES (? ,?) """ -UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? """ -UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? """ -UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? """ +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" -T = typing.TypeVar("T") +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db.""" __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") @@ -404,9 +403,11 @@ def __await__( Returns: A sequence of decoded objects of type `T`. """ + async def _wrapper() -> collections.abc.Sequence[T]: result = await (await self._conn.execute(self._sql, self._args)).fetchall() return [self._decode_hook(row) for row in result] + return _wrapper().__await__() async def __anext__(self) -> T: @@ -430,276 +431,171 @@ async def __anext__(self) -> T: return self._decode_hook(record) -async def create_rows_table(conn: aiosqlite.Connection) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. +async def insert_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - - Returns: - The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. - """ - return (await conn.execute(CREATE_ROWS_TABLE)).rowcount - - -async def delete_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: - """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - id_: int. - - Returns: - The id (`int | None`) of the last affected row. Will be `None` if no rows are affected. - """ - return (await conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid - - -async def delete_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneSqliteType :exec`. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - id_: int. - """ - await conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, )) - - -async def delete_one_test_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. - - ```sql - DELETE FROM test_inner_sqlite_types - WHERE test_inner_sqlite_types.table_id = ? - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - table_id: int. - """ - await conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, )) - - -async def delete_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - id_: int. - - Returns: - The result of type `aiosqlite.Cursor` returned when executing the query. - """ - return await conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, )) - - -async def delete_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: - """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - id_: int. - - Returns: - The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. - """ - return (await conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount - - -async def delete_type_override(conn: aiosqlite.Connection, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. - - ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = ? - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - id_: int. - """ - await conn.execute(DELETE_TYPE_OVERRIDE, (id_, )) - - -def get_many_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. - - ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. blob_test: memoryview. - - Returns: - Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. - """ - return QueryResults[memoryview](conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) - - -def get_many_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBool :many`. - - ```sql - SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - id_: int. - bool_test: bool. - - Returns: - Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. - """ - return QueryResults[bool](conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) - - -def get_many_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. - - ```sql - SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - id_: int. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. boolean_test: bool. - - Returns: - Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. - """ - return QueryResults[bool](conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) - - -def get_many_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: - """Fetch many from the db using the SQL query with `name: GetManyDate :many`. - - ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - id_: int. + bool_test: bool. date_test: datetime.date. - - Returns: - Helper class of type `QueryResults[datetime.date]` that allows both iteration and normal fetching of data from the db. - """ - return QueryResults[datetime.date](conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) - - -def get_many_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. - - ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - id_: int. datetime_test: datetime.datetime. - - Returns: - Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. - """ - return QueryResults[datetime.datetime](conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) - - -def get_many_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: - """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. - - ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - id_: int. - decimal_test: decimal.Decimal. - - Returns: - Helper class of type `QueryResults[decimal.Decimal]` that allows both iteration and normal fetching of data from the db. - """ - return QueryResults[decimal.Decimal](conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) - - -def get_many_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? - ``` - - Args: - conn: - Connection object of type `aiosqlite.Connection` used to execute the query. - table_id: int. - - Returns: - Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. """ - def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) - - -def get_many_nullable_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) + + +async def insert_one_inner_sqlite_type( + conn: aiosqlite.Connection, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, +) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Args: @@ -707,17 +603,70 @@ def get_many_nullable_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: Connection object of type `aiosqlite.Connection` used to execute the query. table_id: int. int_test: int | None. - - Returns: - Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. + bigint_test: int | None. + smallint_test: int | None. + tinyint_test: int | None. + int2_test: int | None. + int8_test: int | None. + bigserial_test: int | None. + blob_test: memoryview | None. + real_test: float | None. + double_test: float | None. + double_precision_test: float | None. + float_test: float | None. + numeric_test: float | None. + decimal_test: decimal.Decimal | None. + boolean_test: bool | None. + bool_test: bool | None. + date_test: datetime.date | None. + datetime_test: datetime.datetime | None. + timestamp_test: datetime.datetime | None. + character_test: str | None. + varchar_test: str | None. + varyingcharacter_test: str | None. + nchar_test: str | None. + nativecharacter_test: str | None. + nvarchar_test: str | None. + text_test: str | None. + clob_test: str | None. + json_test: str | None. """ - def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) -def get_many_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. +async def get_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. ```sql SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? @@ -729,89 +678,156 @@ def get_many_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> QueryResult id_: int. Returns: - Helper class of type `QueryResults[models.TestSqliteType]` that allows both iteration and normal fetching of data from the db. + Result of type `models.TestSqliteType` fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestSqliteType](conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + row = await (await conn.execute(GET_ONE_SQLITE_TYPE, (id_,))).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) -def get_many_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. +async def get_one_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. - id_: int. + table_id: int. Returns: - Helper class of type `QueryResults[UserString]` that allows both iteration and normal fetching of data from the db. + Result of type `models.TestInnerSqliteType` fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> UserString: - return UserString(row[0]) - return QueryResults[UserString](conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + row = await (await conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,))).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) -def get_many_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. +async def get_one_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. id_: int. - timestamp_test: datetime.datetime. + date_test: datetime.date. Returns: - Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + Result of type `datetime.date` fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.datetime](conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) + row = await (await conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() + if row is None: + return None + return row[0] -def get_many_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: - """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. +async def get_one_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. ```sql - SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. id_: int. + datetime_test: datetime.datetime. Returns: - Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - return QueryResults[models.TestTypeOverride](conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + row = await (await conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() + if row is None: + return None + return row[0] -async def get_one_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. +async def get_one_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. id_: int. - blob_test: memoryview. + timestamp_test: datetime.datetime. Returns: - Result of type `memoryview` fetched from the db. Will be `None` if not found. + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. """ - row = await (await conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone() + row = await (await conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() if row is None: return None return row[0] @@ -861,74 +877,104 @@ async def get_one_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: return row[0] -async def get_one_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: - """Fetch one from the db using the SQL query with `name: GetOneDate :one`. +async def get_one_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. id_: int. - date_test: datetime.date. + decimal_test: decimal.Decimal. Returns: - Result of type `datetime.date` fetched from the db. Will be `None` if not found. + Result of type `decimal.Decimal` fetched from the db. Will be `None` if not found. """ - row = await (await conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() + row = await (await conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() if row is None: return None return row[0] -async def get_one_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. +async def get_one_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. id_: int. - datetime_test: datetime.datetime. + blob_test: memoryview. Returns: - Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + Result of type `memoryview` fetched from the db. Will be `None` if not found. """ - row = await (await conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() + row = await (await conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone() if row is None: return None return row[0] -async def get_one_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: - """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. +def get_many_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. id_: int. - decimal_test: decimal.Decimal. Returns: - Result of type `decimal.Decimal` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[models.TestSqliteType]` that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() - if row is None: - return None - return row[0] + + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) -async def get_one_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. +def get_many_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. ```sql SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? @@ -940,58 +986,138 @@ async def get_one_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int table_id: int. Returns: - Result of type `models.TestInnerSqliteType` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id, ))).fetchone() - if row is None: - return None - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) -async def get_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> models.TestSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. + +def get_many_nullable_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + table_id: int. + int_test: int | None. + + Returns: + Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + + +def get_many_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. + + ```sql + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. id_: int. + date_test: datetime.date. Returns: - Result of type `models.TestSqliteType` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[datetime.date]` that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_SQLITE_TYPE, (id_, ))).fetchone() - if row is None: - return None - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) -async def get_one_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. +def get_many_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. id_: int. + datetime_test: datetime.datetime. Returns: - Result of type `UserString` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_, ))).fetchone() - if row is None: - return None - return UserString(row[0]) + return QueryResults(conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) -async def get_one_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. +def get_many_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. ```sql SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? @@ -1004,148 +1130,154 @@ async def get_one_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_t timestamp_test: datetime.datetime. Returns: - Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) -async def get_one_type_override(conn: aiosqlite.Connection, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. +def get_many_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = ? + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. id_: int. + bool_test: bool. Returns: - Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_TYPE_OVERRIDE, (id_, ))).fetchone() - if row is None: - return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) + return QueryResults(conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) -async def insert_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int | None: - """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. +def get_many_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. ```sql - INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. id_: int. - int_test: int. - bigint_test: int. - smallint_test: int. - tinyint_test: int. - int2_test: int. - int8_test: int. - bigserial_test: int. - blob_test: memoryview. - real_test: float. - double_test: float. - double_precision_test: float. - float_test: float. - numeric_test: float. - decimal_test: decimal.Decimal. boolean_test: bool. - bool_test: bool. - date_test: datetime.date. - datetime_test: datetime.datetime. - timestamp_test: datetime.datetime. - character_test: str. - varchar_test: str. - varyingcharacter_test: str. - nchar_test: str. - nativecharacter_test: str. - nvarchar_test: str. - text_test: str. - clob_test: str. - json_test: str. Returns: - The id (`int | None`) of the last affected row. Will be `None` if no rows are affected. + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. """ - return (await conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test))).lastrowid + return QueryResults(conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) -async def insert_one_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int, int_test: int | None, bigint_test: int | None, smallint_test: int | None, tinyint_test: int | None, int2_test: int | None, int8_test: int | None, bigserial_test: int | None, blob_test: memoryview | None, real_test: float | None, double_test: float | None, double_precision_test: float | None, float_test: float | None, numeric_test: float | None, decimal_test: decimal.Decimal | None, boolean_test: bool | None, bool_test: bool | None, date_test: datetime.date | None, datetime_test: datetime.datetime | None, timestamp_test: datetime.datetime | None, character_test: str | None, varchar_test: str | None, varyingcharacter_test: str | None, nchar_test: str | None, nativecharacter_test: str | None, nvarchar_test: str | None, text_test: str | None, clob_test: str | None, json_test: str | None) -> None: - """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. +def get_many_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. ```sql - INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + decimal_test: decimal.Decimal. + + Returns: + Helper class of type `QueryResults[decimal.Decimal]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + +def get_many_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. + + ```sql + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + blob_test: memoryview. + + Returns: + Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + + +async def delete_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + """ + await conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) + + +async def delete_one_test_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + + ```sql + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? ``` Args: conn: Connection object of type `aiosqlite.Connection` used to execute the query. table_id: int. - int_test: int | None. - bigint_test: int | None. - smallint_test: int | None. - tinyint_test: int | None. - int2_test: int | None. - int8_test: int | None. - bigserial_test: int | None. - blob_test: memoryview | None. - real_test: float | None. - double_test: float | None. - double_precision_test: float | None. - float_test: float | None. - numeric_test: float | None. - decimal_test: decimal.Decimal | None. - boolean_test: bool | None. - bool_test: bool | None. - date_test: datetime.date | None. - datetime_test: datetime.datetime | None. - timestamp_test: datetime.datetime | None. - character_test: str | None. - varchar_test: str | None. - varyingcharacter_test: str | None. - nchar_test: str | None. - nativecharacter_test: str | None. - nvarchar_test: str | None. - text_test: str | None. - clob_test: str | None. - json_test: str | None. """ - await conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, (table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) - - -async def insert_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> None: - """Execute SQL query with `name: InsertOneSqliteType :exec`. + await conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) + + +async def insert_result_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. ```sql INSERT INTO test_sqlite_types ( @@ -1194,12 +1326,118 @@ async def insert_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_te text_test: str. clob_test: str. json_test: str. + + Returns: + The result of type `aiosqlite.Cursor` returned when executing the query. """ - await conn.execute(INSERT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return await conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) -async def insert_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. +async def update_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + The result of type `aiosqlite.Cursor` returned when executing the query. + """ + return await conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +async def delete_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + The result of type `aiosqlite.Cursor` returned when executing the query. + """ + return await conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +async def insert_rows_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. ```sql INSERT INTO test_sqlite_types ( @@ -1250,13 +1488,137 @@ async def insert_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, json_test: str. Returns: - The result of type `aiosqlite.Cursor` returned when executing the query. + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - return await conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args)).rowcount -async def insert_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int: - """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. +async def update_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + +async def delete_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + +async def create_rows_table(conn: aiosqlite.Connection) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await conn.execute(CREATE_ROWS_TABLE)).rowcount + + +async def insert_last_id_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. ```sql INSERT INTO test_sqlite_types ( @@ -1307,9 +1669,80 @@ async def insert_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, i json_test: str. Returns: - The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args)).lastrowid + + +async def update_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + return (await conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid + + +async def delete_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. """ - return (await conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test))).rowcount + return (await conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid async def insert_type_override(conn: aiosqlite.Connection, *, id_: int, text_test: UserString | None) -> None: @@ -1327,16 +1760,14 @@ async def insert_type_override(conn: aiosqlite.Connection, *, id_: int, text_tes id_: int. text_test: UserString | None. """ - await conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test))) + await conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) -async def update_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: - """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. +async def get_one_type_override(conn: aiosqlite.Connection, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE id = ? ``` Args: @@ -1345,18 +1776,19 @@ async def update_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int id_: int. Returns: - The id (`int | None`) of the last affected row. Will be `None` if no rows are affected. + Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. """ - return (await conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid + row = await (await conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) -async def update_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. +def get_many_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? ``` Args: @@ -1365,18 +1797,20 @@ async def update_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) id_: int. Returns: - The result of type `aiosqlite.Cursor` returned when executing the query. + Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. """ - return await conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_, )) + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) -async def update_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + +async def get_one_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? ``` Args: @@ -1385,6 +1819,48 @@ async def update_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) - id_: int. Returns: - The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + Result of type `UserString` fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + +def get_many_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[UserString | None]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + +async def delete_type_override(conn: aiosqlite.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. """ - return (await conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount + await conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_aiosqlite/dataclass/test_aiosqlite_dataclass_classes.py b/test/driver_aiosqlite/dataclass/test_aiosqlite_dataclass_classes.py index a664d40f..f257e477 100644 --- a/test/driver_aiosqlite/dataclass/test_aiosqlite_dataclass_classes.py +++ b/test/driver_aiosqlite/dataclass/test_aiosqlite_dataclass_classes.py @@ -39,12 +39,12 @@ class TestDataclassClasses: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestSqliteType: return models.TestSqliteType( - id=random.randint(1, 10000000), + id_=random.randint(1, 10000000), int_test=42, bigint_test=9_007_199_254_740_991, smallint_test=32_767, @@ -78,7 +78,7 @@ def model(self) -> models.TestSqliteType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: return models.TestInnerSqliteType( - table_id=model.id, + table_id=model.id_, int_test=None, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -125,7 +125,7 @@ async def test_insert( model: models.TestSqliteType, ) -> None: await queries_obj.insert_one_sqlite_type( - id_=model.id, + id_=model.id_, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -157,9 +157,7 @@ async def test_insert( ) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::inner_insert", depends=["AiosqliteTestDataclassClasses::insert"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::inner_insert", depends=["AiosqliteTestDataclassClasses::insert"]) async def test_inner_insert( self, queries_obj: queries.Queries, @@ -198,15 +196,13 @@ async def test_inner_insert( ) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_one", depends=["AiosqliteTestDataclassClasses::inner_insert"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_one", depends=["AiosqliteTestDataclassClasses::inner_insert"]) async def test_get_one( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_sqlite_type(id_=model.id) + result = await queries_obj.get_one_sqlite_type(id_=model.id_) assert result is not None @@ -215,9 +211,7 @@ async def test_get_one( assert result == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_one_none", depends=["AiosqliteTestDataclassClasses::get_one"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_one_none", depends=["AiosqliteTestDataclassClasses::get_one"]) async def test_get_one_none( self, queries_obj: queries.Queries, @@ -227,9 +221,7 @@ async def test_get_one_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_one_inner", depends=["AiosqliteTestDataclassClasses::get_one_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_one_inner", depends=["AiosqliteTestDataclassClasses::get_one_none"]) async def test_get_one_inner( self, queries_obj: queries.Queries, @@ -256,15 +248,13 @@ async def test_get_one_inner_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_date", depends=["AiosqliteTestDataclassClasses::get_one_inner_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_date", depends=["AiosqliteTestDataclassClasses::get_one_inner_none"]) async def test_get_date( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_date(id_=model.id, date_test=model.date_test) + result = await queries_obj.get_one_date(id_=model.id_, date_test=model.date_test) assert result is not None @@ -272,9 +262,7 @@ async def test_get_date( assert result == model.date_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_date_none", depends=["AiosqliteTestDataclassClasses::get_date"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_date_none", depends=["AiosqliteTestDataclassClasses::get_date"]) async def test_get_date_none( self, queries_obj: queries.Queries, @@ -284,15 +272,13 @@ async def test_get_date_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_datetime", depends=["AiosqliteTestDataclassClasses::get_date_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_datetime", depends=["AiosqliteTestDataclassClasses::get_date_none"]) async def test_get_datetime( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_datetime(id_=model.id, datetime_test=model.datetime_test) + result = await queries_obj.get_one_datetime(id_=model.id_, datetime_test=model.datetime_test) assert result is not None @@ -300,9 +286,7 @@ async def test_get_datetime( assert result == model.datetime_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_datetime_none", depends=["AiosqliteTestDataclassClasses::get_datetime"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_datetime_none", depends=["AiosqliteTestDataclassClasses::get_datetime"]) async def test_get_datetime_none( self, queries_obj: queries.Queries, @@ -321,7 +305,7 @@ async def test_get_timestamp( queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_timestamp(id_=model.id, timestamp_test=model.timestamp_test) + result = await queries_obj.get_one_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None @@ -342,15 +326,13 @@ async def test_get_timestamp_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_bool", depends=["AiosqliteTestDataclassClasses::get_timestamp_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_bool", depends=["AiosqliteTestDataclassClasses::get_timestamp_none"]) async def test_get_bool( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_bool(id_=model.id, bool_test=model.bool_test) + result = await queries_obj.get_one_bool(id_=model.id_, bool_test=model.bool_test) assert result is not None @@ -358,9 +340,7 @@ async def test_get_bool( assert result == model.bool_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_bool_none", depends=["AiosqliteTestDataclassClasses::get_bool"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_bool_none", depends=["AiosqliteTestDataclassClasses::get_bool"]) async def test_get_bool_none( self, queries_obj: queries.Queries, @@ -370,15 +350,13 @@ async def test_get_bool_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_boolean", depends=["AiosqliteTestDataclassClasses::get_bool_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_boolean", depends=["AiosqliteTestDataclassClasses::get_bool_none"]) async def test_get_boolean( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_boolean(id_=model.id, boolean_test=model.boolean_test) + result = await queries_obj.get_one_boolean(id_=model.id_, boolean_test=model.boolean_test) assert result is not None @@ -386,9 +364,7 @@ async def test_get_boolean( assert result == model.boolean_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_boolean_none", depends=["AiosqliteTestDataclassClasses::get_boolean"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_boolean_none", depends=["AiosqliteTestDataclassClasses::get_boolean"]) async def test_get_boolean_none( self, queries_obj: queries.Queries, @@ -398,15 +374,13 @@ async def test_get_boolean_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_decimal", depends=["AiosqliteTestDataclassClasses::get_boolean_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_decimal", depends=["AiosqliteTestDataclassClasses::get_boolean_none"]) async def test_get_decimal( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_decimal(id_=model.id, decimal_test=model.decimal_test) + result = await queries_obj.get_one_decimal(id_=model.id_, decimal_test=model.decimal_test) assert result is not None @@ -414,9 +388,7 @@ async def test_get_decimal( assert result == model.decimal_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_decimal_none", depends=["AiosqliteTestDataclassClasses::get_decimal"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_decimal_none", depends=["AiosqliteTestDataclassClasses::get_decimal"]) async def test_get_decimal_none( self, queries_obj: queries.Queries, @@ -426,15 +398,13 @@ async def test_get_decimal_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_blob", depends=["AiosqliteTestDataclassClasses::get_decimal_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_blob", depends=["AiosqliteTestDataclassClasses::get_decimal_none"]) async def test_get_blob( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_blob(id_=model.id, blob_test=model.blob_test) + result = await queries_obj.get_one_blob(id_=model.id_, blob_test=model.blob_test) assert result is not None @@ -442,9 +412,7 @@ async def test_get_blob( assert result == model.blob_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_blob_none", depends=["AiosqliteTestDataclassClasses::get_blob"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_blob_none", depends=["AiosqliteTestDataclassClasses::get_blob"]) async def test_get_blob_none( self, queries_obj: queries.Queries, @@ -454,11 +422,9 @@ async def test_get_blob_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_many", depends=["AiosqliteTestDataclassClasses::get_blob_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_many", depends=["AiosqliteTestDataclassClasses::get_blob_none"]) async def test_get_many(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_sqlite_type(id_=model.id) + result = await queries_obj.get_many_sqlite_type(id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -467,20 +433,16 @@ async def test_get_many(self, queries_obj: queries.Queries, model: models.TestSq assert result[0] == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_many_iter", depends=["AiosqliteTestDataclassClasses::get_many"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_many_iter", depends=["AiosqliteTestDataclassClasses::get_many"]) async def test_get_many_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_sqlite_type(id_=model.id): + async for result in queries_obj.get_many_sqlite_type(id_=model.id_): assert result is not None assert isinstance(result, models.TestSqliteType) assert result == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::get_many_inner", depends=["AiosqliteTestDataclassClasses::get_many_iter"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::get_many_inner", depends=["AiosqliteTestDataclassClasses::get_many_iter"]) async def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: result = await queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id) @@ -495,9 +457,7 @@ async def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: m name="AiosqliteTestDataclassClasses::get_many_inner_iter", depends=["AiosqliteTestDataclassClasses::get_many_inner"], ) - async def test_get_many_inner_iter( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: + async def test_get_many_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: async for result in queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -509,12 +469,8 @@ async def test_get_many_inner_iter( name="AiosqliteTestDataclassClasses::get_many_nullable_inner", depends=["AiosqliteTestDataclassClasses::get_many_inner_iter"], ) - async def test_get_many_nullable_inner( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: - result = await queries_obj.get_many_nullable_inner_sqlite_type( - table_id=inner_model.table_id, int_test=inner_model.int_test - ) + async def test_get_many_nullable_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + result = await queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -527,12 +483,8 @@ async def test_get_many_nullable_inner( name="AiosqliteTestDataclassClasses::get_many_nullable_inner_iter", depends=["AiosqliteTestDataclassClasses::get_many_nullable_inner"], ) - async def test_get_many_nullable_inner_iter( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: - async for result in queries_obj.get_many_nullable_inner_sqlite_type( - table_id=inner_model.table_id, int_test=inner_model.int_test - ): + async def test_get_many_nullable_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + async for result in queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -544,7 +496,7 @@ async def test_get_many_nullable_inner_iter( depends=["AiosqliteTestDataclassClasses::get_many_nullable_inner_iter"], ) async def test_get_many_date(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_date(id_=model.id, date_test=model.date_test) + result = await queries_obj.get_many_date(id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -558,7 +510,7 @@ async def test_get_many_date(self, queries_obj: queries.Queries, model: models.T depends=["AiosqliteTestDataclassClasses::get_many_date"], ) async def test_get_many_date_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_date(id_=model.id, date_test=model.date_test): + async for result in queries_obj.get_many_date(id_=model.id_, date_test=model.date_test): assert result is not None assert isinstance(result, datetime.date) @@ -570,7 +522,7 @@ async def test_get_many_date_iter(self, queries_obj: queries.Queries, model: mod depends=["AiosqliteTestDataclassClasses::get_many_date_iter"], ) async def test_get_many_datetime(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_datetime(id_=model.id, datetime_test=model.datetime_test) + result = await queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -584,7 +536,7 @@ async def test_get_many_datetime(self, queries_obj: queries.Queries, model: mode depends=["AiosqliteTestDataclassClasses::get_many_datetime"], ) async def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_datetime(id_=model.id, datetime_test=model.datetime_test): + async for result in queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -596,7 +548,7 @@ async def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: depends=["AiosqliteTestDataclassClasses::get_many_datetime_iter"], ) async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_timestamp(id_=model.id, timestamp_test=model.timestamp_test) + result = await queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -610,7 +562,7 @@ async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: mod depends=["AiosqliteTestDataclassClasses::get_many_timestamp"], ) async def test_get_many_timestamp_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_timestamp(id_=model.id, timestamp_test=model.timestamp_test): + async for result in queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -622,7 +574,7 @@ async def test_get_many_timestamp_iter(self, queries_obj: queries.Queries, model depends=["AiosqliteTestDataclassClasses::get_many_timestamp_iter"], ) async def test_get_many_bool(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_bool(id_=model.id, bool_test=model.bool_test) + result = await queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -636,7 +588,7 @@ async def test_get_many_bool(self, queries_obj: queries.Queries, model: models.T depends=["AiosqliteTestDataclassClasses::get_many_bool"], ) async def test_get_many_bool_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_bool(id_=model.id, bool_test=model.bool_test): + async for result in queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test): assert result is not None assert isinstance(result, bool) @@ -648,7 +600,7 @@ async def test_get_many_bool_iter(self, queries_obj: queries.Queries, model: mod depends=["AiosqliteTestDataclassClasses::get_many_bool_iter"], ) async def test_get_many_boolean(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_boolean(id_=model.id, boolean_test=model.boolean_test) + result = await queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -662,7 +614,7 @@ async def test_get_many_boolean(self, queries_obj: queries.Queries, model: model depends=["AiosqliteTestDataclassClasses::get_many_boolean"], ) async def test_get_many_boolean_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_boolean(id_=model.id, boolean_test=model.boolean_test): + async for result in queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test): assert result is not None assert isinstance(result, bool) @@ -674,7 +626,7 @@ async def test_get_many_boolean_iter(self, queries_obj: queries.Queries, model: depends=["AiosqliteTestDataclassClasses::get_many_boolean_iter"], ) async def test_get_many_decimal(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_decimal(id_=model.id, decimal_test=model.decimal_test) + result = await queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -688,7 +640,7 @@ async def test_get_many_decimal(self, queries_obj: queries.Queries, model: model depends=["AiosqliteTestDataclassClasses::get_many_decimal"], ) async def test_get_many_decimal_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_decimal(id_=model.id, decimal_test=model.decimal_test): + async for result in queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test): assert result is not None assert isinstance(result, decimal.Decimal) @@ -700,7 +652,7 @@ async def test_get_many_decimal_iter(self, queries_obj: queries.Queries, model: depends=["AiosqliteTestDataclassClasses::get_many_decimal_iter"], ) async def test_get_many_blob(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_blob(id_=model.id, blob_test=model.blob_test) + result = await queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -714,7 +666,7 @@ async def test_get_many_blob(self, queries_obj: queries.Queries, model: models.T depends=["AiosqliteTestDataclassClasses::get_many_blob"], ) async def test_get_many_blob_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_blob(id_=model.id, blob_test=model.blob_test): + async for result in queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test): assert result is not None assert isinstance(result, memoryview) @@ -731,7 +683,7 @@ async def test_insert_result( model: models.TestSqliteType, ) -> None: result = await queries_obj.insert_result_one_sqlite_type( - id_=model.id + 1, + id_=model.id_ + 1, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -764,40 +716,34 @@ async def test_insert_result( assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::update_result", depends=["AiosqliteTestDataclassClasses::insert_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::update_result", depends=["AiosqliteTestDataclassClasses::insert_result"]) async def test_update_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.update_result_one_sqlite_type(id_=model.id + 1) + result = await queries_obj.update_result_one_sqlite_type(id_=model.id_ + 1) assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::delete_result", depends=["AiosqliteTestDataclassClasses::update_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::delete_result", depends=["AiosqliteTestDataclassClasses::update_result"]) async def test_delete_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.delete_result_one_sqlite_type(id_=model.id + 1) + result = await queries_obj.delete_result_one_sqlite_type(id_=model.id_ + 1) assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::insert_rows", depends=["AiosqliteTestDataclassClasses::delete_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::insert_rows", depends=["AiosqliteTestDataclassClasses::delete_result"]) async def test_insert_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = await queries_obj.insert_rows_one_sqlite_type( - id_=model.id + 2, + id_=model.id_ + 2, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -831,35 +777,29 @@ async def test_insert_rows( assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::update_rows", depends=["AiosqliteTestDataclassClasses::insert_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::update_rows", depends=["AiosqliteTestDataclassClasses::insert_rows"]) async def test_update_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.update_rows_one_sqlite_type(id_=model.id + 2) + result = await queries_obj.update_rows_one_sqlite_type(id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::delete_rows", depends=["AiosqliteTestDataclassClasses::update_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::delete_rows", depends=["AiosqliteTestDataclassClasses::update_rows"]) async def test_delete_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.delete_rows_one_sqlite_type(id_=model.id + 2) + result = await queries_obj.delete_rows_one_sqlite_type(id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::create_table_rows", depends=["AiosqliteTestDataclassClasses::delete_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::create_table_rows", depends=["AiosqliteTestDataclassClasses::delete_rows"]) async def test_create_table_rows( self, queries_obj: queries.Queries, @@ -882,7 +822,7 @@ async def test_insert_last_id( model: models.TestSqliteType, ) -> None: result = await queries_obj.insert_last_id_one_sqlite_type( - id_=model.id + 3, + id_=model.id_ + 3, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -913,33 +853,29 @@ async def test_insert_last_id( json_test=model.json_test, ) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::update_last_id", depends=["AiosqliteTestDataclassClasses::insert_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::update_last_id", depends=["AiosqliteTestDataclassClasses::insert_last_id"]) async def test_update_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.update_last_id_one_sqlite_type(id_=model.id + 3) + result = await queries_obj.update_last_id_one_sqlite_type(id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassClasses::delete_last_id", depends=["AiosqliteTestDataclassClasses::update_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassClasses::delete_last_id", depends=["AiosqliteTestDataclassClasses::update_last_id"]) async def test_delete_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.delete_last_id_one_sqlite_type(id_=model.id + 3) + result = await queries_obj.delete_last_id_one_sqlite_type(id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( @@ -947,36 +883,30 @@ async def test_delete_last_id( depends=["AiosqliteTestDataclassClasses::delete_last_id"], ) async def test_delete_sqlite_type(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - await queries_obj.delete_one_sqlite_type(id_=model.id) + await queries_obj.delete_one_sqlite_type(id_=model.id_) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestDataclassClasses::delete_inner_sqlite_type", depends=["AiosqliteTestDataclassClasses::delete_sqlite_type"], ) - async def test_delete_inner_sqlite_type( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: + async def test_delete_inner_sqlite_type(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: await queries_obj.delete_one_test_inner_sqlite_type(table_id=inner_model.table_id) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestDataclassClasses::insert_type_override", ) - async def test_insert_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - await queries_obj.insert_type_override(id_=override_model.id, text_test=override_model.text_test) + async def test_insert_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.insert_type_override(id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestDataclassClasses::get_one_type_override", depends=["AiosqliteTestDataclassClasses::insert_type_override"], ) - async def test_get_one_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_type_override(id_=override_model.id) + async def test_get_one_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_) assert result is not None assert result == override_model @@ -985,10 +915,8 @@ async def test_get_one_type_override( name="AiosqliteTestDataclassClasses::get_one_type_override_none", depends=["AiosqliteTestDataclassClasses::get_one_type_override"], ) - async def test_get_one_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_type_override(id_=override_model.id - 1) + async def test_get_one_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -996,10 +924,8 @@ async def test_get_one_type_override_none( name="AiosqliteTestDataclassClasses::get_many_type_override", depends=["AiosqliteTestDataclassClasses::get_one_type_override_none"], ) - async def test_get_many_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_many_type_override(id_=override_model.id) + async def test_get_many_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_type_override(id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model @@ -1008,10 +934,8 @@ async def test_get_many_type_override( name="AiosqliteTestDataclassClasses::get_one_text_type_override", depends=["AiosqliteTestDataclassClasses::get_many_type_override"], ) - async def test_get_one_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_text_type_override(id_=override_model.id) + async def test_get_one_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -1020,10 +944,8 @@ async def test_get_one_text_type_override( name="AiosqliteTestDataclassClasses::get_one_text_type_override_none", depends=["AiosqliteTestDataclassClasses::get_one_text_type_override"], ) - async def test_get_one_text_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_text_type_override(id_=override_model.id - 1) + async def test_get_one_text_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -1031,10 +953,8 @@ async def test_get_one_text_type_override_none( name="AiosqliteTestDataclassClasses::get_many_text_type_override", depends=["AiosqliteTestDataclassClasses::get_one_text_type_override_none"], ) - async def test_get_many_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_many_text_type_override(id_=override_model.id) + async def test_get_many_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_text_type_override(id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model.text_test @@ -1043,7 +963,5 @@ async def test_get_many_text_type_override( name="AiosqliteTestDataclassClasses::delete_type_override", depends=["AiosqliteTestDataclassClasses::get_many_text_type_override"], ) - async def test_delete_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - await queries_obj.delete_type_override(id_=override_model.id) + async def test_delete_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.delete_type_override(id_=override_model.id_) diff --git a/test/driver_aiosqlite/dataclass/test_aiosqlite_dataclass_functions.py b/test/driver_aiosqlite/dataclass/test_aiosqlite_dataclass_functions.py index 468c5e50..47fc554c 100644 --- a/test/driver_aiosqlite/dataclass/test_aiosqlite_dataclass_functions.py +++ b/test/driver_aiosqlite/dataclass/test_aiosqlite_dataclass_functions.py @@ -38,12 +38,12 @@ class TestDataclassFunctions: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestSqliteType: return models.TestSqliteType( - id=random.randint(1, 10000000), + id_=random.randint(1, 10000000), int_test=42, bigint_test=9_007_199_254_740_991, smallint_test=32_767, @@ -77,7 +77,7 @@ def model(self) -> models.TestSqliteType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: return models.TestInnerSqliteType( - table_id=model.id, + table_id=model.id_, int_test=None, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -117,7 +117,7 @@ async def test_insert( ) -> None: await queries.insert_one_sqlite_type( conn=aiosqlite_conn, - id_=model.id, + id_=model.id_, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -149,9 +149,7 @@ async def test_insert( ) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::inner_insert", depends=["AiosqliteTestDataclassFunctions::insert"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::inner_insert", depends=["AiosqliteTestDataclassFunctions::insert"]) async def test_inner_insert( self, aiosqlite_conn: aiosqlite.Connection, @@ -191,15 +189,13 @@ async def test_inner_insert( ) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::get_one", depends=["AiosqliteTestDataclassFunctions::inner_insert"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::get_one", depends=["AiosqliteTestDataclassFunctions::inner_insert"]) async def test_get_one( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_sqlite_type(conn=aiosqlite_conn, id_=model.id) + result = await queries.get_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_) assert result is not None @@ -208,9 +204,7 @@ async def test_get_one( assert result == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::get_one_none", depends=["AiosqliteTestDataclassFunctions::get_one"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::get_one_none", depends=["AiosqliteTestDataclassFunctions::get_one"]) async def test_get_one_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -220,9 +214,7 @@ async def test_get_one_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::get_one_inner", depends=["AiosqliteTestDataclassFunctions::get_one_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::get_one_inner", depends=["AiosqliteTestDataclassFunctions::get_one_none"]) async def test_get_one_inner( self, aiosqlite_conn: aiosqlite.Connection, @@ -258,7 +250,7 @@ async def test_get_date( aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_date(conn=aiosqlite_conn, id_=model.id, date_test=model.date_test) + result = await queries.get_one_date(conn=aiosqlite_conn, id_=model.id_, date_test=model.date_test) assert result is not None @@ -266,9 +258,7 @@ async def test_get_date( assert result == model.date_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::get_date_none", depends=["AiosqliteTestDataclassFunctions::get_date"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::get_date_none", depends=["AiosqliteTestDataclassFunctions::get_date"]) async def test_get_date_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -278,15 +268,13 @@ async def test_get_date_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::get_datetime", depends=["AiosqliteTestDataclassFunctions::get_date_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::get_datetime", depends=["AiosqliteTestDataclassFunctions::get_date_none"]) async def test_get_datetime( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_datetime(conn=aiosqlite_conn, id_=model.id, datetime_test=model.datetime_test) + result = await queries.get_one_datetime(conn=aiosqlite_conn, id_=model.id_, datetime_test=model.datetime_test) assert result is not None @@ -316,7 +304,7 @@ async def test_get_timestamp( aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_timestamp(conn=aiosqlite_conn, id_=model.id, timestamp_test=model.timestamp_test) + result = await queries.get_one_timestamp(conn=aiosqlite_conn, id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None @@ -346,7 +334,7 @@ async def test_get_bool( aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_bool(conn=aiosqlite_conn, id_=model.id, bool_test=model.bool_test) + result = await queries.get_one_bool(conn=aiosqlite_conn, id_=model.id_, bool_test=model.bool_test) assert result is not None @@ -354,9 +342,7 @@ async def test_get_bool( assert result == model.bool_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::get_bool_none", depends=["AiosqliteTestDataclassFunctions::get_bool"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::get_bool_none", depends=["AiosqliteTestDataclassFunctions::get_bool"]) async def test_get_bool_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -366,15 +352,13 @@ async def test_get_bool_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::get_boolean", depends=["AiosqliteTestDataclassFunctions::get_bool_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::get_boolean", depends=["AiosqliteTestDataclassFunctions::get_bool_none"]) async def test_get_boolean( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_boolean(conn=aiosqlite_conn, id_=model.id, boolean_test=model.boolean_test) + result = await queries.get_one_boolean(conn=aiosqlite_conn, id_=model.id_, boolean_test=model.boolean_test) assert result is not None @@ -404,7 +388,7 @@ async def test_get_decimal( aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_decimal(conn=aiosqlite_conn, id_=model.id, decimal_test=model.decimal_test) + result = await queries.get_one_decimal(conn=aiosqlite_conn, id_=model.id_, decimal_test=model.decimal_test) assert result is not None @@ -425,15 +409,13 @@ async def test_get_decimal_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::get_blob", depends=["AiosqliteTestDataclassFunctions::get_decimal_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::get_blob", depends=["AiosqliteTestDataclassFunctions::get_decimal_none"]) async def test_get_blob( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_blob(conn=aiosqlite_conn, id_=model.id, blob_test=model.blob_test) + result = await queries.get_one_blob(conn=aiosqlite_conn, id_=model.id_, blob_test=model.blob_test) assert result is not None @@ -441,9 +423,7 @@ async def test_get_blob( assert result == model.blob_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::get_blob_none", depends=["AiosqliteTestDataclassFunctions::get_blob"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::get_blob_none", depends=["AiosqliteTestDataclassFunctions::get_blob"]) async def test_get_blob_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -453,11 +433,9 @@ async def test_get_blob_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::get_many", depends=["AiosqliteTestDataclassFunctions::get_blob_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::get_many", depends=["AiosqliteTestDataclassFunctions::get_blob_none"]) async def test_get_many(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id) + result = await queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -466,11 +444,9 @@ async def test_get_many(self, aiosqlite_conn: aiosqlite.Connection, model: model assert result[0] == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::get_many_iter", depends=["AiosqliteTestDataclassFunctions::get_many"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::get_many_iter", depends=["AiosqliteTestDataclassFunctions::get_many"]) async def test_get_many_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - async for result in queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id): + async for result in queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id_): assert result is not None assert isinstance(result, models.TestSqliteType) @@ -481,9 +457,7 @@ async def test_get_many_iter(self, aiosqlite_conn: aiosqlite.Connection, model: name="AiosqliteTestDataclassFunctions::get_many_inner", depends=["AiosqliteTestDataclassFunctions::get_many_iter"], ) - async def test_get_many_inner( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + async def test_get_many_inner(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: result = await queries.get_many_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id) assert result is not None @@ -497,9 +471,7 @@ async def test_get_many_inner( name="AiosqliteTestDataclassFunctions::get_many_inner_iter", depends=["AiosqliteTestDataclassFunctions::get_many_inner"], ) - async def test_get_many_inner_iter( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + async def test_get_many_inner_iter(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: async for result in queries.get_many_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -511,12 +483,8 @@ async def test_get_many_inner_iter( name="AiosqliteTestDataclassFunctions::get_many_nullable_inner", depends=["AiosqliteTestDataclassFunctions::get_many_inner_iter"], ) - async def test_get_many_nullable_inner( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: - result = await queries.get_many_nullable_inner_sqlite_type( - conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test - ) + async def test_get_many_nullable_inner(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: + result = await queries.get_many_nullable_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -529,12 +497,8 @@ async def test_get_many_nullable_inner( name="AiosqliteTestDataclassFunctions::get_many_nullable_inner_iter", depends=["AiosqliteTestDataclassFunctions::get_many_nullable_inner"], ) - async def test_get_many_nullable_inner_iter( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: - async for result in queries.get_many_nullable_inner_sqlite_type( - conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test - ): + async def test_get_many_nullable_inner_iter(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: + async for result in queries.get_many_nullable_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -546,7 +510,7 @@ async def test_get_many_nullable_inner_iter( depends=["AiosqliteTestDataclassFunctions::get_many_nullable_inner_iter"], ) async def test_get_many_date(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_date(conn=aiosqlite_conn, id_=model.id, date_test=model.date_test) + result = await queries.get_many_date(conn=aiosqlite_conn, id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -560,7 +524,7 @@ async def test_get_many_date(self, aiosqlite_conn: aiosqlite.Connection, model: depends=["AiosqliteTestDataclassFunctions::get_many_date"], ) async def test_get_many_date_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - async for result in queries.get_many_date(conn=aiosqlite_conn, id_=model.id, date_test=model.date_test): + async for result in queries.get_many_date(conn=aiosqlite_conn, id_=model.id_, date_test=model.date_test): assert result is not None assert isinstance(result, datetime.date) @@ -572,7 +536,7 @@ async def test_get_many_date_iter(self, aiosqlite_conn: aiosqlite.Connection, mo depends=["AiosqliteTestDataclassFunctions::get_many_date_iter"], ) async def test_get_many_datetime(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_datetime(conn=aiosqlite_conn, id_=model.id, datetime_test=model.datetime_test) + result = await queries.get_many_datetime(conn=aiosqlite_conn, id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -585,12 +549,8 @@ async def test_get_many_datetime(self, aiosqlite_conn: aiosqlite.Connection, mod name="AiosqliteTestDataclassFunctions::get_many_datetime_iter", depends=["AiosqliteTestDataclassFunctions::get_many_datetime"], ) - async def test_get_many_datetime_iter( - self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType - ) -> None: - async for result in queries.get_many_datetime( - conn=aiosqlite_conn, id_=model.id, datetime_test=model.datetime_test - ): + async def test_get_many_datetime_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_datetime(conn=aiosqlite_conn, id_=model.id_, datetime_test=model.datetime_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -602,9 +562,7 @@ async def test_get_many_datetime_iter( depends=["AiosqliteTestDataclassFunctions::get_many_datetime_iter"], ) async def test_get_many_timestamp(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_timestamp( - conn=aiosqlite_conn, id_=model.id, timestamp_test=model.timestamp_test - ) + result = await queries.get_many_timestamp(conn=aiosqlite_conn, id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -617,12 +575,8 @@ async def test_get_many_timestamp(self, aiosqlite_conn: aiosqlite.Connection, mo name="AiosqliteTestDataclassFunctions::get_many_timestamp_iter", depends=["AiosqliteTestDataclassFunctions::get_many_timestamp"], ) - async def test_get_many_timestamp_iter( - self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType - ) -> None: - async for result in queries.get_many_timestamp( - conn=aiosqlite_conn, id_=model.id, timestamp_test=model.timestamp_test - ): + async def test_get_many_timestamp_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_timestamp(conn=aiosqlite_conn, id_=model.id_, timestamp_test=model.timestamp_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -634,7 +588,7 @@ async def test_get_many_timestamp_iter( depends=["AiosqliteTestDataclassFunctions::get_many_timestamp_iter"], ) async def test_get_many_bool(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_bool(conn=aiosqlite_conn, id_=model.id, bool_test=model.bool_test) + result = await queries.get_many_bool(conn=aiosqlite_conn, id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -648,7 +602,7 @@ async def test_get_many_bool(self, aiosqlite_conn: aiosqlite.Connection, model: depends=["AiosqliteTestDataclassFunctions::get_many_bool"], ) async def test_get_many_bool_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - async for result in queries.get_many_bool(conn=aiosqlite_conn, id_=model.id, bool_test=model.bool_test): + async for result in queries.get_many_bool(conn=aiosqlite_conn, id_=model.id_, bool_test=model.bool_test): assert result is not None assert isinstance(result, bool) @@ -660,7 +614,7 @@ async def test_get_many_bool_iter(self, aiosqlite_conn: aiosqlite.Connection, mo depends=["AiosqliteTestDataclassFunctions::get_many_bool_iter"], ) async def test_get_many_boolean(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_boolean(conn=aiosqlite_conn, id_=model.id, boolean_test=model.boolean_test) + result = await queries.get_many_boolean(conn=aiosqlite_conn, id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -673,12 +627,8 @@ async def test_get_many_boolean(self, aiosqlite_conn: aiosqlite.Connection, mode name="AiosqliteTestDataclassFunctions::get_many_boolean_iter", depends=["AiosqliteTestDataclassFunctions::get_many_boolean"], ) - async def test_get_many_boolean_iter( - self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType - ) -> None: - async for result in queries.get_many_boolean( - conn=aiosqlite_conn, id_=model.id, boolean_test=model.boolean_test - ): + async def test_get_many_boolean_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_boolean(conn=aiosqlite_conn, id_=model.id_, boolean_test=model.boolean_test): assert result is not None assert isinstance(result, bool) @@ -690,7 +640,7 @@ async def test_get_many_boolean_iter( depends=["AiosqliteTestDataclassFunctions::get_many_boolean_iter"], ) async def test_get_many_decimal(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_decimal(conn=aiosqlite_conn, id_=model.id, decimal_test=model.decimal_test) + result = await queries.get_many_decimal(conn=aiosqlite_conn, id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -703,12 +653,8 @@ async def test_get_many_decimal(self, aiosqlite_conn: aiosqlite.Connection, mode name="AiosqliteTestDataclassFunctions::get_many_decimal_iter", depends=["AiosqliteTestDataclassFunctions::get_many_decimal"], ) - async def test_get_many_decimal_iter( - self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType - ) -> None: - async for result in queries.get_many_decimal( - conn=aiosqlite_conn, id_=model.id, decimal_test=model.decimal_test - ): + async def test_get_many_decimal_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_decimal(conn=aiosqlite_conn, id_=model.id_, decimal_test=model.decimal_test): assert result is not None assert isinstance(result, decimal.Decimal) @@ -720,7 +666,7 @@ async def test_get_many_decimal_iter( depends=["AiosqliteTestDataclassFunctions::get_many_decimal_iter"], ) async def test_get_many_blob(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_blob(conn=aiosqlite_conn, id_=model.id, blob_test=model.blob_test) + result = await queries.get_many_blob(conn=aiosqlite_conn, id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -734,7 +680,7 @@ async def test_get_many_blob(self, aiosqlite_conn: aiosqlite.Connection, model: depends=["AiosqliteTestDataclassFunctions::get_many_blob"], ) async def test_get_many_blob_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - async for result in queries.get_many_blob(conn=aiosqlite_conn, id_=model.id, blob_test=model.blob_test): + async for result in queries.get_many_blob(conn=aiosqlite_conn, id_=model.id_, blob_test=model.blob_test): assert result is not None assert isinstance(result, memoryview) @@ -752,7 +698,7 @@ async def test_insert_result( ) -> None: result = await queries.insert_result_one_sqlite_type( conn=aiosqlite_conn, - id_=model.id + 1, + id_=model.id_ + 1, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -794,7 +740,7 @@ async def test_update_result( aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.update_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 1) + result = await queries.update_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 1) assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") @@ -807,13 +753,11 @@ async def test_delete_result( aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.delete_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 1) + result = await queries.delete_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 1) assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::insert_rows", depends=["AiosqliteTestDataclassFunctions::delete_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::insert_rows", depends=["AiosqliteTestDataclassFunctions::delete_result"]) async def test_insert_rows( self, aiosqlite_conn: aiosqlite.Connection, @@ -821,7 +765,7 @@ async def test_insert_rows( ) -> None: result = await queries.insert_rows_one_sqlite_type( conn=aiosqlite_conn, - id_=model.id + 2, + id_=model.id_ + 2, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -855,28 +799,24 @@ async def test_insert_rows( assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::update_rows", depends=["AiosqliteTestDataclassFunctions::insert_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::update_rows", depends=["AiosqliteTestDataclassFunctions::insert_rows"]) async def test_update_rows( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.update_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 2) + result = await queries.update_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestDataclassFunctions::delete_rows", depends=["AiosqliteTestDataclassFunctions::update_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestDataclassFunctions::delete_rows", depends=["AiosqliteTestDataclassFunctions::update_rows"]) async def test_delete_rows( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.delete_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 2) + result = await queries.delete_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 @@ -907,7 +847,7 @@ async def test_insert_last_id( ) -> None: result = await queries.insert_last_id_one_sqlite_type( conn=aiosqlite_conn, - id_=model.id + 3, + id_=model.id_ + 3, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -938,7 +878,7 @@ async def test_insert_last_id( json_test=model.json_test, ) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( @@ -950,9 +890,9 @@ async def test_update_last_id( aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.update_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 3) + result = await queries.update_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( @@ -964,9 +904,9 @@ async def test_delete_last_id( aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.delete_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 3) + result = await queries.delete_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( @@ -974,38 +914,30 @@ async def test_delete_last_id( depends=["AiosqliteTestDataclassFunctions::delete_last_id"], ) async def test_delete_sqlite_type(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - await queries.delete_one_sqlite_type(conn=aiosqlite_conn, id_=model.id) + await queries.delete_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestDataclassFunctions::delete_inner_sqlite_type", depends=["AiosqliteTestDataclassFunctions::delete_sqlite_type"], ) - async def test_delete_inner_sqlite_type( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + async def test_delete_inner_sqlite_type(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: await queries.delete_one_test_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestDataclassFunctions::insert_type_override", ) - async def test_insert_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - await queries.insert_type_override( - conn=aiosqlite_conn, id_=override_model.id, text_test=override_model.text_test - ) + async def test_insert_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + await queries.insert_type_override(conn=aiosqlite_conn, id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestDataclassFunctions::get_one_type_override", depends=["AiosqliteTestDataclassFunctions::insert_type_override"], ) - async def test_get_one_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_get_one_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id_) assert result is not None assert result == override_model @@ -1014,10 +946,8 @@ async def test_get_one_type_override( name="AiosqliteTestDataclassFunctions::get_one_type_override_none", depends=["AiosqliteTestDataclassFunctions::get_one_type_override"], ) - async def test_get_one_type_override_none( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id - 1) + async def test_get_one_type_override_none(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -1025,10 +955,8 @@ async def test_get_one_type_override_none( name="AiosqliteTestDataclassFunctions::get_many_type_override", depends=["AiosqliteTestDataclassFunctions::get_one_type_override_none"], ) - async def test_get_many_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_many_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_get_many_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_type_override(conn=aiosqlite_conn, id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model @@ -1037,10 +965,8 @@ async def test_get_many_type_override( name="AiosqliteTestDataclassFunctions::get_one_text_type_override", depends=["AiosqliteTestDataclassFunctions::get_many_type_override"], ) - async def test_get_one_text_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_get_one_text_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -1049,10 +975,8 @@ async def test_get_one_text_type_override( name="AiosqliteTestDataclassFunctions::get_one_text_type_override_none", depends=["AiosqliteTestDataclassFunctions::get_one_text_type_override"], ) - async def test_get_one_text_type_override_none( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id - 1) + async def test_get_one_text_type_override_none(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -1060,10 +984,8 @@ async def test_get_one_text_type_override_none( name="AiosqliteTestDataclassFunctions::get_many_text_type_override", depends=["AiosqliteTestDataclassFunctions::get_one_text_type_override_none"], ) - async def test_get_many_text_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_many_text_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_get_many_text_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_text_type_override(conn=aiosqlite_conn, id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model.text_test @@ -1072,7 +994,5 @@ async def test_get_many_text_type_override( name="AiosqliteTestDataclassFunctions::delete_type_override", depends=["AiosqliteTestDataclassFunctions::get_many_text_type_override"], ) - async def test_delete_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - await queries.delete_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_delete_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + await queries.delete_type_override(conn=aiosqlite_conn, id_=override_model.id_) diff --git a/test/driver_aiosqlite/msgspec/classes/__init__.py b/test/driver_aiosqlite/msgspec/classes/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_aiosqlite/msgspec/classes/__init__.py +++ b/test/driver_aiosqlite/msgspec/classes/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_aiosqlite/msgspec/classes/models.py b/test/driver_aiosqlite/msgspec/classes/models.py index 0819a9c8..69e8f334 100644 --- a/test/driver_aiosqlite/msgspec/classes/models.py +++ b/test/driver_aiosqlite/msgspec/classes/models.py @@ -1,8 +1,9 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -91,7 +92,7 @@ class TestSqliteType(msgspec.Struct): """Model representing TestSqliteType. Attributes: - id -- int + id_ -- int int_test -- int bigint_test -- int smallint_test -- int @@ -122,7 +123,7 @@ class TestSqliteType(msgspec.Struct): json_test -- str """ - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -157,9 +158,9 @@ class TestTypeOverride(msgspec.Struct): """Model representing TestTypeOverride. Attributes: - id -- int + id_ -- int text_test -- UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_aiosqlite/msgspec/classes/queries.py b/test/driver_aiosqlite/msgspec/classes/queries.py index 4225502b..85c79a4f 100644 --- a/test/driver_aiosqlite/msgspec/classes/queries.py +++ b/test/driver_aiosqlite/msgspec/classes/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -21,7 +23,7 @@ import collections.abc import sqlite3 - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None from test.driver_aiosqlite.msgspec.classes import models @@ -81,71 +83,74 @@ def _convert_memoryview(val: bytes) -> memoryview: aiosqlite.register_converter("blob", _convert_memoryview) -CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows -CREATE TABLE test_create_rows_table -( - id int PRIMARY KEY NOT NULL, - test int NOT NULL -) -""" - -DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec -DELETE FROM test_inner_sqlite_types -WHERE test_inner_sqlite_types.table_id = ? +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ -DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? """ -DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec -DELETE -FROM test_type_override -WHERE test_type_override.id = ? +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ -GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many -SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many @@ -156,67 +161,46 @@ def _convert_memoryview(val: bytes) -> memoryview: SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? """ -GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? -""" - -GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? -""" - -GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? -""" - -GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? -""" - -GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one -SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? -""" - -GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one -SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = ? +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? """ -INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -231,37 +215,19 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec -INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? """ -INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec -INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -276,7 +242,27 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -291,35 +277,48 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec INSERT INTO test_type_override ( id, text_test ) VALUES (? ,?) """ -UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? """ -UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? """ -UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? """ +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" -T = typing.TypeVar("T") +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db.""" __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") @@ -362,9 +361,11 @@ def __await__( Returns: A sequence of decoded objects of type `T`. """ + async def _wrapper() -> collections.abc.Sequence[T]: result = await (await self._conn.execute(self._sql, self._args)).fetchall() return [self._decode_hook(row) for row in result] + return _wrapper().__await__() async def __anext__(self) -> T: @@ -410,132 +411,389 @@ def conn(self) -> aiosqlite.Connection: """ return self._conn - async def create_rows_table(self) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + async def insert_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Returns: - int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. - """ - return (await self._conn.execute(CREATE_ROWS_TABLE)).rowcount - - async def delete_last_id_one_sqlite_type(self, *, id_: int) -> int | None: - """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Arguments: id_ -- int. - - Returns: - int | None -- The id of the last affected row. Will be `None` if no rows are affected. + int_test -- int. + bigint_test -- int. + smallint_test -- int. + tinyint_test -- int. + int2_test -- int. + int8_test -- int. + bigserial_test -- int. + blob_test -- memoryview. + real_test -- float. + double_test -- float. + double_precision_test -- float. + float_test -- float. + numeric_test -- float. + decimal_test -- decimal.Decimal. + boolean_test -- bool. + bool_test -- bool. + date_test -- datetime.date. + datetime_test -- datetime.datetime. + timestamp_test -- datetime.datetime. + character_test -- str. + varchar_test -- str. + varyingcharacter_test -- str. + nchar_test -- str. + nativecharacter_test -- str. + nvarchar_test -- str. + text_test -- str. + clob_test -- str. + json_test -- str. """ - return (await self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await self._conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) - async def delete_one_sqlite_type(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneSqliteType :exec`. + async def insert_one_inner_sqlite_type( + self, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, + ) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Arguments: - id_ -- int. + table_id -- int. + int_test -- int | None. + bigint_test -- int | None. + smallint_test -- int | None. + tinyint_test -- int | None. + int2_test -- int | None. + int8_test -- int | None. + bigserial_test -- int | None. + blob_test -- memoryview | None. + real_test -- float | None. + double_test -- float | None. + double_precision_test -- float | None. + float_test -- float | None. + numeric_test -- float | None. + decimal_test -- decimal.Decimal | None. + boolean_test -- bool | None. + bool_test -- bool | None. + date_test -- datetime.date | None. + datetime_test -- datetime.datetime | None. + timestamp_test -- datetime.datetime | None. + character_test -- str | None. + varchar_test -- str | None. + varyingcharacter_test -- str | None. + nchar_test -- str | None. + nativecharacter_test -- str | None. + nvarchar_test -- str | None. + text_test -- str | None. + clob_test -- str | None. + json_test -- str | None. """ - await self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, )) + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) - async def delete_one_test_inner_sqlite_type(self, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + async def get_one_sqlite_type(self, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. ```sql - DELETE FROM test_inner_sqlite_types - WHERE test_inner_sqlite_types.table_id = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Arguments: - table_id -- int. + id_ -- int. + + Returns: + models.TestSqliteType -- Result fetched from the db. Will be `None` if not found. """ - await self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, )) + row = await (await self._conn.execute(GET_ONE_SQLITE_TYPE, (id_,))).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) - async def delete_result_one_sqlite_type(self, *, id_: int) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + async def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Arguments: - id_ -- int. + table_id -- int. Returns: - aiosqlite.Cursor -- The result returned when executing the query. + models.TestInnerSqliteType -- Result fetched from the db. Will be `None` if not found. """ - return await self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, )) + row = await (await self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,))).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) - async def delete_rows_one_sqlite_type(self, *, id_: int) -> int: - """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + async def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Arguments: id_ -- int. + date_test -- datetime.date. Returns: - int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + datetime.date -- Result fetched from the db. Will be `None` if not found. """ - return (await self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount + row = await (await self._conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() + if row is None: + return None + return row[0] - async def delete_type_override(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. + async def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Arguments: id_ -- int. + datetime_test -- datetime.datetime. + + Returns: + datetime.datetime -- Result fetched from the db. Will be `None` if not found. """ - await self._conn.execute(DELETE_TYPE_OVERRIDE, (id_, )) + row = await (await self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. + async def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Arguments: id_ -- int. - blob_test -- memoryview. + timestamp_test -- datetime.datetime. Returns: - QueryResults[memoryview] -- Helper class that allows both iteration and normal fetching of data from the db. + datetime.datetime -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[memoryview](self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + row = await (await self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBool :many`. + async def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -546,12 +804,15 @@ def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: bool_test -- bool. Returns: - QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. + bool -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + row = await (await self._conn.execute(GET_ONE_BOOL, (id_, bool_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. + async def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -562,57 +823,99 @@ def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool boolean_test -- bool. Returns: - QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. + bool -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + row = await (await self._conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: - """Fetch many from the db using the SQL query with `name: GetManyDate :many`. + async def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Arguments: id_ -- int. - date_test -- datetime.date. + decimal_test -- decimal.Decimal. Returns: - QueryResults[datetime.date] -- Helper class that allows both iteration and normal fetching of data from the db. + decimal.Decimal -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.date](self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + row = await (await self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. + async def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Arguments: id_ -- int. - datetime_test -- datetime.datetime. + blob_test -- memoryview. Returns: - QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. + memoryview -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) + row = await (await self._conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone() + if row is None: + return None + return row[0] - def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: - """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. + def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Arguments: id_ -- int. - decimal_test -- decimal.Decimal. Returns: - QueryResults[decimal.Decimal] -- Helper class that allows both iteration and normal fetching of data from the db. + QueryResults[models.TestSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. """ - return QueryResults[decimal.Decimal](self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) def get_many_inner_sqlite_type(self, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. @@ -627,9 +930,41 @@ def get_many_inner_sqlite_type(self, *, table_id: int) -> QueryResults[models.Te Returns: QueryResults[models.TestInnerSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. @@ -645,43 +980,73 @@ def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | Returns: QueryResults[models.TestInnerSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) - def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. + def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Arguments: id_ -- int. + date_test -- datetime.date. Returns: - QueryResults[models.TestSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. + QueryResults[datetime.date] -- Helper class that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestSqliteType](self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + return QueryResults(self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) - def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Arguments: id_ -- int. + datetime_test -- datetime.datetime. Returns: - QueryResults[UserString] -- Helper class that allows both iteration and normal fetching of data from the db. + QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> UserString: - return UserString(row[0]) - return QueryResults[UserString](self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + return QueryResults(self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. @@ -697,46 +1062,10 @@ def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> Returns: QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - - def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: - """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. - - ```sql - SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? - ``` - - Arguments: - id_ -- int. - - Returns: - QueryResults[models.TestTypeOverride] -- Helper class that allows both iteration and normal fetching of data from the db. - """ - def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - return QueryResults[models.TestTypeOverride](self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + return QueryResults(self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - async def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. - - ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? - ``` - - Arguments: - id_ -- int. - blob_test -- memoryview. - - Returns: - memoryview -- Result fetched from the db. Will be `None` if not found. - """ - row = await (await self._conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone() - if row is None: - return None - return row[0] - - async def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBool :one`. + def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -747,15 +1076,12 @@ async def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: bool_test -- bool. Returns: - bool -- Result fetched from the db. Will be `None` if not found. + QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_BOOL, (id_, bool_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) - async def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. + def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -766,53 +1092,12 @@ async def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: boolean_test -- bool. Returns: - bool -- Result fetched from the db. Will be `None` if not found. - """ - row = await (await self._conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test))).fetchone() - if row is None: - return None - return row[0] - - async def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: - """Fetch one from the db using the SQL query with `name: GetOneDate :one`. - - ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? - ``` - - Arguments: - id_ -- int. - date_test -- datetime.date. - - Returns: - datetime.date -- Result fetched from the db. Will be `None` if not found. - """ - row = await (await self._conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() - if row is None: - return None - return row[0] - - async def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. - - ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? - ``` - - Arguments: - id_ -- int. - datetime_test -- datetime.datetime. - - Returns: - datetime.datetime -- Result fetched from the db. Will be `None` if not found. + QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) - async def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: - """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. + def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. ```sql SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? @@ -823,106 +1108,87 @@ async def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> d decimal_test -- decimal.Decimal. Returns: - decimal.Decimal -- Result fetched from the db. Will be `None` if not found. - """ - row = await (await self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() - if row is None: - return None - return row[0] - - async def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? - ``` - - Arguments: - table_id -- int. - - Returns: - models.TestInnerSqliteType -- Result fetched from the db. Will be `None` if not found. - """ - row = await (await self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id, ))).fetchone() - if row is None: - return None - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - - async def get_one_sqlite_type(self, *, id_: int) -> models.TestSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. - - ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? - ``` - - Arguments: - id_ -- int. - - Returns: - models.TestSqliteType -- Result fetched from the db. Will be `None` if not found. + QueryResults[decimal.Decimal] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_SQLITE_TYPE, (id_, ))).fetchone() - if row is None: - return None - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) - async def get_one_text_type_override(self, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Arguments: id_ -- int. + blob_test -- memoryview. Returns: - UserString -- Result fetched from the db. Will be `None` if not found. + QueryResults[memoryview] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_, ))).fetchone() - if row is None: - return None - return UserString(row[0]) + return QueryResults(self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) - async def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. + async def delete_one_sqlite_type(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? ``` Arguments: id_ -- int. - timestamp_test -- datetime.datetime. - - Returns: - datetime.datetime -- Result fetched from the db. Will be `None` if not found. """ - row = await (await self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() - if row is None: - return None - return row[0] + await self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) - async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + async def delete_one_test_inner_sqlite_type(self, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = ? + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? ``` - - Arguments: - id_ -- int. - - Returns: - models.TestTypeOverride -- Result fetched from the db. Will be `None` if not found. + + Arguments: + table_id -- int. """ - row = await (await self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_, ))).fetchone() - if row is None: - return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) + await self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) - async def insert_last_id_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int | None: - """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. + async def insert_result_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. ```sql INSERT INTO test_sqlite_types ( @@ -971,114 +1237,109 @@ async def insert_last_id_one_sqlite_type(self, *, id_: int, int_test: int, bigin json_test -- str. Returns: - int | None -- The id of the last affected row. Will be `None` if no rows are affected. + aiosqlite.Cursor -- The result returned when executing the query. """ - return (await self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test))).lastrowid + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return await self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) - async def insert_one_inner_sqlite_type(self, *, table_id: int, int_test: int | None, bigint_test: int | None, smallint_test: int | None, tinyint_test: int | None, int2_test: int | None, int8_test: int | None, bigserial_test: int | None, blob_test: memoryview | None, real_test: float | None, double_test: float | None, double_precision_test: float | None, float_test: float | None, numeric_test: float | None, decimal_test: decimal.Decimal | None, boolean_test: bool | None, bool_test: bool | None, date_test: datetime.date | None, datetime_test: datetime.datetime | None, timestamp_test: datetime.datetime | None, character_test: str | None, varchar_test: str | None, varyingcharacter_test: str | None, nchar_test: str | None, nativecharacter_test: str | None, nvarchar_test: str | None, text_test: str | None, clob_test: str | None, json_test: str | None) -> None: - """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. + async def update_result_one_sqlite_type(self, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. ```sql - INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? ``` Arguments: - table_id -- int. - int_test -- int | None. - bigint_test -- int | None. - smallint_test -- int | None. - tinyint_test -- int | None. - int2_test -- int | None. - int8_test -- int | None. - bigserial_test -- int | None. - blob_test -- memoryview | None. - real_test -- float | None. - double_test -- float | None. - double_precision_test -- float | None. - float_test -- float | None. - numeric_test -- float | None. - decimal_test -- decimal.Decimal | None. - boolean_test -- bool | None. - bool_test -- bool | None. - date_test -- datetime.date | None. - datetime_test -- datetime.datetime | None. - timestamp_test -- datetime.datetime | None. - character_test -- str | None. - varchar_test -- str | None. - varyingcharacter_test -- str | None. - nchar_test -- str | None. - nativecharacter_test -- str | None. - nvarchar_test -- str | None. - text_test -- str | None. - clob_test -- str | None. - json_test -- str | None. + id_ -- int. + + Returns: + aiosqlite.Cursor -- The result returned when executing the query. """ - await self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, (table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + return await self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) - async def insert_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> None: - """Execute SQL query with `name: InsertOneSqliteType :exec`. + async def delete_result_one_sqlite_type(self, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. ```sql - INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? ``` Arguments: id_ -- int. - int_test -- int. - bigint_test -- int. - smallint_test -- int. - tinyint_test -- int. - int2_test -- int. - int8_test -- int. - bigserial_test -- int. - blob_test -- memoryview. - real_test -- float. - double_test -- float. - double_precision_test -- float. - float_test -- float. - numeric_test -- float. - decimal_test -- decimal.Decimal. - boolean_test -- bool. - bool_test -- bool. - date_test -- datetime.date. - datetime_test -- datetime.datetime. - timestamp_test -- datetime.datetime. - character_test -- str. - varchar_test -- str. - varyingcharacter_test -- str. - nchar_test -- str. - nativecharacter_test -- str. - nvarchar_test -- str. - text_test -- str. - clob_test -- str. - json_test -- str. + + Returns: + aiosqlite.Cursor -- The result returned when executing the query. """ - await self._conn.execute(INSERT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + return await self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) - async def insert_result_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. + async def insert_rows_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. ```sql INSERT INTO test_sqlite_types ( @@ -1127,12 +1388,125 @@ async def insert_result_one_sqlite_type(self, *, id_: int, int_test: int, bigint json_test -- str. Returns: - aiosqlite.Cursor -- The result returned when executing the query. + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - return await self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args)).rowcount - async def insert_rows_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int: - """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. + async def update_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + async def delete_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + async def create_rows_table(self) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Returns: + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await self._conn.execute(CREATE_ROWS_TABLE)).rowcount + + async def insert_last_id_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. ```sql INSERT INTO test_sqlite_types ( @@ -1181,9 +1555,74 @@ async def insert_rows_one_sqlite_type(self, *, id_: int, int_test: int, bigint_t json_test -- str. Returns: - int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + int -- The id of the last affected row. Will be `None` if no rows are affected. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args)).lastrowid + + async def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + int -- The id of the last affected row. Will be `None` if no rows are affected. + """ + return (await self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid + + async def delete_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + int -- The id of the last affected row. Will be `None` if no rows are affected. """ - return (await self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test))).rowcount + return (await self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid async def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: """Execute SQL query with `name: InsertTypeOverride :exec`. @@ -1198,55 +1637,92 @@ async def insert_type_override(self, *, id_: int, text_test: UserString | None) id_ -- int. text_test -- UserString | None. """ - await self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test))) + await self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) - async def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: - """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE id = ? ``` Arguments: id_ -- int. Returns: - int | None -- The id of the last affected row. Will be `None` if no rows are affected. + models.TestTypeOverride -- Result fetched from the db. Will be `None` if not found. """ - return (await self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid + row = await (await self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - async def update_result_one_sqlite_type(self, *, id_: int) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? ``` Arguments: id_ -- int. Returns: - aiosqlite.Cursor -- The result returned when executing the query. + QueryResults[models.TestTypeOverride] -- Helper class that allows both iteration and normal fetching of data from the db. """ - return await self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_, )) - async def update_rows_one_sqlite_type(self, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + async def get_one_text_type_override(self, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + UserString -- Result fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? ``` Arguments: id_ -- int. Returns: - int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + QueryResults[UserString | None] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + async def delete_type_override(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Arguments: + id_ -- int. """ - return (await self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount + await self._conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_aiosqlite/msgspec/functions/__init__.py b/test/driver_aiosqlite/msgspec/functions/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_aiosqlite/msgspec/functions/__init__.py +++ b/test/driver_aiosqlite/msgspec/functions/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_aiosqlite/msgspec/functions/models.py b/test/driver_aiosqlite/msgspec/functions/models.py index 0819a9c8..69e8f334 100644 --- a/test/driver_aiosqlite/msgspec/functions/models.py +++ b/test/driver_aiosqlite/msgspec/functions/models.py @@ -1,8 +1,9 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -91,7 +92,7 @@ class TestSqliteType(msgspec.Struct): """Model representing TestSqliteType. Attributes: - id -- int + id_ -- int int_test -- int bigint_test -- int smallint_test -- int @@ -122,7 +123,7 @@ class TestSqliteType(msgspec.Struct): json_test -- str """ - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -157,9 +158,9 @@ class TestTypeOverride(msgspec.Struct): """Model representing TestTypeOverride. Attributes: - id -- int + id_ -- int text_test -- UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_aiosqlite/msgspec/functions/queries.py b/test/driver_aiosqlite/msgspec/functions/queries.py index cfd53289..ce027c28 100644 --- a/test/driver_aiosqlite/msgspec/functions/queries.py +++ b/test/driver_aiosqlite/msgspec/functions/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -59,7 +61,7 @@ import collections.abc import sqlite3 - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None from test.driver_aiosqlite.msgspec.functions import models @@ -119,71 +121,74 @@ def _convert_memoryview(val: bytes) -> memoryview: aiosqlite.register_converter("blob", _convert_memoryview) -CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows -CREATE TABLE test_create_rows_table -( - id int PRIMARY KEY NOT NULL, - test int NOT NULL -) -""" - -DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec -DELETE FROM test_inner_sqlite_types -WHERE test_inner_sqlite_types.table_id = ? +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ -DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? """ -DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec -DELETE -FROM test_type_override -WHERE test_type_override.id = ? +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ -GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many -SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many @@ -194,67 +199,46 @@ def _convert_memoryview(val: bytes) -> memoryview: SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? """ -GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? -""" - -GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? -""" - -GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? -""" - -GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? -""" - -GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one -SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? -""" - -GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one -SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = ? +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? """ -INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -269,37 +253,19 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec -INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? """ -INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec -INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -314,7 +280,27 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -329,35 +315,48 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec INSERT INTO test_type_override ( id, text_test ) VALUES (? ,?) """ -UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? """ -UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? """ -UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? """ +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" -T = typing.TypeVar("T") +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db.""" __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") @@ -400,9 +399,11 @@ def __await__( Returns: A sequence of decoded objects of type `T`. """ + async def _wrapper() -> collections.abc.Sequence[T]: result = await (await self._conn.execute(self._sql, self._args)).fetchall() return [self._decode_hook(row) for row in result] + return _wrapper().__await__() async def __anext__(self) -> T: @@ -426,150 +427,403 @@ async def __anext__(self) -> T: return self._decode_hook(record) -async def create_rows_table(conn: aiosqlite.Connection) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. +async def insert_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Arguments: - conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - - Returns: - int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. - """ - return (await conn.execute(CREATE_ROWS_TABLE)).rowcount - - -async def delete_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: - """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. id_ -- int. - - Returns: - int | None -- The id of the last affected row. Will be `None` if no rows are affected. + int_test -- int. + bigint_test -- int. + smallint_test -- int. + tinyint_test -- int. + int2_test -- int. + int8_test -- int. + bigserial_test -- int. + blob_test -- memoryview. + real_test -- float. + double_test -- float. + double_precision_test -- float. + float_test -- float. + numeric_test -- float. + decimal_test -- decimal.Decimal. + boolean_test -- bool. + bool_test -- bool. + date_test -- datetime.date. + datetime_test -- datetime.datetime. + timestamp_test -- datetime.datetime. + character_test -- str. + varchar_test -- str. + varyingcharacter_test -- str. + nchar_test -- str. + nativecharacter_test -- str. + nvarchar_test -- str. + text_test -- str. + clob_test -- str. + json_test -- str. """ - return (await conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid - - -async def delete_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneSqliteType :exec`. + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) + + +async def insert_one_inner_sqlite_type( + conn: aiosqlite.Connection, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, +) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - id_ -- int. + table_id -- int. + int_test -- int | None. + bigint_test -- int | None. + smallint_test -- int | None. + tinyint_test -- int | None. + int2_test -- int | None. + int8_test -- int | None. + bigserial_test -- int | None. + blob_test -- memoryview | None. + real_test -- float | None. + double_test -- float | None. + double_precision_test -- float | None. + float_test -- float | None. + numeric_test -- float | None. + decimal_test -- decimal.Decimal | None. + boolean_test -- bool | None. + bool_test -- bool | None. + date_test -- datetime.date | None. + datetime_test -- datetime.datetime | None. + timestamp_test -- datetime.datetime | None. + character_test -- str | None. + varchar_test -- str | None. + varyingcharacter_test -- str | None. + nchar_test -- str | None. + nativecharacter_test -- str | None. + nvarchar_test -- str | None. + text_test -- str | None. + clob_test -- str | None. + json_test -- str | None. """ - await conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, )) + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) -async def delete_one_test_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. +async def get_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. ```sql - DELETE FROM test_inner_sqlite_types - WHERE test_inner_sqlite_types.table_id = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - table_id -- int. + id_ -- int. + + Returns: + models.TestSqliteType -- Result fetched from the db. Will be `None` if not found. """ - await conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, )) + row = await (await conn.execute(GET_ONE_SQLITE_TYPE, (id_,))).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) -async def delete_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. +async def get_one_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - id_ -- int. + table_id -- int. Returns: - aiosqlite.Cursor -- The result returned when executing the query. + models.TestInnerSqliteType -- Result fetched from the db. Will be `None` if not found. """ - return await conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, )) + row = await (await conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,))).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) -async def delete_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: - """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. +async def get_one_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. id_ -- int. + date_test -- datetime.date. Returns: - int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + datetime.date -- Result fetched from the db. Will be `None` if not found. """ - return (await conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount + row = await (await conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() + if row is None: + return None + return row[0] -async def delete_type_override(conn: aiosqlite.Connection, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. +async def get_one_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. id_ -- int. + datetime_test -- datetime.datetime. + + Returns: + datetime.datetime -- Result fetched from the db. Will be `None` if not found. """ - await conn.execute(DELETE_TYPE_OVERRIDE, (id_, )) + row = await (await conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() + if row is None: + return None + return row[0] -def get_many_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. +async def get_one_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. id_ -- int. - blob_test -- memoryview. + timestamp_test -- datetime.datetime. Returns: - QueryResults[memoryview] -- Helper class that allows both iteration and normal fetching of data from the db. + datetime.datetime -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[memoryview](conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + row = await (await conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() + if row is None: + return None + return row[0] -def get_many_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBool :many`. +async def get_one_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -581,13 +835,16 @@ def get_many_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> Q bool_test -- bool. Returns: - QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. + bool -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + row = await (await conn.execute(GET_ONE_BOOL, (id_, bool_test))).fetchone() + if row is None: + return None + return row[0] -def get_many_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. +async def get_one_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -599,63 +856,105 @@ def get_many_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool boolean_test -- bool. Returns: - QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. + bool -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + row = await (await conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test))).fetchone() + if row is None: + return None + return row[0] -def get_many_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: - """Fetch many from the db using the SQL query with `name: GetManyDate :many`. +async def get_one_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. id_ -- int. - date_test -- datetime.date. + decimal_test -- decimal.Decimal. Returns: - QueryResults[datetime.date] -- Helper class that allows both iteration and normal fetching of data from the db. + decimal.Decimal -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.date](conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + row = await (await conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() + if row is None: + return None + return row[0] -def get_many_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. +async def get_one_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. id_ -- int. - datetime_test -- datetime.datetime. + blob_test -- memoryview. Returns: - QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. + memoryview -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.datetime](conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) + row = await (await conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone() + if row is None: + return None + return row[0] -def get_many_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: - """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. +def get_many_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. id_ -- int. - decimal_test -- decimal.Decimal. Returns: - QueryResults[decimal.Decimal] -- Helper class that allows both iteration and normal fetching of data from the db. + QueryResults[models.TestSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. """ - return QueryResults[decimal.Decimal](conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) def get_many_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: @@ -672,9 +971,41 @@ def get_many_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> Returns: QueryResults[models.TestInnerSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) def get_many_nullable_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: @@ -692,47 +1023,77 @@ def get_many_nullable_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: Returns: QueryResults[models.TestInnerSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) -def get_many_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. +def get_many_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. id_ -- int. + date_test -- datetime.date. Returns: - QueryResults[models.TestSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. + QueryResults[datetime.date] -- Helper class that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestSqliteType](conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + return QueryResults(conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) -def get_many_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. +def get_many_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. id_ -- int. + datetime_test -- datetime.datetime. Returns: - QueryResults[UserString] -- Helper class that allows both iteration and normal fetching of data from the db. + QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> UserString: - return UserString(row[0]) - return QueryResults[UserString](conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + return QueryResults(conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) def get_many_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: @@ -750,51 +1111,11 @@ def get_many_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: Returns: QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. """ - return QueryResults[datetime.datetime](conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - - -def get_many_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: - """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. - - ```sql - SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? - ``` - - Arguments: - conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - id_ -- int. - - Returns: - QueryResults[models.TestTypeOverride] -- Helper class that allows both iteration and normal fetching of data from the db. - """ - def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - return QueryResults[models.TestTypeOverride](conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) - - -async def get_one_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. + return QueryResults(conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? - ``` - Arguments: - conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - id_ -- int. - blob_test -- memoryview. - - Returns: - memoryview -- Result fetched from the db. Will be `None` if not found. - """ - row = await (await conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone() - if row is None: - return None - return row[0] - - -async def get_one_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBool :one`. +def get_many_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -806,16 +1127,13 @@ async def get_one_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) bool_test -- bool. Returns: - bool -- Result fetched from the db. Will be `None` if not found. + QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_BOOL, (id_, bool_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) -async def get_one_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. +def get_many_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -827,58 +1145,13 @@ async def get_one_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: boolean_test -- bool. Returns: - bool -- Result fetched from the db. Will be `None` if not found. - """ - row = await (await conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test))).fetchone() - if row is None: - return None - return row[0] - - -async def get_one_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: - """Fetch one from the db using the SQL query with `name: GetOneDate :one`. - - ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? - ``` - - Arguments: - conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - id_ -- int. - date_test -- datetime.date. - - Returns: - datetime.date -- Result fetched from the db. Will be `None` if not found. - """ - row = await (await conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() - if row is None: - return None - return row[0] - - -async def get_one_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. - - ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? - ``` - - Arguments: - conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - id_ -- int. - datetime_test -- datetime.datetime. - - Returns: - datetime.datetime -- Result fetched from the db. Will be `None` if not found. + QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) -async def get_one_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: - """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. +def get_many_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. ```sql SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? @@ -890,226 +1163,94 @@ async def get_one_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal_test -- decimal.Decimal. Returns: - decimal.Decimal -- Result fetched from the db. Will be `None` if not found. - """ - row = await (await conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() - if row is None: - return None - return row[0] - - -async def get_one_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? - ``` - - Arguments: - conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - table_id -- int. - - Returns: - models.TestInnerSqliteType -- Result fetched from the db. Will be `None` if not found. - """ - row = await (await conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id, ))).fetchone() - if row is None: - return None - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - - -async def get_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> models.TestSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. - - ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? - ``` - - Arguments: - conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - id_ -- int. - - Returns: - models.TestSqliteType -- Result fetched from the db. Will be `None` if not found. - """ - row = await (await conn.execute(GET_ONE_SQLITE_TYPE, (id_, ))).fetchone() - if row is None: - return None - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - - -async def get_one_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. - - ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? - ``` - - Arguments: - conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - id_ -- int. - - Returns: - UserString -- Result fetched from the db. Will be `None` if not found. - """ - row = await (await conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_, ))).fetchone() - if row is None: - return None - return UserString(row[0]) - - -async def get_one_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. - - ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? - ``` - - Arguments: - conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - id_ -- int. - timestamp_test -- datetime.datetime. - - Returns: - datetime.datetime -- Result fetched from the db. Will be `None` if not found. + QueryResults[decimal.Decimal] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) -async def get_one_type_override(conn: aiosqlite.Connection, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. +def get_many_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. id_ -- int. + blob_test -- memoryview. Returns: - models.TestTypeOverride -- Result fetched from the db. Will be `None` if not found. + QueryResults[memoryview] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = await (await conn.execute(GET_ONE_TYPE_OVERRIDE, (id_, ))).fetchone() - if row is None: - return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - + return QueryResults(conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) -async def insert_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int | None: - """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. - ```sql - INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) - ``` +async def delete_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. - Arguments: - conn -- Connection object of type `aiosqlite.Connection` used to execute the query. - id_ -- int. - int_test -- int. - bigint_test -- int. - smallint_test -- int. - tinyint_test -- int. - int2_test -- int. - int8_test -- int. - bigserial_test -- int. - blob_test -- memoryview. - real_test -- float. - double_test -- float. - double_precision_test -- float. - float_test -- float. - numeric_test -- float. - decimal_test -- decimal.Decimal. - boolean_test -- bool. - bool_test -- bool. - date_test -- datetime.date. - datetime_test -- datetime.datetime. - timestamp_test -- datetime.datetime. - character_test -- str. - varchar_test -- str. - varyingcharacter_test -- str. - nchar_test -- str. - nativecharacter_test -- str. - nvarchar_test -- str. - text_test -- str. - clob_test -- str. - json_test -- str. + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` - Returns: - int | None -- The id of the last affected row. Will be `None` if no rows are affected. + Arguments: + conn -- Connection object of type `aiosqlite.Connection` used to execute the query. + id_ -- int. """ - return (await conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test))).lastrowid + await conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) -async def insert_one_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int, int_test: int | None, bigint_test: int | None, smallint_test: int | None, tinyint_test: int | None, int2_test: int | None, int8_test: int | None, bigserial_test: int | None, blob_test: memoryview | None, real_test: float | None, double_test: float | None, double_precision_test: float | None, float_test: float | None, numeric_test: float | None, decimal_test: decimal.Decimal | None, boolean_test: bool | None, bool_test: bool | None, date_test: datetime.date | None, datetime_test: datetime.datetime | None, timestamp_test: datetime.datetime | None, character_test: str | None, varchar_test: str | None, varyingcharacter_test: str | None, nchar_test: str | None, nativecharacter_test: str | None, nvarchar_test: str | None, text_test: str | None, clob_test: str | None, json_test: str | None) -> None: - """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. +async def delete_one_test_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. ```sql - INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? ``` Arguments: conn -- Connection object of type `aiosqlite.Connection` used to execute the query. table_id -- int. - int_test -- int | None. - bigint_test -- int | None. - smallint_test -- int | None. - tinyint_test -- int | None. - int2_test -- int | None. - int8_test -- int | None. - bigserial_test -- int | None. - blob_test -- memoryview | None. - real_test -- float | None. - double_test -- float | None. - double_precision_test -- float | None. - float_test -- float | None. - numeric_test -- float | None. - decimal_test -- decimal.Decimal | None. - boolean_test -- bool | None. - bool_test -- bool | None. - date_test -- datetime.date | None. - datetime_test -- datetime.datetime | None. - timestamp_test -- datetime.datetime | None. - character_test -- str | None. - varchar_test -- str | None. - varyingcharacter_test -- str | None. - nchar_test -- str | None. - nativecharacter_test -- str | None. - nvarchar_test -- str | None. - text_test -- str | None. - clob_test -- str | None. - json_test -- str | None. """ - await conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, (table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) - - -async def insert_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> None: - """Execute SQL query with `name: InsertOneSqliteType :exec`. + await conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) + + +async def insert_result_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. ```sql INSERT INTO test_sqlite_types ( @@ -1157,12 +1298,116 @@ async def insert_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_te text_test -- str. clob_test -- str. json_test -- str. + + Returns: + aiosqlite.Cursor -- The result returned when executing the query. """ - await conn.execute(INSERT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return await conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) -async def insert_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. +async def update_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + conn -- Connection object of type `aiosqlite.Connection` used to execute the query. + id_ -- int. + + Returns: + aiosqlite.Cursor -- The result returned when executing the query. + """ + return await conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +async def delete_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + conn -- Connection object of type `aiosqlite.Connection` used to execute the query. + id_ -- int. + + Returns: + aiosqlite.Cursor -- The result returned when executing the query. + """ + return await conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +async def insert_rows_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. ```sql INSERT INTO test_sqlite_types ( @@ -1212,13 +1457,134 @@ async def insert_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, json_test -- str. Returns: - aiosqlite.Cursor -- The result returned when executing the query. + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - return await conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args)).rowcount -async def insert_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int: - """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. +async def update_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + conn -- Connection object of type `aiosqlite.Connection` used to execute the query. + id_ -- int. + + Returns: + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + +async def delete_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + conn -- Connection object of type `aiosqlite.Connection` used to execute the query. + id_ -- int. + + Returns: + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + +async def create_rows_table(conn: aiosqlite.Connection) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Arguments: + conn -- Connection object of type `aiosqlite.Connection` used to execute the query. + + Returns: + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await conn.execute(CREATE_ROWS_TABLE)).rowcount + + +async def insert_last_id_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. ```sql INSERT INTO test_sqlite_types ( @@ -1268,9 +1634,78 @@ async def insert_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int, i json_test -- str. Returns: - int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + int -- The id of the last affected row. Will be `None` if no rows are affected. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args)).lastrowid + + +async def update_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + conn -- Connection object of type `aiosqlite.Connection` used to execute the query. + id_ -- int. + + Returns: + int -- The id of the last affected row. Will be `None` if no rows are affected. + """ + return (await conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid + + +async def delete_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + conn -- Connection object of type `aiosqlite.Connection` used to execute the query. + id_ -- int. + + Returns: + int -- The id of the last affected row. Will be `None` if no rows are affected. """ - return (await conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test))).rowcount + return (await conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid async def insert_type_override(conn: aiosqlite.Connection, *, id_: int, text_test: UserString | None) -> None: @@ -1287,16 +1722,14 @@ async def insert_type_override(conn: aiosqlite.Connection, *, id_: int, text_tes id_ -- int. text_test -- UserString | None. """ - await conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test))) + await conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) -async def update_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: - """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. +async def get_one_type_override(conn: aiosqlite.Connection, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE id = ? ``` Arguments: @@ -1304,18 +1737,19 @@ async def update_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int id_ -- int. Returns: - int | None -- The id of the last affected row. Will be `None` if no rows are affected. + models.TestTypeOverride -- Result fetched from the db. Will be `None` if not found. """ - return (await conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_, ))).lastrowid + row = await (await conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) -async def update_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: - """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. +def get_many_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? ``` Arguments: @@ -1323,18 +1757,40 @@ async def update_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) id_ -- int. Returns: - aiosqlite.Cursor -- The result returned when executing the query. + QueryResults[models.TestTypeOverride] -- Helper class that allows both iteration and normal fetching of data from the db. """ - return await conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_, )) + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) -async def update_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + +async def get_one_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Arguments: + conn -- Connection object of type `aiosqlite.Connection` used to execute the query. + id_ -- int. + + Returns: + UserString -- Result fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + +def get_many_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? ``` Arguments: @@ -1342,6 +1798,26 @@ async def update_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) - id_ -- int. Returns: - int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + QueryResults[UserString | None] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + +async def delete_type_override(conn: aiosqlite.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Arguments: + conn -- Connection object of type `aiosqlite.Connection` used to execute the query. + id_ -- int. """ - return (await conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_, ))).rowcount + await conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_aiosqlite/msgspec/test_aiosqlite_msgspec_classes.py b/test/driver_aiosqlite/msgspec/test_aiosqlite_msgspec_classes.py index 0f5438e2..62cad934 100644 --- a/test/driver_aiosqlite/msgspec/test_aiosqlite_msgspec_classes.py +++ b/test/driver_aiosqlite/msgspec/test_aiosqlite_msgspec_classes.py @@ -39,12 +39,12 @@ class TestMsgspecClasses: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestSqliteType: return models.TestSqliteType( - id=random.randint(1, 10000000), + id_=random.randint(1, 10000000), int_test=42, bigint_test=9_007_199_254_740_991, smallint_test=32_767, @@ -78,7 +78,7 @@ def model(self) -> models.TestSqliteType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: return models.TestInnerSqliteType( - table_id=model.id, + table_id=model.id_, int_test=None, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -125,7 +125,7 @@ async def test_insert( model: models.TestSqliteType, ) -> None: await queries_obj.insert_one_sqlite_type( - id_=model.id, + id_=model.id_, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -157,9 +157,7 @@ async def test_insert( ) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::inner_insert", depends=["AiosqliteTestMsgspecClasses::insert"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::inner_insert", depends=["AiosqliteTestMsgspecClasses::insert"]) async def test_inner_insert( self, queries_obj: queries.Queries, @@ -198,15 +196,13 @@ async def test_inner_insert( ) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_one", depends=["AiosqliteTestMsgspecClasses::inner_insert"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_one", depends=["AiosqliteTestMsgspecClasses::inner_insert"]) async def test_get_one( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_sqlite_type(id_=model.id) + result = await queries_obj.get_one_sqlite_type(id_=model.id_) assert result is not None @@ -215,9 +211,7 @@ async def test_get_one( assert result == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_one_none", depends=["AiosqliteTestMsgspecClasses::get_one"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_one_none", depends=["AiosqliteTestMsgspecClasses::get_one"]) async def test_get_one_none( self, queries_obj: queries.Queries, @@ -227,9 +221,7 @@ async def test_get_one_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_one_inner", depends=["AiosqliteTestMsgspecClasses::get_one_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_one_inner", depends=["AiosqliteTestMsgspecClasses::get_one_none"]) async def test_get_one_inner( self, queries_obj: queries.Queries, @@ -243,9 +235,7 @@ async def test_get_one_inner( assert result == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_one_inner_none", depends=["AiosqliteTestMsgspecClasses::get_one_inner"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_one_inner_none", depends=["AiosqliteTestMsgspecClasses::get_one_inner"]) async def test_get_one_inner_none( self, queries_obj: queries.Queries, @@ -255,15 +245,13 @@ async def test_get_one_inner_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_date", depends=["AiosqliteTestMsgspecClasses::get_one_inner_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_date", depends=["AiosqliteTestMsgspecClasses::get_one_inner_none"]) async def test_get_date( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_date(id_=model.id, date_test=model.date_test) + result = await queries_obj.get_one_date(id_=model.id_, date_test=model.date_test) assert result is not None @@ -271,9 +259,7 @@ async def test_get_date( assert result == model.date_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_date_none", depends=["AiosqliteTestMsgspecClasses::get_date"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_date_none", depends=["AiosqliteTestMsgspecClasses::get_date"]) async def test_get_date_none( self, queries_obj: queries.Queries, @@ -283,15 +269,13 @@ async def test_get_date_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_datetime", depends=["AiosqliteTestMsgspecClasses::get_date_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_datetime", depends=["AiosqliteTestMsgspecClasses::get_date_none"]) async def test_get_datetime( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_datetime(id_=model.id, datetime_test=model.datetime_test) + result = await queries_obj.get_one_datetime(id_=model.id_, datetime_test=model.datetime_test) assert result is not None @@ -299,9 +283,7 @@ async def test_get_datetime( assert result == model.datetime_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_datetime_none", depends=["AiosqliteTestMsgspecClasses::get_datetime"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_datetime_none", depends=["AiosqliteTestMsgspecClasses::get_datetime"]) async def test_get_datetime_none( self, queries_obj: queries.Queries, @@ -311,15 +293,13 @@ async def test_get_datetime_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_timestamp", depends=["AiosqliteTestMsgspecClasses::get_datetime_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_timestamp", depends=["AiosqliteTestMsgspecClasses::get_datetime_none"]) async def test_get_timestamp( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_timestamp(id_=model.id, timestamp_test=model.timestamp_test) + result = await queries_obj.get_one_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None @@ -327,9 +307,7 @@ async def test_get_timestamp( assert result == model.timestamp_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_timestamp_none", depends=["AiosqliteTestMsgspecClasses::get_timestamp"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_timestamp_none", depends=["AiosqliteTestMsgspecClasses::get_timestamp"]) async def test_get_timestamp_none( self, queries_obj: queries.Queries, @@ -339,15 +317,13 @@ async def test_get_timestamp_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_bool", depends=["AiosqliteTestMsgspecClasses::get_timestamp_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_bool", depends=["AiosqliteTestMsgspecClasses::get_timestamp_none"]) async def test_get_bool( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_bool(id_=model.id, bool_test=model.bool_test) + result = await queries_obj.get_one_bool(id_=model.id_, bool_test=model.bool_test) assert result is not None @@ -355,9 +331,7 @@ async def test_get_bool( assert result == model.bool_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_bool_none", depends=["AiosqliteTestMsgspecClasses::get_bool"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_bool_none", depends=["AiosqliteTestMsgspecClasses::get_bool"]) async def test_get_bool_none( self, queries_obj: queries.Queries, @@ -367,15 +341,13 @@ async def test_get_bool_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_boolean", depends=["AiosqliteTestMsgspecClasses::get_bool_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_boolean", depends=["AiosqliteTestMsgspecClasses::get_bool_none"]) async def test_get_boolean( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_boolean(id_=model.id, boolean_test=model.boolean_test) + result = await queries_obj.get_one_boolean(id_=model.id_, boolean_test=model.boolean_test) assert result is not None @@ -383,9 +355,7 @@ async def test_get_boolean( assert result == model.boolean_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_boolean_none", depends=["AiosqliteTestMsgspecClasses::get_boolean"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_boolean_none", depends=["AiosqliteTestMsgspecClasses::get_boolean"]) async def test_get_boolean_none( self, queries_obj: queries.Queries, @@ -395,15 +365,13 @@ async def test_get_boolean_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_decimal", depends=["AiosqliteTestMsgspecClasses::get_boolean_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_decimal", depends=["AiosqliteTestMsgspecClasses::get_boolean_none"]) async def test_get_decimal( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_decimal(id_=model.id, decimal_test=model.decimal_test) + result = await queries_obj.get_one_decimal(id_=model.id_, decimal_test=model.decimal_test) assert result is not None @@ -411,9 +379,7 @@ async def test_get_decimal( assert result == model.decimal_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_decimal_none", depends=["AiosqliteTestMsgspecClasses::get_decimal"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_decimal_none", depends=["AiosqliteTestMsgspecClasses::get_decimal"]) async def test_get_decimal_none( self, queries_obj: queries.Queries, @@ -423,15 +389,13 @@ async def test_get_decimal_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_blob", depends=["AiosqliteTestMsgspecClasses::get_decimal_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_blob", depends=["AiosqliteTestMsgspecClasses::get_decimal_none"]) async def test_get_blob( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.get_one_blob(id_=model.id, blob_test=model.blob_test) + result = await queries_obj.get_one_blob(id_=model.id_, blob_test=model.blob_test) assert result is not None @@ -439,9 +403,7 @@ async def test_get_blob( assert result == model.blob_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_blob_none", depends=["AiosqliteTestMsgspecClasses::get_blob"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_blob_none", depends=["AiosqliteTestMsgspecClasses::get_blob"]) async def test_get_blob_none( self, queries_obj: queries.Queries, @@ -451,11 +413,9 @@ async def test_get_blob_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_many", depends=["AiosqliteTestMsgspecClasses::get_blob_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_many", depends=["AiosqliteTestMsgspecClasses::get_blob_none"]) async def test_get_many(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_sqlite_type(id_=model.id) + result = await queries_obj.get_many_sqlite_type(id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -464,20 +424,16 @@ async def test_get_many(self, queries_obj: queries.Queries, model: models.TestSq assert result[0] == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_many_iter", depends=["AiosqliteTestMsgspecClasses::get_many"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_many_iter", depends=["AiosqliteTestMsgspecClasses::get_many"]) async def test_get_many_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_sqlite_type(id_=model.id): + async for result in queries_obj.get_many_sqlite_type(id_=model.id_): assert result is not None assert isinstance(result, models.TestSqliteType) assert result == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_many_inner", depends=["AiosqliteTestMsgspecClasses::get_many_iter"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_many_inner", depends=["AiosqliteTestMsgspecClasses::get_many_iter"]) async def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: result = await queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id) @@ -488,12 +444,8 @@ async def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: m assert result[0] == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_many_inner_iter", depends=["AiosqliteTestMsgspecClasses::get_many_inner"] - ) - async def test_get_many_inner_iter( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_many_inner_iter", depends=["AiosqliteTestMsgspecClasses::get_many_inner"]) + async def test_get_many_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: async for result in queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -505,9 +457,7 @@ async def test_get_many_inner_iter( name="AiosqliteTestMsgspecClasses::get_many_nullable_inner", depends=["AiosqliteTestMsgspecClasses::get_many_inner_iter"], ) - async def test_get_many_nullable_inner( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: + async def test_get_many_nullable_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: result = await queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=None) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -520,12 +470,8 @@ async def test_get_many_nullable_inner( name="AiosqliteTestMsgspecClasses::get_many_nullable_inner_iter", depends=["AiosqliteTestMsgspecClasses::get_many_nullable_inner"], ) - async def test_get_many_nullable_inner_iter( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: - async for result in queries_obj.get_many_nullable_inner_sqlite_type( - table_id=inner_model.table_id, int_test=inner_model.int_test - ): + async def test_get_many_nullable_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + async for result in queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -537,7 +483,7 @@ async def test_get_many_nullable_inner_iter( depends=["AiosqliteTestMsgspecClasses::get_many_nullable_inner_iter"], ) async def test_get_many_date(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_date(id_=model.id, date_test=model.date_test) + result = await queries_obj.get_many_date(id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -546,11 +492,9 @@ async def test_get_many_date(self, queries_obj: queries.Queries, model: models.T assert result[0] == model.date_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_many_date_iter", depends=["AiosqliteTestMsgspecClasses::get_many_date"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_many_date_iter", depends=["AiosqliteTestMsgspecClasses::get_many_date"]) async def test_get_many_date_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_date(id_=model.id, date_test=model.date_test): + async for result in queries_obj.get_many_date(id_=model.id_, date_test=model.date_test): assert result is not None assert isinstance(result, datetime.date) @@ -562,7 +506,7 @@ async def test_get_many_date_iter(self, queries_obj: queries.Queries, model: mod depends=["AiosqliteTestMsgspecClasses::get_many_date_iter"], ) async def test_get_many_datetime(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_datetime(id_=model.id, datetime_test=model.datetime_test) + result = await queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -576,7 +520,7 @@ async def test_get_many_datetime(self, queries_obj: queries.Queries, model: mode depends=["AiosqliteTestMsgspecClasses::get_many_datetime"], ) async def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_datetime(id_=model.id, datetime_test=model.datetime_test): + async for result in queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -588,7 +532,7 @@ async def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: depends=["AiosqliteTestMsgspecClasses::get_many_datetime_iter"], ) async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_timestamp(id_=model.id, timestamp_test=model.timestamp_test) + result = await queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -602,7 +546,7 @@ async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: mod depends=["AiosqliteTestMsgspecClasses::get_many_timestamp"], ) async def test_get_many_timestamp_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_timestamp(id_=model.id, timestamp_test=model.timestamp_test): + async for result in queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -614,7 +558,7 @@ async def test_get_many_timestamp_iter(self, queries_obj: queries.Queries, model depends=["AiosqliteTestMsgspecClasses::get_many_timestamp_iter"], ) async def test_get_many_bool(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_bool(id_=model.id, bool_test=model.bool_test) + result = await queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -623,11 +567,9 @@ async def test_get_many_bool(self, queries_obj: queries.Queries, model: models.T assert result[0] == model.bool_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_many_bool_iter", depends=["AiosqliteTestMsgspecClasses::get_many_bool"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_many_bool_iter", depends=["AiosqliteTestMsgspecClasses::get_many_bool"]) async def test_get_many_bool_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_bool(id_=model.id, bool_test=model.bool_test): + async for result in queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test): assert result is not None assert isinstance(result, bool) @@ -639,7 +581,7 @@ async def test_get_many_bool_iter(self, queries_obj: queries.Queries, model: mod depends=["AiosqliteTestMsgspecClasses::get_many_bool_iter"], ) async def test_get_many_boolean(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_boolean(id_=model.id, boolean_test=model.boolean_test) + result = await queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -653,7 +595,7 @@ async def test_get_many_boolean(self, queries_obj: queries.Queries, model: model depends=["AiosqliteTestMsgspecClasses::get_many_boolean"], ) async def test_get_many_boolean_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_boolean(id_=model.id, boolean_test=model.boolean_test): + async for result in queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test): assert result is not None assert isinstance(result, bool) @@ -665,7 +607,7 @@ async def test_get_many_boolean_iter(self, queries_obj: queries.Queries, model: depends=["AiosqliteTestMsgspecClasses::get_many_boolean_iter"], ) async def test_get_many_decimal(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_decimal(id_=model.id, decimal_test=model.decimal_test) + result = await queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -679,7 +621,7 @@ async def test_get_many_decimal(self, queries_obj: queries.Queries, model: model depends=["AiosqliteTestMsgspecClasses::get_many_decimal"], ) async def test_get_many_decimal_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_decimal(id_=model.id, decimal_test=model.decimal_test): + async for result in queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test): assert result is not None assert isinstance(result, decimal.Decimal) @@ -691,7 +633,7 @@ async def test_get_many_decimal_iter(self, queries_obj: queries.Queries, model: depends=["AiosqliteTestMsgspecClasses::get_many_decimal_iter"], ) async def test_get_many_blob(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = await queries_obj.get_many_blob(id_=model.id, blob_test=model.blob_test) + result = await queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -700,27 +642,23 @@ async def test_get_many_blob(self, queries_obj: queries.Queries, model: models.T assert result[0] == model.blob_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::get_many_blob_iter", depends=["AiosqliteTestMsgspecClasses::get_many_blob"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::get_many_blob_iter", depends=["AiosqliteTestMsgspecClasses::get_many_blob"]) async def test_get_many_blob_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - async for result in queries_obj.get_many_blob(id_=model.id, blob_test=model.blob_test): + async for result in queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test): assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::insert_result", depends=["AiosqliteTestMsgspecClasses::get_many_blob_iter"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::insert_result", depends=["AiosqliteTestMsgspecClasses::get_many_blob_iter"]) async def test_insert_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = await queries_obj.insert_result_one_sqlite_type( - id_=model.id + 1, + id_=model.id_ + 1, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -753,40 +691,34 @@ async def test_insert_result( assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::update_result", depends=["AiosqliteTestMsgspecClasses::insert_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::update_result", depends=["AiosqliteTestMsgspecClasses::insert_result"]) async def test_update_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.update_result_one_sqlite_type(id_=model.id + 1) + result = await queries_obj.update_result_one_sqlite_type(id_=model.id_ + 1) assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::delete_result", depends=["AiosqliteTestMsgspecClasses::update_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::delete_result", depends=["AiosqliteTestMsgspecClasses::update_result"]) async def test_delete_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.delete_result_one_sqlite_type(id_=model.id + 1) + result = await queries_obj.delete_result_one_sqlite_type(id_=model.id_ + 1) assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::insert_rows", depends=["AiosqliteTestMsgspecClasses::delete_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::insert_rows", depends=["AiosqliteTestMsgspecClasses::delete_result"]) async def test_insert_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = await queries_obj.insert_rows_one_sqlite_type( - id_=model.id + 2, + id_=model.id_ + 2, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -820,35 +752,29 @@ async def test_insert_rows( assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::update_rows", depends=["AiosqliteTestMsgspecClasses::insert_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::update_rows", depends=["AiosqliteTestMsgspecClasses::insert_rows"]) async def test_update_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.update_rows_one_sqlite_type(id_=model.id + 2) + result = await queries_obj.update_rows_one_sqlite_type(id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::delete_rows", depends=["AiosqliteTestMsgspecClasses::update_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::delete_rows", depends=["AiosqliteTestMsgspecClasses::update_rows"]) async def test_delete_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.delete_rows_one_sqlite_type(id_=model.id + 2) + result = await queries_obj.delete_rows_one_sqlite_type(id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::create_table_rows", depends=["AiosqliteTestMsgspecClasses::delete_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::create_table_rows", depends=["AiosqliteTestMsgspecClasses::delete_rows"]) async def test_create_table_rows( self, queries_obj: queries.Queries, @@ -861,16 +787,14 @@ async def test_create_table_rows( assert result == -1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::insert_last_id", depends=["AiosqliteTestMsgspecClasses::create_table_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::insert_last_id", depends=["AiosqliteTestMsgspecClasses::create_table_rows"]) async def test_insert_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = await queries_obj.insert_last_id_one_sqlite_type( - id_=model.id + 3, + id_=model.id_ + 3, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -901,69 +825,57 @@ async def test_insert_last_id( json_test=model.json_test, ) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::update_last_id", depends=["AiosqliteTestMsgspecClasses::insert_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::update_last_id", depends=["AiosqliteTestMsgspecClasses::insert_last_id"]) async def test_update_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.update_last_id_one_sqlite_type(id_=model.id + 3) + result = await queries_obj.update_last_id_one_sqlite_type(id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::delete_last_id", depends=["AiosqliteTestMsgspecClasses::update_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::delete_last_id", depends=["AiosqliteTestMsgspecClasses::update_last_id"]) async def test_delete_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = await queries_obj.delete_last_id_one_sqlite_type(id_=model.id + 3) + result = await queries_obj.delete_last_id_one_sqlite_type(id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecClasses::delete_sqlite_type", depends=["AiosqliteTestMsgspecClasses::delete_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecClasses::delete_sqlite_type", depends=["AiosqliteTestMsgspecClasses::delete_last_id"]) async def test_delete_sqlite_type(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - await queries_obj.delete_one_sqlite_type(id_=model.id) + await queries_obj.delete_one_sqlite_type(id_=model.id_) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestMsgspecClasses::delete_inner_sqlite_type", depends=["AiosqliteTestMsgspecClasses::delete_sqlite_type"], ) - async def test_delete_inner_sqlite_type( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: + async def test_delete_inner_sqlite_type(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: await queries_obj.delete_one_test_inner_sqlite_type(table_id=inner_model.table_id) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestMsgspecClasses::insert_type_override", ) - async def test_insert_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - await queries_obj.insert_type_override(id_=override_model.id, text_test=override_model.text_test) + async def test_insert_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.insert_type_override(id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestMsgspecClasses::get_one_type_override", depends=["AiosqliteTestMsgspecClasses::insert_type_override"], ) - async def test_get_one_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_type_override(id_=override_model.id) + async def test_get_one_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_) assert result is not None assert result == override_model @@ -972,10 +884,8 @@ async def test_get_one_type_override( name="AiosqliteTestMsgspecClasses::get_one_type_override_none", depends=["AiosqliteTestMsgspecClasses::get_one_type_override"], ) - async def test_get_one_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_type_override(id_=override_model.id - 1) + async def test_get_one_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -983,10 +893,8 @@ async def test_get_one_type_override_none( name="AiosqliteTestMsgspecClasses::get_many_type_override", depends=["AiosqliteTestMsgspecClasses::get_one_type_override_none"], ) - async def test_get_many_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_many_type_override(id_=override_model.id) + async def test_get_many_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_type_override(id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model @@ -995,10 +903,8 @@ async def test_get_many_type_override( name="AiosqliteTestMsgspecClasses::get_one_text_type_override", depends=["AiosqliteTestMsgspecClasses::get_many_type_override"], ) - async def test_get_one_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_text_type_override(id_=override_model.id) + async def test_get_one_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -1007,10 +913,8 @@ async def test_get_one_text_type_override( name="AiosqliteTestMsgspecClasses::get_one_text_type_override_none", depends=["AiosqliteTestMsgspecClasses::get_one_text_type_override"], ) - async def test_get_one_text_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_text_type_override(id_=override_model.id - 1) + async def test_get_one_text_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -1018,10 +922,8 @@ async def test_get_one_text_type_override_none( name="AiosqliteTestMsgspecClasses::get_many_text_type_override", depends=["AiosqliteTestMsgspecClasses::get_one_text_type_override_none"], ) - async def test_get_many_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_many_text_type_override(id_=override_model.id) + async def test_get_many_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_text_type_override(id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model.text_test @@ -1030,7 +932,5 @@ async def test_get_many_text_type_override( name="AiosqliteTestMsgspecClasses::delete_type_override", depends=["AiosqliteTestMsgspecClasses::get_many_text_type_override"], ) - async def test_delete_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - await queries_obj.delete_type_override(id_=override_model.id) + async def test_delete_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.delete_type_override(id_=override_model.id_) diff --git a/test/driver_aiosqlite/msgspec/test_aiosqlite_msgspec_functions.py b/test/driver_aiosqlite/msgspec/test_aiosqlite_msgspec_functions.py index ac1d8c29..e7b35fb2 100644 --- a/test/driver_aiosqlite/msgspec/test_aiosqlite_msgspec_functions.py +++ b/test/driver_aiosqlite/msgspec/test_aiosqlite_msgspec_functions.py @@ -38,12 +38,12 @@ class TestMsgspecFunctions: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestSqliteType: return models.TestSqliteType( - id=random.randint(1, 10000000), + id_=random.randint(1, 10000000), int_test=42, bigint_test=9_007_199_254_740_991, smallint_test=32_767, @@ -77,7 +77,7 @@ def model(self) -> models.TestSqliteType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: return models.TestInnerSqliteType( - table_id=model.id, + table_id=model.id_, int_test=None, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -117,7 +117,7 @@ async def test_insert( ) -> None: await queries.insert_one_sqlite_type( conn=aiosqlite_conn, - id_=model.id, + id_=model.id_, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -149,9 +149,7 @@ async def test_insert( ) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::inner_insert", depends=["AiosqliteTestMsgspecFunctions::insert"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::inner_insert", depends=["AiosqliteTestMsgspecFunctions::insert"]) async def test_inner_insert( self, aiosqlite_conn: aiosqlite.Connection, @@ -191,15 +189,13 @@ async def test_inner_insert( ) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_one", depends=["AiosqliteTestMsgspecFunctions::inner_insert"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_one", depends=["AiosqliteTestMsgspecFunctions::inner_insert"]) async def test_get_one( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_sqlite_type(conn=aiosqlite_conn, id_=model.id) + result = await queries.get_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_) assert result is not None @@ -208,9 +204,7 @@ async def test_get_one( assert result == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_one_none", depends=["AiosqliteTestMsgspecFunctions::get_one"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_one_none", depends=["AiosqliteTestMsgspecFunctions::get_one"]) async def test_get_one_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -220,9 +214,7 @@ async def test_get_one_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_one_inner", depends=["AiosqliteTestMsgspecFunctions::get_one_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_one_inner", depends=["AiosqliteTestMsgspecFunctions::get_one_none"]) async def test_get_one_inner( self, aiosqlite_conn: aiosqlite.Connection, @@ -249,15 +241,13 @@ async def test_get_one_inner_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_date", depends=["AiosqliteTestMsgspecFunctions::get_one_inner_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_date", depends=["AiosqliteTestMsgspecFunctions::get_one_inner_none"]) async def test_get_date( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_date(conn=aiosqlite_conn, id_=model.id, date_test=model.date_test) + result = await queries.get_one_date(conn=aiosqlite_conn, id_=model.id_, date_test=model.date_test) assert result is not None @@ -265,9 +255,7 @@ async def test_get_date( assert result == model.date_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_date_none", depends=["AiosqliteTestMsgspecFunctions::get_date"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_date_none", depends=["AiosqliteTestMsgspecFunctions::get_date"]) async def test_get_date_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -277,15 +265,13 @@ async def test_get_date_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_datetime", depends=["AiosqliteTestMsgspecFunctions::get_date_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_datetime", depends=["AiosqliteTestMsgspecFunctions::get_date_none"]) async def test_get_datetime( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_datetime(conn=aiosqlite_conn, id_=model.id, datetime_test=model.datetime_test) + result = await queries.get_one_datetime(conn=aiosqlite_conn, id_=model.id_, datetime_test=model.datetime_test) assert result is not None @@ -293,9 +279,7 @@ async def test_get_datetime( assert result == model.datetime_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_datetime_none", depends=["AiosqliteTestMsgspecFunctions::get_datetime"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_datetime_none", depends=["AiosqliteTestMsgspecFunctions::get_datetime"]) async def test_get_datetime_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -314,7 +298,7 @@ async def test_get_timestamp( aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_timestamp(conn=aiosqlite_conn, id_=model.id, timestamp_test=model.timestamp_test) + result = await queries.get_one_timestamp(conn=aiosqlite_conn, id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None @@ -335,15 +319,13 @@ async def test_get_timestamp_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_bool", depends=["AiosqliteTestMsgspecFunctions::get_timestamp_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_bool", depends=["AiosqliteTestMsgspecFunctions::get_timestamp_none"]) async def test_get_bool( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_bool(conn=aiosqlite_conn, id_=model.id, bool_test=model.bool_test) + result = await queries.get_one_bool(conn=aiosqlite_conn, id_=model.id_, bool_test=model.bool_test) assert result is not None @@ -351,9 +333,7 @@ async def test_get_bool( assert result == model.bool_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_bool_none", depends=["AiosqliteTestMsgspecFunctions::get_bool"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_bool_none", depends=["AiosqliteTestMsgspecFunctions::get_bool"]) async def test_get_bool_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -363,15 +343,13 @@ async def test_get_bool_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_boolean", depends=["AiosqliteTestMsgspecFunctions::get_bool_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_boolean", depends=["AiosqliteTestMsgspecFunctions::get_bool_none"]) async def test_get_boolean( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_boolean(conn=aiosqlite_conn, id_=model.id, boolean_test=model.boolean_test) + result = await queries.get_one_boolean(conn=aiosqlite_conn, id_=model.id_, boolean_test=model.boolean_test) assert result is not None @@ -379,9 +357,7 @@ async def test_get_boolean( assert result == model.boolean_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_boolean_none", depends=["AiosqliteTestMsgspecFunctions::get_boolean"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_boolean_none", depends=["AiosqliteTestMsgspecFunctions::get_boolean"]) async def test_get_boolean_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -391,15 +367,13 @@ async def test_get_boolean_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_decimal", depends=["AiosqliteTestMsgspecFunctions::get_boolean_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_decimal", depends=["AiosqliteTestMsgspecFunctions::get_boolean_none"]) async def test_get_decimal( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_decimal(conn=aiosqlite_conn, id_=model.id, decimal_test=model.decimal_test) + result = await queries.get_one_decimal(conn=aiosqlite_conn, id_=model.id_, decimal_test=model.decimal_test) assert result is not None @@ -407,9 +381,7 @@ async def test_get_decimal( assert result == model.decimal_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_decimal_none", depends=["AiosqliteTestMsgspecFunctions::get_decimal"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_decimal_none", depends=["AiosqliteTestMsgspecFunctions::get_decimal"]) async def test_get_decimal_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -419,15 +391,13 @@ async def test_get_decimal_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_blob", depends=["AiosqliteTestMsgspecFunctions::get_decimal_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_blob", depends=["AiosqliteTestMsgspecFunctions::get_decimal_none"]) async def test_get_blob( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.get_one_blob(conn=aiosqlite_conn, id_=model.id, blob_test=model.blob_test) + result = await queries.get_one_blob(conn=aiosqlite_conn, id_=model.id_, blob_test=model.blob_test) assert result is not None @@ -435,9 +405,7 @@ async def test_get_blob( assert result == model.blob_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_blob_none", depends=["AiosqliteTestMsgspecFunctions::get_blob"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_blob_none", depends=["AiosqliteTestMsgspecFunctions::get_blob"]) async def test_get_blob_none( self, aiosqlite_conn: aiosqlite.Connection, @@ -447,11 +415,9 @@ async def test_get_blob_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_many", depends=["AiosqliteTestMsgspecFunctions::get_blob_none"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_many", depends=["AiosqliteTestMsgspecFunctions::get_blob_none"]) async def test_get_many(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id) + result = await queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -460,23 +426,17 @@ async def test_get_many(self, aiosqlite_conn: aiosqlite.Connection, model: model assert result[0] == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_many_iter", depends=["AiosqliteTestMsgspecFunctions::get_many"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_many_iter", depends=["AiosqliteTestMsgspecFunctions::get_many"]) async def test_get_many_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - async for result in queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id): + async for result in queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id_): assert result is not None assert isinstance(result, models.TestSqliteType) assert result == model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::get_many_inner", depends=["AiosqliteTestMsgspecFunctions::get_many_iter"] - ) - async def test_get_many_inner( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::get_many_inner", depends=["AiosqliteTestMsgspecFunctions::get_many_iter"]) + async def test_get_many_inner(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: result = await queries.get_many_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id) assert result is not None @@ -490,9 +450,7 @@ async def test_get_many_inner( name="AiosqliteTestMsgspecFunctions::get_many_inner_iter", depends=["AiosqliteTestMsgspecFunctions::get_many_inner"], ) - async def test_get_many_inner_iter( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + async def test_get_many_inner_iter(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: async for result in queries.get_many_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -504,12 +462,8 @@ async def test_get_many_inner_iter( name="AiosqliteTestMsgspecFunctions::get_many_nullable_inner", depends=["AiosqliteTestMsgspecFunctions::get_many_inner_iter"], ) - async def test_get_many_nullable_inner( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: - result = await queries.get_many_nullable_inner_sqlite_type( - conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test - ) + async def test_get_many_nullable_inner(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: + result = await queries.get_many_nullable_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -522,12 +476,8 @@ async def test_get_many_nullable_inner( name="AiosqliteTestMsgspecFunctions::get_many_nullable_inner_iter", depends=["AiosqliteTestMsgspecFunctions::get_many_nullable_inner"], ) - async def test_get_many_nullable_inner_iter( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: - async for result in queries.get_many_nullable_inner_sqlite_type( - conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test - ): + async def test_get_many_nullable_inner_iter(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: + async for result in queries.get_many_nullable_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -539,7 +489,7 @@ async def test_get_many_nullable_inner_iter( depends=["AiosqliteTestMsgspecFunctions::get_many_nullable_inner_iter"], ) async def test_get_many_date(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_date(conn=aiosqlite_conn, id_=model.id, date_test=model.date_test) + result = await queries.get_many_date(conn=aiosqlite_conn, id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -553,7 +503,7 @@ async def test_get_many_date(self, aiosqlite_conn: aiosqlite.Connection, model: depends=["AiosqliteTestMsgspecFunctions::get_many_date"], ) async def test_get_many_date_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - async for result in queries.get_many_date(conn=aiosqlite_conn, id_=model.id, date_test=model.date_test): + async for result in queries.get_many_date(conn=aiosqlite_conn, id_=model.id_, date_test=model.date_test): assert result is not None assert isinstance(result, datetime.date) @@ -565,7 +515,7 @@ async def test_get_many_date_iter(self, aiosqlite_conn: aiosqlite.Connection, mo depends=["AiosqliteTestMsgspecFunctions::get_many_date_iter"], ) async def test_get_many_datetime(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_datetime(conn=aiosqlite_conn, id_=model.id, datetime_test=model.datetime_test) + result = await queries.get_many_datetime(conn=aiosqlite_conn, id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -578,12 +528,8 @@ async def test_get_many_datetime(self, aiosqlite_conn: aiosqlite.Connection, mod name="AiosqliteTestMsgspecFunctions::get_many_datetime_iter", depends=["AiosqliteTestMsgspecFunctions::get_many_datetime"], ) - async def test_get_many_datetime_iter( - self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType - ) -> None: - async for result in queries.get_many_datetime( - conn=aiosqlite_conn, id_=model.id, datetime_test=model.datetime_test - ): + async def test_get_many_datetime_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_datetime(conn=aiosqlite_conn, id_=model.id_, datetime_test=model.datetime_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -595,9 +541,7 @@ async def test_get_many_datetime_iter( depends=["AiosqliteTestMsgspecFunctions::get_many_datetime_iter"], ) async def test_get_many_timestamp(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_timestamp( - conn=aiosqlite_conn, id_=model.id, timestamp_test=model.timestamp_test - ) + result = await queries.get_many_timestamp(conn=aiosqlite_conn, id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -610,12 +554,8 @@ async def test_get_many_timestamp(self, aiosqlite_conn: aiosqlite.Connection, mo name="AiosqliteTestMsgspecFunctions::get_many_timestamp_iter", depends=["AiosqliteTestMsgspecFunctions::get_many_timestamp"], ) - async def test_get_many_timestamp_iter( - self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType - ) -> None: - async for result in queries.get_many_timestamp( - conn=aiosqlite_conn, id_=model.id, timestamp_test=model.timestamp_test - ): + async def test_get_many_timestamp_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_timestamp(conn=aiosqlite_conn, id_=model.id_, timestamp_test=model.timestamp_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -627,7 +567,7 @@ async def test_get_many_timestamp_iter( depends=["AiosqliteTestMsgspecFunctions::get_many_timestamp_iter"], ) async def test_get_many_bool(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_bool(conn=aiosqlite_conn, id_=model.id, bool_test=model.bool_test) + result = await queries.get_many_bool(conn=aiosqlite_conn, id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -641,7 +581,7 @@ async def test_get_many_bool(self, aiosqlite_conn: aiosqlite.Connection, model: depends=["AiosqliteTestMsgspecFunctions::get_many_bool"], ) async def test_get_many_bool_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - async for result in queries.get_many_bool(conn=aiosqlite_conn, id_=model.id, bool_test=model.bool_test): + async for result in queries.get_many_bool(conn=aiosqlite_conn, id_=model.id_, bool_test=model.bool_test): assert result is not None assert isinstance(result, bool) @@ -653,7 +593,7 @@ async def test_get_many_bool_iter(self, aiosqlite_conn: aiosqlite.Connection, mo depends=["AiosqliteTestMsgspecFunctions::get_many_bool_iter"], ) async def test_get_many_boolean(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_boolean(conn=aiosqlite_conn, id_=model.id, boolean_test=model.boolean_test) + result = await queries.get_many_boolean(conn=aiosqlite_conn, id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -666,12 +606,8 @@ async def test_get_many_boolean(self, aiosqlite_conn: aiosqlite.Connection, mode name="AiosqliteTestMsgspecFunctions::get_many_boolean_iter", depends=["AiosqliteTestMsgspecFunctions::get_many_boolean"], ) - async def test_get_many_boolean_iter( - self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType - ) -> None: - async for result in queries.get_many_boolean( - conn=aiosqlite_conn, id_=model.id, boolean_test=model.boolean_test - ): + async def test_get_many_boolean_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_boolean(conn=aiosqlite_conn, id_=model.id_, boolean_test=model.boolean_test): assert result is not None assert isinstance(result, bool) @@ -683,7 +619,7 @@ async def test_get_many_boolean_iter( depends=["AiosqliteTestMsgspecFunctions::get_many_boolean_iter"], ) async def test_get_many_decimal(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_decimal(conn=aiosqlite_conn, id_=model.id, decimal_test=model.decimal_test) + result = await queries.get_many_decimal(conn=aiosqlite_conn, id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -696,12 +632,8 @@ async def test_get_many_decimal(self, aiosqlite_conn: aiosqlite.Connection, mode name="AiosqliteTestMsgspecFunctions::get_many_decimal_iter", depends=["AiosqliteTestMsgspecFunctions::get_many_decimal"], ) - async def test_get_many_decimal_iter( - self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType - ) -> None: - async for result in queries.get_many_decimal( - conn=aiosqlite_conn, id_=model.id, decimal_test=model.decimal_test - ): + async def test_get_many_decimal_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_decimal(conn=aiosqlite_conn, id_=model.id_, decimal_test=model.decimal_test): assert result is not None assert isinstance(result, decimal.Decimal) @@ -713,7 +645,7 @@ async def test_get_many_decimal_iter( depends=["AiosqliteTestMsgspecFunctions::get_many_decimal_iter"], ) async def test_get_many_blob(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - result = await queries.get_many_blob(conn=aiosqlite_conn, id_=model.id, blob_test=model.blob_test) + result = await queries.get_many_blob(conn=aiosqlite_conn, id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -727,7 +659,7 @@ async def test_get_many_blob(self, aiosqlite_conn: aiosqlite.Connection, model: depends=["AiosqliteTestMsgspecFunctions::get_many_blob"], ) async def test_get_many_blob_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - async for result in queries.get_many_blob(conn=aiosqlite_conn, id_=model.id, blob_test=model.blob_test): + async for result in queries.get_many_blob(conn=aiosqlite_conn, id_=model.id_, blob_test=model.blob_test): assert result is not None assert isinstance(result, memoryview) @@ -745,7 +677,7 @@ async def test_insert_result( ) -> None: result = await queries.insert_result_one_sqlite_type( conn=aiosqlite_conn, - id_=model.id + 1, + id_=model.id_ + 1, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -778,33 +710,27 @@ async def test_insert_result( assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::update_result", depends=["AiosqliteTestMsgspecFunctions::insert_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::update_result", depends=["AiosqliteTestMsgspecFunctions::insert_result"]) async def test_update_result( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.update_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 1) + result = await queries.update_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 1) assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::delete_result", depends=["AiosqliteTestMsgspecFunctions::update_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::delete_result", depends=["AiosqliteTestMsgspecFunctions::update_result"]) async def test_delete_result( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.delete_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 1) + result = await queries.delete_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 1) assert isinstance(result, aiosqlite.Cursor) @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::insert_rows", depends=["AiosqliteTestMsgspecFunctions::delete_result"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::insert_rows", depends=["AiosqliteTestMsgspecFunctions::delete_result"]) async def test_insert_rows( self, aiosqlite_conn: aiosqlite.Connection, @@ -812,7 +738,7 @@ async def test_insert_rows( ) -> None: result = await queries.insert_rows_one_sqlite_type( conn=aiosqlite_conn, - id_=model.id + 2, + id_=model.id_ + 2, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -846,35 +772,29 @@ async def test_insert_rows( assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::update_rows", depends=["AiosqliteTestMsgspecFunctions::insert_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::update_rows", depends=["AiosqliteTestMsgspecFunctions::insert_rows"]) async def test_update_rows( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.update_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 2) + result = await queries.update_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::delete_rows", depends=["AiosqliteTestMsgspecFunctions::update_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::delete_rows", depends=["AiosqliteTestMsgspecFunctions::update_rows"]) async def test_delete_rows( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.delete_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 2) + result = await queries.delete_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::create_table_rows", depends=["AiosqliteTestMsgspecFunctions::delete_rows"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::create_table_rows", depends=["AiosqliteTestMsgspecFunctions::delete_rows"]) async def test_create_table_rows( self, aiosqlite_conn: aiosqlite.Connection, @@ -897,7 +817,7 @@ async def test_insert_last_id( ) -> None: result = await queries.insert_last_id_one_sqlite_type( conn=aiosqlite_conn, - id_=model.id + 3, + id_=model.id_ + 3, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -928,33 +848,29 @@ async def test_insert_last_id( json_test=model.json_test, ) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::update_last_id", depends=["AiosqliteTestMsgspecFunctions::insert_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::update_last_id", depends=["AiosqliteTestMsgspecFunctions::insert_last_id"]) async def test_update_last_id( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.update_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 3) + result = await queries.update_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - name="AiosqliteTestMsgspecFunctions::delete_last_id", depends=["AiosqliteTestMsgspecFunctions::update_last_id"] - ) + @pytest.mark.dependency(name="AiosqliteTestMsgspecFunctions::delete_last_id", depends=["AiosqliteTestMsgspecFunctions::update_last_id"]) async def test_delete_last_id( self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType, ) -> None: - result = await queries.delete_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id + 3) + result = await queries.delete_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( @@ -962,38 +878,30 @@ async def test_delete_last_id( depends=["AiosqliteTestMsgspecFunctions::delete_last_id"], ) async def test_delete_sqlite_type(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: - await queries.delete_one_sqlite_type(conn=aiosqlite_conn, id_=model.id) + await queries.delete_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestMsgspecFunctions::delete_inner_sqlite_type", depends=["AiosqliteTestMsgspecFunctions::delete_sqlite_type"], ) - async def test_delete_inner_sqlite_type( - self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + async def test_delete_inner_sqlite_type(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: await queries.delete_one_test_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestMsgspecFunctions::insert_type_override", ) - async def test_insert_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - await queries.insert_type_override( - conn=aiosqlite_conn, id_=override_model.id, text_test=override_model.text_test - ) + async def test_insert_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + await queries.insert_type_override(conn=aiosqlite_conn, id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="AiosqliteTestMsgspecFunctions::get_one_type_override", depends=["AiosqliteTestMsgspecFunctions::insert_type_override"], ) - async def test_get_one_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_get_one_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id_) assert result is not None assert result == override_model @@ -1002,10 +910,8 @@ async def test_get_one_type_override( name="AiosqliteTestMsgspecFunctions::get_one_type_override_none", depends=["AiosqliteTestMsgspecFunctions::get_one_type_override"], ) - async def test_get_one_type_override_none( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id - 1) + async def test_get_one_type_override_none(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -1013,10 +919,8 @@ async def test_get_one_type_override_none( name="AiosqliteTestMsgspecFunctions::get_many_type_override", depends=["AiosqliteTestMsgspecFunctions::get_one_type_override_none"], ) - async def test_get_many_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_many_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_get_many_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_type_override(conn=aiosqlite_conn, id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model @@ -1025,10 +929,8 @@ async def test_get_many_type_override( name="AiosqliteTestMsgspecFunctions::get_one_text_type_override", depends=["AiosqliteTestMsgspecFunctions::get_many_type_override"], ) - async def test_get_one_text_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_get_one_text_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -1037,10 +939,8 @@ async def test_get_one_text_type_override( name="AiosqliteTestMsgspecFunctions::get_one_text_type_override_none", depends=["AiosqliteTestMsgspecFunctions::get_one_text_type_override"], ) - async def test_get_one_text_type_override_none( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id - 1) + async def test_get_one_text_type_override_none(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -1048,10 +948,8 @@ async def test_get_one_text_type_override_none( name="AiosqliteTestMsgspecFunctions::get_many_text_type_override", depends=["AiosqliteTestMsgspecFunctions::get_one_text_type_override_none"], ) - async def test_get_many_text_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_many_text_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_get_many_text_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_text_type_override(conn=aiosqlite_conn, id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model.text_test @@ -1060,7 +958,5 @@ async def test_get_many_text_type_override( name="AiosqliteTestMsgspecFunctions::delete_type_override", depends=["AiosqliteTestMsgspecFunctions::get_many_text_type_override"], ) - async def test_delete_type_override( - self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride - ) -> None: - await queries.delete_type_override(conn=aiosqlite_conn, id_=override_model.id) + async def test_delete_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + await queries.delete_type_override(conn=aiosqlite_conn, id_=override_model.id_) diff --git a/test/driver_aiosqlite/pydantic/__init__.py b/test/driver_aiosqlite/pydantic/__init__.py new file mode 100644 index 00000000..f4d072e3 --- /dev/null +++ b/test/driver_aiosqlite/pydantic/__init__.py @@ -0,0 +1,20 @@ +# Copyright (c) 2025 Rayakame + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +"""Package to allow importing for aiosqlite tests.""" diff --git a/test/driver_aiosqlite/pydantic/classes/__init__.py b/test/driver_aiosqlite/pydantic/classes/__init__.py new file mode 100644 index 00000000..5c9110dc --- /dev/null +++ b/test/driver_aiosqlite/pydantic/classes/__init__.py @@ -0,0 +1,5 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_aiosqlite/pydantic/classes/models.py b/test/driver_aiosqlite/pydantic/classes/models.py new file mode 100644 index 00000000..846ac2c1 --- /dev/null +++ b/test/driver_aiosqlite/pydantic/classes/models.py @@ -0,0 +1,172 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing models.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "TestInnerSqliteType", + "TestSqliteType", + "TestTypeOverride", +) + +from collections import UserString +import datetime +import decimal +import pydantic +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +class TestInnerSqliteType(pydantic.BaseModel): + """Model representing TestInnerSqliteType. + + Attributes: + table_id: int + int_test: int | None + bigint_test: int | None + smallint_test: int | None + tinyint_test: int | None + int2_test: int | None + int8_test: int | None + bigserial_test: int | None + blob_test: memoryview | None + real_test: float | None + double_test: float | None + double_precision_test: float | None + float_test: float | None + numeric_test: float | None + decimal_test: decimal.Decimal | None + boolean_test: bool | None + bool_test: bool | None + date_test: datetime.date | None + datetime_test: datetime.datetime | None + timestamp_test: datetime.datetime | None + character_test: str | None + varchar_test: str | None + varyingcharacter_test: str | None + nchar_test: str | None + nativecharacter_test: str | None + nvarchar_test: str | None + text_test: str | None + clob_test: str | None + json_test: str | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + table_id: int + int_test: int | None + bigint_test: int | None + smallint_test: int | None + tinyint_test: int | None + int2_test: int | None + int8_test: int | None + bigserial_test: int | None + blob_test: memoryview | None + real_test: float | None + double_test: float | None + double_precision_test: float | None + float_test: float | None + numeric_test: float | None + decimal_test: decimal.Decimal | None + boolean_test: bool | None + bool_test: bool | None + date_test: datetime.date | None + datetime_test: datetime.datetime | None + timestamp_test: datetime.datetime | None + character_test: str | None + varchar_test: str | None + varyingcharacter_test: str | None + nchar_test: str | None + nativecharacter_test: str | None + nvarchar_test: str | None + text_test: str | None + clob_test: str | None + json_test: str | None + + +class TestSqliteType(pydantic.BaseModel): + """Model representing TestSqliteType. + + Attributes: + id_: int + int_test: int + bigint_test: int + smallint_test: int + tinyint_test: int + int2_test: int + int8_test: int + bigserial_test: int + blob_test: memoryview + real_test: float + double_test: float + double_precision_test: float + float_test: float + numeric_test: float + decimal_test: decimal.Decimal + boolean_test: bool + bool_test: bool + date_test: datetime.date + datetime_test: datetime.datetime + timestamp_test: datetime.datetime + character_test: str + varchar_test: str + varyingcharacter_test: str + nchar_test: str + nativecharacter_test: str + nvarchar_test: str + text_test: str + clob_test: str + json_test: str + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + int_test: int + bigint_test: int + smallint_test: int + tinyint_test: int + int2_test: int + int8_test: int + bigserial_test: int + blob_test: memoryview + real_test: float + double_test: float + double_precision_test: float + float_test: float + numeric_test: float + decimal_test: decimal.Decimal + boolean_test: bool + bool_test: bool + date_test: datetime.date + datetime_test: datetime.datetime + timestamp_test: datetime.datetime + character_test: str + varchar_test: str + varyingcharacter_test: str + nchar_test: str + nativecharacter_test: str + nvarchar_test: str + text_test: str + clob_test: str + json_test: str + + +class TestTypeOverride(pydantic.BaseModel): + """Model representing TestTypeOverride. + + Attributes: + id_: int + text_test: UserString | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + text_test: UserString | None diff --git a/test/driver_aiosqlite/pydantic/classes/queries.py b/test/driver_aiosqlite/pydantic/classes/queries.py new file mode 100644 index 00000000..9691bdf9 --- /dev/null +++ b/test/driver_aiosqlite/pydantic/classes/queries.py @@ -0,0 +1,1733 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql +"""Module containing queries from file queries.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "Queries", + "QueryResults", +) + +from collections import UserString +import aiosqlite +import datetime +import decimal +import operator +import typing + +if typing.TYPE_CHECKING: + import collections.abc + import sqlite3 + + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None + +from test.driver_aiosqlite.pydantic.classes import models + + +def _adapt_date(val: datetime.date) -> str: + return val.isoformat() + + +def _convert_date(val: bytes) -> datetime.date: + return datetime.date.fromisoformat(val.decode()) + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _convert_decimal(val: bytes) -> decimal.Decimal: + return decimal.Decimal(val.decode()) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +def _adapt_bool(val: bool) -> int: + return int(val) + + +def _convert_bool(val: bytes) -> bool: + return bool(int(val)) + + +def _adapt_memoryview(val: memoryview) -> bytes: + return val.tobytes() + + +def _convert_memoryview(val: bytes) -> memoryview: + return memoryview(val) + + +aiosqlite.register_adapter(datetime.date, _adapt_date) +aiosqlite.register_adapter(decimal.Decimal, _adapt_decimal) +aiosqlite.register_adapter(datetime.datetime, _adapt_datetime) +aiosqlite.register_adapter(bool, _adapt_bool) +aiosqlite.register_adapter(memoryview, _adapt_memoryview) + +aiosqlite.register_converter("date", _convert_date) +aiosqlite.register_converter("decimal", _convert_decimal) +aiosqlite.register_converter("datetime", _convert_datetime) +aiosqlite.register_converter("timestamp", _convert_datetime) +aiosqlite.register_converter("bool", _convert_bool) +aiosqlite.register_converter("boolean", _convert_bool) +aiosqlite.register_converter("blob", _convert_memoryview) + + +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +""" + +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? +""" + +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +""" + +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +""" + +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +""" + +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? +""" + +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? +""" + +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +""" + +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +""" + +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +""" + +GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? +""" + +GET_MANY_NULLABLE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyNullableInnerSqliteType :many +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? +""" + +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +""" + +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +""" + +GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +""" + +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? +""" + +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? +""" + +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +""" + +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +""" + +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? +""" + +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec +INSERT INTO test_type_override ( + id, text_test +) VALUES (? ,?) +""" + +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? +""" + +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? +""" + +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" + +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" + +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: aiosqlite.Connection, + sql: str, + decode_hook: collections.abc.Callable[[sqlite3.Row], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Args: + conn: + The connection object of type `aiosqlite.Connection` used to execute queries. + sql: + The SQL statement that will be executed when fetching/iterating. + decode_hook: + A callback that turns an `sqlite3.Row` object into `T` that will be returned. + *args: + Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: aiosqlite.Cursor | None = None + self._iterator: collections.abc.AsyncIterator[sqlite3.Row] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns: + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await (await self._conn.execute(self._sql, self._args)).fetchall() + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an aiosqlite cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopAsyncIteration: When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor: aiosqlite.Cursor | None = await self._conn.execute(self._sql, self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +class Queries: + """Queries from file queries.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: aiosqlite.Connection) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> aiosqlite.Connection: + """Connection object used to make queries. + + Returns: + Connection object of type `aiosqlite.Connection` used to make queries. + """ + return self._conn + + async def insert_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await self._conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) + + async def insert_one_inner_sqlite_type( + self, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, + ) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. + + ```sql + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + table_id: int. + int_test: int | None. + bigint_test: int | None. + smallint_test: int | None. + tinyint_test: int | None. + int2_test: int | None. + int8_test: int | None. + bigserial_test: int | None. + blob_test: memoryview | None. + real_test: float | None. + double_test: float | None. + double_precision_test: float | None. + float_test: float | None. + numeric_test: float | None. + decimal_test: decimal.Decimal | None. + boolean_test: bool | None. + bool_test: bool | None. + date_test: datetime.date | None. + datetime_test: datetime.datetime | None. + timestamp_test: datetime.datetime | None. + character_test: str | None. + varchar_test: str | None. + varyingcharacter_test: str | None. + nchar_test: str | None. + nativecharacter_test: str | None. + nvarchar_test: str | None. + text_test: str | None. + clob_test: str | None. + json_test: str | None. + """ + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) + + async def get_one_sqlite_type(self, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. + + ```sql + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `models.TestSqliteType` fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_SQLITE_TYPE, (id_,))).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + async def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? + ``` + + Args: + table_id: int. + + Returns: + Result of type `models.TestInnerSqliteType` fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,))).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + async def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. + + ```sql + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + ``` + + Args: + id_: int. + date_test: datetime.date. + + Returns: + Result of type `datetime.date` fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() + if row is None: + return None + return row[0] + + async def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. + + ```sql + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + ``` + + Args: + id_: int. + datetime_test: datetime.datetime. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() + if row is None: + return None + return row[0] + + async def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. + + ```sql + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + ``` + + Args: + id_: int. + timestamp_test: datetime.datetime. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() + if row is None: + return None + return row[0] + + async def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. + + ```sql + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? + ``` + + Args: + id_: int. + bool_test: bool. + + Returns: + Result of type `bool` fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_BOOL, (id_, bool_test))).fetchone() + if row is None: + return None + return row[0] + + async def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. + + ```sql + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? + ``` + + Args: + id_: int. + boolean_test: bool. + + Returns: + Result of type `bool` fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test))).fetchone() + if row is None: + return None + return row[0] + + async def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. + + ```sql + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + ``` + + Args: + id_: int. + decimal_test: decimal.Decimal. + + Returns: + Result of type `decimal.Decimal` fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() + if row is None: + return None + return row[0] + + async def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. + + ```sql + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + ``` + + Args: + id_: int. + blob_test: memoryview. + + Returns: + Result of type `memoryview` fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone() + if row is None: + return None + return row[0] + + def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. + + ```sql + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + + def get_many_inner_sqlite_type(self, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? + ``` + + Args: + table_id: int. + + Returns: + Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + + def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? + ``` + + Args: + table_id: int. + int_test: int | None. + + Returns: + Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + + def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. + + ```sql + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + ``` + + Args: + id_: int. + date_test: datetime.date. + + Returns: + Helper class of type `QueryResults[datetime.date]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + + def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. + + ```sql + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + ``` + + Args: + id_: int. + datetime_test: datetime.datetime. + + Returns: + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) + + def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. + + ```sql + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + ``` + + Args: + id_: int. + timestamp_test: datetime.datetime. + + Returns: + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) + + def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. + + ```sql + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? + ``` + + Args: + id_: int. + bool_test: bool. + + Returns: + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + + def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. + + ```sql + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? + ``` + + Args: + id_: int. + boolean_test: bool. + + Returns: + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + + def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. + + ```sql + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + ``` + + Args: + id_: int. + decimal_test: decimal.Decimal. + + Returns: + Helper class of type `QueryResults[decimal.Decimal]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. + + ```sql + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + ``` + + Args: + id_: int. + blob_test: memoryview. + + Returns: + Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + + async def delete_one_sqlite_type(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + """ + await self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) + + async def delete_one_test_inner_sqlite_type(self, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + + ```sql + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? + ``` + + Args: + table_id: int. + """ + await self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) + + async def insert_result_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + + Returns: + The result of type `aiosqlite.Cursor` returned when executing the query. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return await self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) + + async def update_result_one_sqlite_type(self, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The result of type `aiosqlite.Cursor` returned when executing the query. + """ + return await self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + async def delete_result_one_sqlite_type(self, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The result of type `aiosqlite.Cursor` returned when executing the query. + """ + return await self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + async def insert_rows_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args)).rowcount + + async def update_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + async def delete_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + async def create_rows_table(self) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await self._conn.execute(CREATE_ROWS_TABLE)).rowcount + + async def insert_last_id_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args)).lastrowid + + async def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + return (await self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid + + async def delete_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + return (await self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid + + async def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: + """Execute SQL query with `name: InsertTypeOverride :exec`. + + ```sql + INSERT INTO test_type_override ( + id, text_test + ) VALUES (? ,?) + ``` + + Args: + id_: int. + text_test: UserString | None. + """ + await self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) + + async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + + ```sql + SELECT id, text_test FROM test_type_override WHERE id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. + + ```sql + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + async def get_one_text_type_override(self, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `UserString` fetched from the db. Will be `None` if not found. + """ + row = await (await self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[UserString | None]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + async def delete_type_override(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Args: + id_: int. + """ + await self._conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_aiosqlite/pydantic/functions/__init__.py b/test/driver_aiosqlite/pydantic/functions/__init__.py new file mode 100644 index 00000000..5c9110dc --- /dev/null +++ b/test/driver_aiosqlite/pydantic/functions/__init__.py @@ -0,0 +1,5 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_aiosqlite/pydantic/functions/models.py b/test/driver_aiosqlite/pydantic/functions/models.py new file mode 100644 index 00000000..846ac2c1 --- /dev/null +++ b/test/driver_aiosqlite/pydantic/functions/models.py @@ -0,0 +1,172 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing models.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "TestInnerSqliteType", + "TestSqliteType", + "TestTypeOverride", +) + +from collections import UserString +import datetime +import decimal +import pydantic +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +class TestInnerSqliteType(pydantic.BaseModel): + """Model representing TestInnerSqliteType. + + Attributes: + table_id: int + int_test: int | None + bigint_test: int | None + smallint_test: int | None + tinyint_test: int | None + int2_test: int | None + int8_test: int | None + bigserial_test: int | None + blob_test: memoryview | None + real_test: float | None + double_test: float | None + double_precision_test: float | None + float_test: float | None + numeric_test: float | None + decimal_test: decimal.Decimal | None + boolean_test: bool | None + bool_test: bool | None + date_test: datetime.date | None + datetime_test: datetime.datetime | None + timestamp_test: datetime.datetime | None + character_test: str | None + varchar_test: str | None + varyingcharacter_test: str | None + nchar_test: str | None + nativecharacter_test: str | None + nvarchar_test: str | None + text_test: str | None + clob_test: str | None + json_test: str | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + table_id: int + int_test: int | None + bigint_test: int | None + smallint_test: int | None + tinyint_test: int | None + int2_test: int | None + int8_test: int | None + bigserial_test: int | None + blob_test: memoryview | None + real_test: float | None + double_test: float | None + double_precision_test: float | None + float_test: float | None + numeric_test: float | None + decimal_test: decimal.Decimal | None + boolean_test: bool | None + bool_test: bool | None + date_test: datetime.date | None + datetime_test: datetime.datetime | None + timestamp_test: datetime.datetime | None + character_test: str | None + varchar_test: str | None + varyingcharacter_test: str | None + nchar_test: str | None + nativecharacter_test: str | None + nvarchar_test: str | None + text_test: str | None + clob_test: str | None + json_test: str | None + + +class TestSqliteType(pydantic.BaseModel): + """Model representing TestSqliteType. + + Attributes: + id_: int + int_test: int + bigint_test: int + smallint_test: int + tinyint_test: int + int2_test: int + int8_test: int + bigserial_test: int + blob_test: memoryview + real_test: float + double_test: float + double_precision_test: float + float_test: float + numeric_test: float + decimal_test: decimal.Decimal + boolean_test: bool + bool_test: bool + date_test: datetime.date + datetime_test: datetime.datetime + timestamp_test: datetime.datetime + character_test: str + varchar_test: str + varyingcharacter_test: str + nchar_test: str + nativecharacter_test: str + nvarchar_test: str + text_test: str + clob_test: str + json_test: str + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + int_test: int + bigint_test: int + smallint_test: int + tinyint_test: int + int2_test: int + int8_test: int + bigserial_test: int + blob_test: memoryview + real_test: float + double_test: float + double_precision_test: float + float_test: float + numeric_test: float + decimal_test: decimal.Decimal + boolean_test: bool + bool_test: bool + date_test: datetime.date + datetime_test: datetime.datetime + timestamp_test: datetime.datetime + character_test: str + varchar_test: str + varyingcharacter_test: str + nchar_test: str + nativecharacter_test: str + nvarchar_test: str + text_test: str + clob_test: str + json_test: str + + +class TestTypeOverride(pydantic.BaseModel): + """Model representing TestTypeOverride. + + Attributes: + id_: int + text_test: UserString | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + text_test: UserString | None diff --git a/test/driver_aiosqlite/pydantic/functions/queries.py b/test/driver_aiosqlite/pydantic/functions/queries.py new file mode 100644 index 00000000..f4953bb3 --- /dev/null +++ b/test/driver_aiosqlite/pydantic/functions/queries.py @@ -0,0 +1,1866 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql +"""Module containing queries from file queries.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "QueryResults", + "create_rows_table", + "delete_last_id_one_sqlite_type", + "delete_one_sqlite_type", + "delete_one_test_inner_sqlite_type", + "delete_result_one_sqlite_type", + "delete_rows_one_sqlite_type", + "delete_type_override", + "get_many_blob", + "get_many_bool", + "get_many_boolean", + "get_many_date", + "get_many_datetime", + "get_many_decimal", + "get_many_inner_sqlite_type", + "get_many_nullable_inner_sqlite_type", + "get_many_sqlite_type", + "get_many_text_type_override", + "get_many_timestamp", + "get_many_type_override", + "get_one_blob", + "get_one_bool", + "get_one_boolean", + "get_one_date", + "get_one_datetime", + "get_one_decimal", + "get_one_inner_sqlite_type", + "get_one_sqlite_type", + "get_one_text_type_override", + "get_one_timestamp", + "get_one_type_override", + "insert_last_id_one_sqlite_type", + "insert_one_inner_sqlite_type", + "insert_one_sqlite_type", + "insert_result_one_sqlite_type", + "insert_rows_one_sqlite_type", + "insert_type_override", + "update_last_id_one_sqlite_type", + "update_result_one_sqlite_type", + "update_rows_one_sqlite_type", +) + +from collections import UserString +import aiosqlite +import datetime +import decimal +import operator +import typing + +if typing.TYPE_CHECKING: + import collections.abc + import sqlite3 + + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None + +from test.driver_aiosqlite.pydantic.functions import models + + +def _adapt_date(val: datetime.date) -> str: + return val.isoformat() + + +def _convert_date(val: bytes) -> datetime.date: + return datetime.date.fromisoformat(val.decode()) + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _convert_decimal(val: bytes) -> decimal.Decimal: + return decimal.Decimal(val.decode()) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +def _adapt_bool(val: bool) -> int: + return int(val) + + +def _convert_bool(val: bytes) -> bool: + return bool(int(val)) + + +def _adapt_memoryview(val: memoryview) -> bytes: + return val.tobytes() + + +def _convert_memoryview(val: bytes) -> memoryview: + return memoryview(val) + + +aiosqlite.register_adapter(datetime.date, _adapt_date) +aiosqlite.register_adapter(decimal.Decimal, _adapt_decimal) +aiosqlite.register_adapter(datetime.datetime, _adapt_datetime) +aiosqlite.register_adapter(bool, _adapt_bool) +aiosqlite.register_adapter(memoryview, _adapt_memoryview) + +aiosqlite.register_converter("date", _convert_date) +aiosqlite.register_converter("decimal", _convert_decimal) +aiosqlite.register_converter("datetime", _convert_datetime) +aiosqlite.register_converter("timestamp", _convert_datetime) +aiosqlite.register_converter("bool", _convert_bool) +aiosqlite.register_converter("boolean", _convert_bool) +aiosqlite.register_converter("blob", _convert_memoryview) + + +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +""" + +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? +""" + +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +""" + +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +""" + +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +""" + +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? +""" + +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? +""" + +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +""" + +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +""" + +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +""" + +GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? +""" + +GET_MANY_NULLABLE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyNullableInnerSqliteType :many +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? +""" + +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +""" + +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +""" + +GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +""" + +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? +""" + +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? +""" + +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +""" + +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +""" + +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? +""" + +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec +INSERT INTO test_type_override ( + id, text_test +) VALUES (? ,?) +""" + +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? +""" + +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? +""" + +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" + +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" + +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: aiosqlite.Connection, + sql: str, + decode_hook: collections.abc.Callable[[sqlite3.Row], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Args: + conn: + The connection object of type `aiosqlite.Connection` used to execute queries. + sql: + The SQL statement that will be executed when fetching/iterating. + decode_hook: + A callback that turns an `sqlite3.Row` object into `T` that will be returned. + *args: + Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: aiosqlite.Cursor | None = None + self._iterator: collections.abc.AsyncIterator[sqlite3.Row] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns: + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await (await self._conn.execute(self._sql, self._args)).fetchall() + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an aiosqlite cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopAsyncIteration: When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor: aiosqlite.Cursor | None = await self._conn.execute(self._sql, self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +async def insert_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) + + +async def insert_one_inner_sqlite_type( + conn: aiosqlite.Connection, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, +) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. + + ```sql + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + table_id: int. + int_test: int | None. + bigint_test: int | None. + smallint_test: int | None. + tinyint_test: int | None. + int2_test: int | None. + int8_test: int | None. + bigserial_test: int | None. + blob_test: memoryview | None. + real_test: float | None. + double_test: float | None. + double_precision_test: float | None. + float_test: float | None. + numeric_test: float | None. + decimal_test: decimal.Decimal | None. + boolean_test: bool | None. + bool_test: bool | None. + date_test: datetime.date | None. + datetime_test: datetime.datetime | None. + timestamp_test: datetime.datetime | None. + character_test: str | None. + varchar_test: str | None. + varyingcharacter_test: str | None. + nchar_test: str | None. + nativecharacter_test: str | None. + nvarchar_test: str | None. + text_test: str | None. + clob_test: str | None. + json_test: str | None. + """ + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + await conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) + + +async def get_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. + + ```sql + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + Result of type `models.TestSqliteType` fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_SQLITE_TYPE, (id_,))).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + +async def get_one_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + table_id: int. + + Returns: + Result of type `models.TestInnerSqliteType` fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,))).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + +async def get_one_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. + + ```sql + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + date_test: datetime.date. + + Returns: + Result of type `datetime.date` fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_DATE, (id_, date_test))).fetchone() + if row is None: + return None + return row[0] + + +async def get_one_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. + + ```sql + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + datetime_test: datetime.datetime. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_DATETIME, (id_, datetime_test))).fetchone() + if row is None: + return None + return row[0] + + +async def get_one_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. + + ```sql + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + timestamp_test: datetime.datetime. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test))).fetchone() + if row is None: + return None + return row[0] + + +async def get_one_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. + + ```sql + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + bool_test: bool. + + Returns: + Result of type `bool` fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_BOOL, (id_, bool_test))).fetchone() + if row is None: + return None + return row[0] + + +async def get_one_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. + + ```sql + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + boolean_test: bool. + + Returns: + Result of type `bool` fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test))).fetchone() + if row is None: + return None + return row[0] + + +async def get_one_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. + + ```sql + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + decimal_test: decimal.Decimal. + + Returns: + Result of type `decimal.Decimal` fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_DECIMAL, (id_, decimal_test))).fetchone() + if row is None: + return None + return row[0] + + +async def get_one_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. + + ```sql + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + blob_test: memoryview. + + Returns: + Result of type `memoryview` fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_BLOB, (id_, blob_test))).fetchone() + if row is None: + return None + return row[0] + + +def get_many_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. + + ```sql + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + + +def get_many_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + table_id: int. + + Returns: + Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + + +def get_many_nullable_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + table_id: int. + int_test: int | None. + + Returns: + Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + + +def get_many_date(conn: aiosqlite.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. + + ```sql + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + date_test: datetime.date. + + Returns: + Helper class of type `QueryResults[datetime.date]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + + +def get_many_datetime(conn: aiosqlite.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. + + ```sql + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + datetime_test: datetime.datetime. + + Returns: + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) + + +def get_many_timestamp(conn: aiosqlite.Connection, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. + + ```sql + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + timestamp_test: datetime.datetime. + + Returns: + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) + + +def get_many_bool(conn: aiosqlite.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. + + ```sql + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + bool_test: bool. + + Returns: + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + + +def get_many_boolean(conn: aiosqlite.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. + + ```sql + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + boolean_test: bool. + + Returns: + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + + +def get_many_decimal(conn: aiosqlite.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. + + ```sql + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + decimal_test: decimal.Decimal. + + Returns: + Helper class of type `QueryResults[decimal.Decimal]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + +def get_many_blob(conn: aiosqlite.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. + + ```sql + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + blob_test: memoryview. + + Returns: + Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + + +async def delete_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + """ + await conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) + + +async def delete_one_test_inner_sqlite_type(conn: aiosqlite.Connection, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + + ```sql + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + table_id: int. + """ + await conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) + + +async def insert_result_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + + Returns: + The result of type `aiosqlite.Cursor` returned when executing the query. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return await conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) + + +async def update_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + The result of type `aiosqlite.Cursor` returned when executing the query. + """ + return await conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +async def delete_result_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> aiosqlite.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + The result of type `aiosqlite.Cursor` returned when executing the query. + """ + return await conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +async def insert_rows_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args)).rowcount + + +async def update_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + +async def delete_rows_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,))).rowcount + + +async def create_rows_table(conn: aiosqlite.Connection) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return (await conn.execute(CREATE_ROWS_TABLE)).rowcount + + +async def insert_last_id_one_sqlite_type( + conn: aiosqlite.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return (await conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args)).lastrowid + + +async def update_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + return (await conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid + + +async def delete_last_id_one_sqlite_type(conn: aiosqlite.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + return (await conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,))).lastrowid + + +async def insert_type_override(conn: aiosqlite.Connection, *, id_: int, text_test: UserString | None) -> None: + """Execute SQL query with `name: InsertTypeOverride :exec`. + + ```sql + INSERT INTO test_type_override ( + id, text_test + ) VALUES (? ,?) + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + text_test: UserString | None. + """ + await conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) + + +async def get_one_type_override(conn: aiosqlite.Connection, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + + ```sql + SELECT id, text_test FROM test_type_override WHERE id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + +def get_many_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. + + ```sql + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + +async def get_one_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + Result of type `UserString` fetched from the db. Will be `None` if not found. + """ + row = await (await conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,))).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + +def get_many_text_type_override(conn: aiosqlite.Connection, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[UserString | None]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + +async def delete_type_override(conn: aiosqlite.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Args: + conn: + Connection object of type `aiosqlite.Connection` used to execute the query. + id_: int. + """ + await conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_aiosqlite/pydantic/ruff.toml b/test/driver_aiosqlite/pydantic/ruff.toml new file mode 100644 index 00000000..ded540a0 --- /dev/null +++ b/test/driver_aiosqlite/pydantic/ruff.toml @@ -0,0 +1,9 @@ +extend="../../../ruff.toml" + + +[lint.flake8-type-checking] +runtime-evaluated-base-classes = ["pydantic.BaseModel"] + + +[lint.pydocstyle] +convention = "google" \ No newline at end of file diff --git a/test/driver_aiosqlite/pydantic/test_aiosqlite_pydantic_classes.py b/test/driver_aiosqlite/pydantic/test_aiosqlite_pydantic_classes.py new file mode 100644 index 00000000..6b2ff11f --- /dev/null +++ b/test/driver_aiosqlite/pydantic/test_aiosqlite_pydantic_classes.py @@ -0,0 +1,967 @@ +# Copyright (c) 2025 Rayakame + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +from __future__ import annotations + +import collections.abc +import datetime +import decimal +import json +import math +import random +from collections import UserString + +import aiosqlite +import pytest +import pytest_asyncio + +from test.driver_aiosqlite.pydantic.classes import models +from test.driver_aiosqlite.pydantic.classes import queries + + +@pytest.mark.asyncio(loop_scope="session") +class TestPydanticClasses: + @pytest.fixture(scope="session") + def override_model(self) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) + + @pytest.fixture(scope="session") + def model(self) -> models.TestSqliteType: + return models.TestSqliteType( + id_=random.randint(1, 10000000), + int_test=42, + bigint_test=9_007_199_254_740_991, + smallint_test=32_767, + tinyint_test=255, + int2_test=12_345, + int8_test=123_456_789, + bigserial_test=1, + blob_test=memoryview(b"\x00\x01\x02hello"), + real_test=math.pi, + double_test=math.e, + double_precision_test=1.41421, + float_test=9.81, + numeric_test=123.456, + decimal_test=decimal.Decimal("789.0123"), + bool_test=True, + boolean_test=False, + date_test=datetime.date(2025, 1, 1), + datetime_test=datetime.datetime(2025, 1, 1, 12), + timestamp_test=datetime.datetime.now(), + character_test="ABCDEFGHIJ", + varchar_test="Hello varchar", + varyingcharacter_test="VarChar variant", + nchar_test="ABCDEFGHIJ", + nativecharacter_test="NativeChar", + nvarchar_test="Olá mundo", + text_test="Some text", + clob_test="Some clob data", + json_test=json.dumps({"foo": "bar"}), + ) + + @pytest.fixture(scope="session") + def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=model.id_, + int_test=None, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=None, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=None, + bool_test=None, + boolean_test=None, + date_test=None, + datetime_test=None, + timestamp_test=None, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + + @pytest_asyncio.fixture(scope="class", loop_scope="session") + async def queries_obj(self, aiosqlite_conn: aiosqlite.Connection) -> queries.Queries: + return queries.Queries(conn=aiosqlite_conn) + + @pytest.mark.asyncio(loop_scope="session") + async def test_conn_attr(self, queries_obj: queries.Queries) -> None: + assert isinstance(queries_obj.conn, aiosqlite.Connection) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::insert") + async def test_insert( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + await queries_obj.insert_one_sqlite_type( + id_=model.id_, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::inner_insert", depends=["AiosqliteTestPydanticClasses::insert"]) + async def test_inner_insert( + self, + queries_obj: queries.Queries, + inner_model: models.TestInnerSqliteType, + ) -> None: + await queries_obj.insert_one_inner_sqlite_type( + table_id=inner_model.table_id, + int_test=inner_model.int_test, + bigint_test=inner_model.bigint_test, + smallint_test=inner_model.smallint_test, + tinyint_test=inner_model.tinyint_test, + int2_test=inner_model.int2_test, + int8_test=inner_model.int8_test, + bigserial_test=inner_model.bigserial_test, + blob_test=inner_model.blob_test, + real_test=inner_model.real_test, + double_test=inner_model.double_test, + double_precision_test=inner_model.double_precision_test, + float_test=inner_model.float_test, + numeric_test=inner_model.numeric_test, + decimal_test=inner_model.decimal_test, + bool_test=inner_model.bool_test, + boolean_test=inner_model.boolean_test, + date_test=inner_model.date_test, + datetime_test=inner_model.datetime_test, + timestamp_test=inner_model.timestamp_test, + character_test=inner_model.character_test, + varchar_test=inner_model.varchar_test, + varyingcharacter_test=inner_model.varyingcharacter_test, + nchar_test=inner_model.nchar_test, + nativecharacter_test=inner_model.nativecharacter_test, + nvarchar_test=inner_model.nvarchar_test, + text_test=inner_model.text_test, + clob_test=inner_model.clob_test, + json_test=inner_model.json_test, + ) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_one", depends=["AiosqliteTestPydanticClasses::inner_insert"]) + async def test_get_one( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.get_one_sqlite_type(id_=model.id_) + + assert result is not None + + assert isinstance(result, models.TestSqliteType) + + assert result == model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_one_none", depends=["AiosqliteTestPydanticClasses::get_one"]) + async def test_get_one_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = await queries_obj.get_one_sqlite_type(id_=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_one_inner", depends=["AiosqliteTestPydanticClasses::get_one_none"]) + async def test_get_one_inner( + self, + queries_obj: queries.Queries, + inner_model: models.TestInnerSqliteType, + ) -> None: + result = await queries_obj.get_one_inner_sqlite_type(table_id=inner_model.table_id) + + assert result is not None + + assert isinstance(result, models.TestInnerSqliteType) + assert result == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_one_inner_none", + depends=["AiosqliteTestPydanticClasses::get_one_inner"], + ) + async def test_get_one_inner_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = await queries_obj.get_one_inner_sqlite_type(table_id=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_date", depends=["AiosqliteTestPydanticClasses::get_one_inner_none"]) + async def test_get_date( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.get_one_date(id_=model.id_, date_test=model.date_test) + + assert result is not None + + assert isinstance(result, datetime.date) + assert result == model.date_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_date_none", depends=["AiosqliteTestPydanticClasses::get_date"]) + async def test_get_date_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = await queries_obj.get_one_date(id_=0, date_test=datetime.date.today()) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_datetime", depends=["AiosqliteTestPydanticClasses::get_date_none"]) + async def test_get_datetime( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.get_one_datetime(id_=model.id_, datetime_test=model.datetime_test) + + assert result is not None + + assert isinstance(result, datetime.datetime) + assert result == model.datetime_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_datetime_none", depends=["AiosqliteTestPydanticClasses::get_datetime"]) + async def test_get_datetime_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = await queries_obj.get_one_datetime(id_=0, datetime_test=datetime.datetime.now()) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_timestamp", + depends=["AiosqliteTestPydanticClasses::get_datetime_none"], + ) + async def test_get_timestamp( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.get_one_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) + + assert result is not None + + assert isinstance(result, datetime.datetime) + assert result == model.timestamp_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_timestamp_none", + depends=["AiosqliteTestPydanticClasses::get_timestamp"], + ) + async def test_get_timestamp_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = await queries_obj.get_one_timestamp(id_=0, timestamp_test=datetime.datetime.now()) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_bool", depends=["AiosqliteTestPydanticClasses::get_timestamp_none"]) + async def test_get_bool( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.get_one_bool(id_=model.id_, bool_test=model.bool_test) + + assert result is not None + + assert isinstance(result, bool) + assert result == model.bool_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_bool_none", depends=["AiosqliteTestPydanticClasses::get_bool"]) + async def test_get_bool_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = await queries_obj.get_one_bool(id_=0, bool_test=False) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_boolean", depends=["AiosqliteTestPydanticClasses::get_bool_none"]) + async def test_get_boolean( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.get_one_boolean(id_=model.id_, boolean_test=model.boolean_test) + + assert result is not None + + assert isinstance(result, bool) + assert result == model.boolean_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_boolean_none", depends=["AiosqliteTestPydanticClasses::get_boolean"]) + async def test_get_boolean_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = await queries_obj.get_one_boolean(id_=0, boolean_test=True) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_decimal", depends=["AiosqliteTestPydanticClasses::get_boolean_none"]) + async def test_get_decimal( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.get_one_decimal(id_=model.id_, decimal_test=model.decimal_test) + + assert result is not None + + assert isinstance(result, decimal.Decimal) + assert result == model.decimal_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_decimal_none", depends=["AiosqliteTestPydanticClasses::get_decimal"]) + async def test_get_decimal_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = await queries_obj.get_one_decimal(id_=0, decimal_test=decimal.Decimal("0.1")) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_blob", depends=["AiosqliteTestPydanticClasses::get_decimal_none"]) + async def test_get_blob( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.get_one_blob(id_=model.id_, blob_test=model.blob_test) + + assert result is not None + + assert isinstance(result, memoryview) + assert result == model.blob_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_blob_none", depends=["AiosqliteTestPydanticClasses::get_blob"]) + async def test_get_blob_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = await queries_obj.get_one_blob(id_=0, blob_test=memoryview(b"test")) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_many", depends=["AiosqliteTestPydanticClasses::get_blob_none"]) + async def test_get_many(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = await queries_obj.get_many_sqlite_type(id_=model.id_) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], models.TestSqliteType) + + assert result[0] == model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_many_iter", depends=["AiosqliteTestPydanticClasses::get_many"]) + async def test_get_many_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + async for result in queries_obj.get_many_sqlite_type(id_=model.id_): + assert result is not None + assert isinstance(result, models.TestSqliteType) + + assert result == model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::get_many_inner", depends=["AiosqliteTestPydanticClasses::get_many_iter"]) + async def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + result = await queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], models.TestInnerSqliteType) + + assert result[0] == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_inner_iter", + depends=["AiosqliteTestPydanticClasses::get_many_inner"], + ) + async def test_get_many_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + async for result in queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id): + assert result is not None + assert isinstance(result, models.TestInnerSqliteType) + + assert result == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_nullable_inner", + depends=["AiosqliteTestPydanticClasses::get_many_inner_iter"], + ) + async def test_get_many_nullable_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + result = await queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], models.TestInnerSqliteType) + + assert result[0] == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_nullable_inner_iter", + depends=["AiosqliteTestPydanticClasses::get_many_nullable_inner"], + ) + async def test_get_many_nullable_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + async for result in queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test): + assert result is not None + assert isinstance(result, models.TestInnerSqliteType) + + assert result == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_date", + depends=["AiosqliteTestPydanticClasses::get_many_nullable_inner_iter"], + ) + async def test_get_many_date(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = await queries_obj.get_many_date(id_=model.id_, date_test=model.date_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], datetime.date) + + assert result[0] == model.date_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_date_iter", + depends=["AiosqliteTestPydanticClasses::get_many_date"], + ) + async def test_get_many_date_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + async for result in queries_obj.get_many_date(id_=model.id_, date_test=model.date_test): + assert result is not None + assert isinstance(result, datetime.date) + + assert result == model.date_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_datetime", + depends=["AiosqliteTestPydanticClasses::get_many_date_iter"], + ) + async def test_get_many_datetime(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = await queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], datetime.datetime) + + assert result[0] == model.datetime_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_datetime_iter", + depends=["AiosqliteTestPydanticClasses::get_many_datetime"], + ) + async def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + async for result in queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test): + assert result is not None + assert isinstance(result, datetime.datetime) + + assert result == model.datetime_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_timestamp", + depends=["AiosqliteTestPydanticClasses::get_many_datetime_iter"], + ) + async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = await queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], datetime.datetime) + + assert result[0] == model.timestamp_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_timestamp_iter", + depends=["AiosqliteTestPydanticClasses::get_many_timestamp"], + ) + async def test_get_many_timestamp_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + async for result in queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test): + assert result is not None + assert isinstance(result, datetime.datetime) + + assert result == model.timestamp_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_bool", + depends=["AiosqliteTestPydanticClasses::get_many_timestamp_iter"], + ) + async def test_get_many_bool(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = await queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], bool) + + assert result[0] == model.bool_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_bool_iter", + depends=["AiosqliteTestPydanticClasses::get_many_bool"], + ) + async def test_get_many_bool_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + async for result in queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test): + assert result is not None + assert isinstance(result, bool) + + assert result == model.bool_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_boolean", + depends=["AiosqliteTestPydanticClasses::get_many_bool_iter"], + ) + async def test_get_many_boolean(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = await queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], bool) + + assert result[0] == model.boolean_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_boolean_iter", + depends=["AiosqliteTestPydanticClasses::get_many_boolean"], + ) + async def test_get_many_boolean_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + async for result in queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test): + assert result is not None + assert isinstance(result, bool) + + assert result == model.boolean_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_decimal", + depends=["AiosqliteTestPydanticClasses::get_many_boolean_iter"], + ) + async def test_get_many_decimal(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = await queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], decimal.Decimal) + + assert result[0] == model.decimal_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_decimal_iter", + depends=["AiosqliteTestPydanticClasses::get_many_decimal"], + ) + async def test_get_many_decimal_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + async for result in queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test): + assert result is not None + assert isinstance(result, decimal.Decimal) + + assert result == model.decimal_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_blob", + depends=["AiosqliteTestPydanticClasses::get_many_decimal_iter"], + ) + async def test_get_many_blob(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = await queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], memoryview) + + assert result[0] == model.blob_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_blob_iter", + depends=["AiosqliteTestPydanticClasses::get_many_blob"], + ) + async def test_get_many_blob_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + async for result in queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test): + assert result is not None + assert isinstance(result, memoryview) + + assert result == model.blob_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::insert_result", + depends=["AiosqliteTestPydanticClasses::get_many_blob_iter"], + ) + async def test_insert_result( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.insert_result_one_sqlite_type( + id_=model.id_ + 1, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + assert isinstance(result, aiosqlite.Cursor) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::update_result", depends=["AiosqliteTestPydanticClasses::insert_result"]) + async def test_update_result( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.update_result_one_sqlite_type(id_=model.id_ + 1) + assert isinstance(result, aiosqlite.Cursor) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::delete_result", depends=["AiosqliteTestPydanticClasses::update_result"]) + async def test_delete_result( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.delete_result_one_sqlite_type(id_=model.id_ + 1) + assert isinstance(result, aiosqlite.Cursor) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::insert_rows", depends=["AiosqliteTestPydanticClasses::delete_result"]) + async def test_insert_rows( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.insert_rows_one_sqlite_type( + id_=model.id_ + 2, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + assert isinstance(result, int) + assert result == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::update_rows", depends=["AiosqliteTestPydanticClasses::insert_rows"]) + async def test_update_rows( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.update_rows_one_sqlite_type(id_=model.id_ + 2) + assert isinstance(result, int) + assert result == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::delete_rows", depends=["AiosqliteTestPydanticClasses::update_rows"]) + async def test_delete_rows( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.delete_rows_one_sqlite_type(id_=model.id_ + 2) + assert isinstance(result, int) + assert result == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::create_table_rows", depends=["AiosqliteTestPydanticClasses::delete_rows"]) + async def test_create_table_rows( + self, + queries_obj: queries.Queries, + aiosqlite_conn: aiosqlite.Connection, + ) -> None: + result = await queries_obj.create_rows_table() + assert isinstance(result, int) + await aiosqlite_conn.execute("DROP TABLE test_create_rows_table;") + await aiosqlite_conn.commit() + assert result == -1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::insert_last_id", + depends=["AiosqliteTestPydanticClasses::create_table_rows"], + ) + async def test_insert_last_id( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.insert_last_id_one_sqlite_type( + id_=model.id_ + 3, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + assert isinstance(result, int) + assert result == model.id_ + 3 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::update_last_id", depends=["AiosqliteTestPydanticClasses::insert_last_id"]) + async def test_update_last_id( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.update_last_id_one_sqlite_type(id_=model.id_ + 3) + assert isinstance(result, int) + assert result == model.id_ + 3 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticClasses::delete_last_id", depends=["AiosqliteTestPydanticClasses::update_last_id"]) + async def test_delete_last_id( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = await queries_obj.delete_last_id_one_sqlite_type(id_=model.id_ + 3) + assert isinstance(result, int) + assert result == model.id_ + 3 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::delete_sqlite_type", + depends=["AiosqliteTestPydanticClasses::delete_last_id"], + ) + async def test_delete_sqlite_type(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + await queries_obj.delete_one_sqlite_type(id_=model.id_) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::delete_inner_sqlite_type", + depends=["AiosqliteTestPydanticClasses::delete_sqlite_type"], + ) + async def test_delete_inner_sqlite_type(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + await queries_obj.delete_one_test_inner_sqlite_type(table_id=inner_model.table_id) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::insert_type_override", + ) + async def test_insert_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.insert_type_override(id_=override_model.id_, text_test=override_model.text_test) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_one_type_override", + depends=["AiosqliteTestPydanticClasses::insert_type_override"], + ) + async def test_get_one_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_) + assert result is not None + assert result == override_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_one_type_override_none", + depends=["AiosqliteTestPydanticClasses::get_one_type_override"], + ) + async def test_get_one_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_ - 1) + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_type_override", + depends=["AiosqliteTestPydanticClasses::get_one_type_override_none"], + ) + async def test_get_many_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_type_override(id_=override_model.id_) + assert isinstance(result, collections.abc.Sequence) + assert result[0] == override_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_one_text_type_override", + depends=["AiosqliteTestPydanticClasses::get_many_type_override"], + ) + async def test_get_one_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_) + assert result is not None + assert result == override_model.text_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_one_text_type_override_none", + depends=["AiosqliteTestPydanticClasses::get_one_text_type_override"], + ) + async def test_get_one_text_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_ - 1) + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::get_many_text_type_override", + depends=["AiosqliteTestPydanticClasses::get_one_text_type_override_none"], + ) + async def test_get_many_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_text_type_override(id_=override_model.id_) + assert isinstance(result, collections.abc.Sequence) + assert result[0] == override_model.text_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticClasses::delete_type_override", + depends=["AiosqliteTestPydanticClasses::get_many_text_type_override"], + ) + async def test_delete_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.delete_type_override(id_=override_model.id_) diff --git a/test/driver_aiosqlite/pydantic/test_aiosqlite_pydantic_functions.py b/test/driver_aiosqlite/pydantic/test_aiosqlite_pydantic_functions.py new file mode 100644 index 00000000..25bb61e0 --- /dev/null +++ b/test/driver_aiosqlite/pydantic/test_aiosqlite_pydantic_functions.py @@ -0,0 +1,998 @@ +# Copyright (c) 2025 Rayakame + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +from __future__ import annotations + +import collections.abc +import datetime +import decimal +import json +import math +import random +from collections import UserString + +import aiosqlite +import pytest + +from test.driver_aiosqlite.pydantic.functions import models +from test.driver_aiosqlite.pydantic.functions import queries + + +@pytest.mark.asyncio(loop_scope="session") +class TestPydanticFunctions: + @pytest.fixture(scope="session") + def override_model(self) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) + + @pytest.fixture(scope="session") + def model(self) -> models.TestSqliteType: + return models.TestSqliteType( + id_=random.randint(1, 10000000), + int_test=42, + bigint_test=9_007_199_254_740_991, + smallint_test=32_767, + tinyint_test=255, + int2_test=12_345, + int8_test=123_456_789, + bigserial_test=1, + blob_test=memoryview(b"\x00\x01\x02hello"), + real_test=math.pi, + double_test=math.e, + double_precision_test=1.41421, + float_test=9.81, + numeric_test=123.456, + decimal_test=decimal.Decimal("789.0123"), + bool_test=True, + boolean_test=False, + date_test=datetime.date(2025, 1, 1), + datetime_test=datetime.datetime(2025, 1, 1, 12), + timestamp_test=datetime.datetime.now(), + character_test="ABCDEFGHIJ", + varchar_test="Hello varchar", + varyingcharacter_test="VarChar variant", + nchar_test="ABCDEFGHIJ", + nativecharacter_test="NativeChar", + nvarchar_test="Olá mundo", + text_test="Some text", + clob_test="Some clob data", + json_test=json.dumps({"foo": "bar"}), + ) + + @pytest.fixture(scope="session") + def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=model.id_, + int_test=None, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=None, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=None, + bool_test=None, + boolean_test=None, + date_test=None, + datetime_test=None, + timestamp_test=None, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::insert") + async def test_insert( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + await queries.insert_one_sqlite_type( + conn=aiosqlite_conn, + id_=model.id_, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::inner_insert", depends=["AiosqliteTestPydanticFunctions::insert"]) + async def test_inner_insert( + self, + aiosqlite_conn: aiosqlite.Connection, + inner_model: models.TestInnerSqliteType, + ) -> None: + await queries.insert_one_inner_sqlite_type( + conn=aiosqlite_conn, + table_id=inner_model.table_id, + int_test=inner_model.int_test, + bigint_test=inner_model.bigint_test, + smallint_test=inner_model.smallint_test, + tinyint_test=inner_model.tinyint_test, + int2_test=inner_model.int2_test, + int8_test=inner_model.int8_test, + bigserial_test=inner_model.bigserial_test, + blob_test=inner_model.blob_test, + real_test=inner_model.real_test, + double_test=inner_model.double_test, + double_precision_test=inner_model.double_precision_test, + float_test=inner_model.float_test, + numeric_test=inner_model.numeric_test, + decimal_test=inner_model.decimal_test, + bool_test=inner_model.bool_test, + boolean_test=inner_model.boolean_test, + date_test=inner_model.date_test, + datetime_test=inner_model.datetime_test, + timestamp_test=inner_model.timestamp_test, + character_test=inner_model.character_test, + varchar_test=inner_model.varchar_test, + varyingcharacter_test=inner_model.varyingcharacter_test, + nchar_test=inner_model.nchar_test, + nativecharacter_test=inner_model.nativecharacter_test, + nvarchar_test=inner_model.nvarchar_test, + text_test=inner_model.text_test, + clob_test=inner_model.clob_test, + json_test=inner_model.json_test, + ) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::get_one", depends=["AiosqliteTestPydanticFunctions::inner_insert"]) + async def test_get_one( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.get_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_) + + assert result is not None + + assert isinstance(result, models.TestSqliteType) + + assert result == model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::get_one_none", depends=["AiosqliteTestPydanticFunctions::get_one"]) + async def test_get_one_none( + self, + aiosqlite_conn: aiosqlite.Connection, + ) -> None: + result = await queries.get_one_sqlite_type(conn=aiosqlite_conn, id_=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::get_one_inner", depends=["AiosqliteTestPydanticFunctions::get_one_none"]) + async def test_get_one_inner( + self, + aiosqlite_conn: aiosqlite.Connection, + inner_model: models.TestInnerSqliteType, + ) -> None: + result = await queries.get_one_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id) + + assert result is not None + + assert isinstance(result, models.TestInnerSqliteType) + assert result == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_one_inner_none", + depends=["AiosqliteTestPydanticFunctions::get_one_inner"], + ) + async def test_get_one_inner_none( + self, + aiosqlite_conn: aiosqlite.Connection, + ) -> None: + result = await queries.get_one_inner_sqlite_type(conn=aiosqlite_conn, table_id=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_date", + depends=["AiosqliteTestPydanticFunctions::get_one_inner_none"], + ) + async def test_get_date( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.get_one_date(conn=aiosqlite_conn, id_=model.id_, date_test=model.date_test) + + assert result is not None + + assert isinstance(result, datetime.date) + assert result == model.date_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::get_date_none", depends=["AiosqliteTestPydanticFunctions::get_date"]) + async def test_get_date_none( + self, + aiosqlite_conn: aiosqlite.Connection, + ) -> None: + result = await queries.get_one_date(conn=aiosqlite_conn, id_=0, date_test=datetime.date.today()) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::get_datetime", depends=["AiosqliteTestPydanticFunctions::get_date_none"]) + async def test_get_datetime( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.get_one_datetime(conn=aiosqlite_conn, id_=model.id_, datetime_test=model.datetime_test) + + assert result is not None + + assert isinstance(result, datetime.datetime) + assert result == model.datetime_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_datetime_none", + depends=["AiosqliteTestPydanticFunctions::get_datetime"], + ) + async def test_get_datetime_none( + self, + aiosqlite_conn: aiosqlite.Connection, + ) -> None: + result = await queries.get_one_datetime(conn=aiosqlite_conn, id_=0, datetime_test=datetime.datetime.now()) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_timestamp", + depends=["AiosqliteTestPydanticFunctions::get_datetime_none"], + ) + async def test_get_timestamp( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.get_one_timestamp(conn=aiosqlite_conn, id_=model.id_, timestamp_test=model.timestamp_test) + + assert result is not None + + assert isinstance(result, datetime.datetime) + assert result == model.timestamp_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_timestamp_none", + depends=["AiosqliteTestPydanticFunctions::get_timestamp"], + ) + async def test_get_timestamp_none( + self, + aiosqlite_conn: aiosqlite.Connection, + ) -> None: + result = await queries.get_one_timestamp(conn=aiosqlite_conn, id_=0, timestamp_test=datetime.datetime.now()) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_bool", + depends=["AiosqliteTestPydanticFunctions::get_timestamp_none"], + ) + async def test_get_bool( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.get_one_bool(conn=aiosqlite_conn, id_=model.id_, bool_test=model.bool_test) + + assert result is not None + + assert isinstance(result, bool) + assert result == model.bool_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::get_bool_none", depends=["AiosqliteTestPydanticFunctions::get_bool"]) + async def test_get_bool_none( + self, + aiosqlite_conn: aiosqlite.Connection, + ) -> None: + result = await queries.get_one_bool(conn=aiosqlite_conn, id_=0, bool_test=False) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::get_boolean", depends=["AiosqliteTestPydanticFunctions::get_bool_none"]) + async def test_get_boolean( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.get_one_boolean(conn=aiosqlite_conn, id_=model.id_, boolean_test=model.boolean_test) + + assert result is not None + + assert isinstance(result, bool) + assert result == model.boolean_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_boolean_none", + depends=["AiosqliteTestPydanticFunctions::get_boolean"], + ) + async def test_get_boolean_none( + self, + aiosqlite_conn: aiosqlite.Connection, + ) -> None: + result = await queries.get_one_boolean(conn=aiosqlite_conn, id_=0, boolean_test=True) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_decimal", + depends=["AiosqliteTestPydanticFunctions::get_boolean_none"], + ) + async def test_get_decimal( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.get_one_decimal(conn=aiosqlite_conn, id_=model.id_, decimal_test=model.decimal_test) + + assert result is not None + + assert isinstance(result, decimal.Decimal) + assert result == model.decimal_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_decimal_none", + depends=["AiosqliteTestPydanticFunctions::get_decimal"], + ) + async def test_get_decimal_none( + self, + aiosqlite_conn: aiosqlite.Connection, + ) -> None: + result = await queries.get_one_decimal(conn=aiosqlite_conn, id_=0, decimal_test=decimal.Decimal("0.1")) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::get_blob", depends=["AiosqliteTestPydanticFunctions::get_decimal_none"]) + async def test_get_blob( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.get_one_blob(conn=aiosqlite_conn, id_=model.id_, blob_test=model.blob_test) + + assert result is not None + + assert isinstance(result, memoryview) + assert result == model.blob_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::get_blob_none", depends=["AiosqliteTestPydanticFunctions::get_blob"]) + async def test_get_blob_none( + self, + aiosqlite_conn: aiosqlite.Connection, + ) -> None: + result = await queries.get_one_blob(conn=aiosqlite_conn, id_=0, blob_test=memoryview(b"test")) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::get_many", depends=["AiosqliteTestPydanticFunctions::get_blob_none"]) + async def test_get_many(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + result = await queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id_) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], models.TestSqliteType) + + assert result[0] == model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::get_many_iter", depends=["AiosqliteTestPydanticFunctions::get_many"]) + async def test_get_many_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_sqlite_type(conn=aiosqlite_conn, id_=model.id_): + assert result is not None + assert isinstance(result, models.TestSqliteType) + + assert result == model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_inner", + depends=["AiosqliteTestPydanticFunctions::get_many_iter"], + ) + async def test_get_many_inner(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: + result = await queries.get_many_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], models.TestInnerSqliteType) + + assert result[0] == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_inner_iter", + depends=["AiosqliteTestPydanticFunctions::get_many_inner"], + ) + async def test_get_many_inner_iter(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: + async for result in queries.get_many_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id): + assert result is not None + assert isinstance(result, models.TestInnerSqliteType) + + assert result == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_nullable_inner", + depends=["AiosqliteTestPydanticFunctions::get_many_inner_iter"], + ) + async def test_get_many_nullable_inner(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: + result = await queries.get_many_nullable_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], models.TestInnerSqliteType) + + assert result[0] == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_nullable_inner_iter", + depends=["AiosqliteTestPydanticFunctions::get_many_nullable_inner"], + ) + async def test_get_many_nullable_inner_iter(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: + async for result in queries.get_many_nullable_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id, int_test=inner_model.int_test): + assert result is not None + assert isinstance(result, models.TestInnerSqliteType) + + assert result == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_date", + depends=["AiosqliteTestPydanticFunctions::get_many_nullable_inner_iter"], + ) + async def test_get_many_date(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + result = await queries.get_many_date(conn=aiosqlite_conn, id_=model.id_, date_test=model.date_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], datetime.date) + + assert result[0] == model.date_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_date_iter", + depends=["AiosqliteTestPydanticFunctions::get_many_date"], + ) + async def test_get_many_date_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_date(conn=aiosqlite_conn, id_=model.id_, date_test=model.date_test): + assert result is not None + assert isinstance(result, datetime.date) + + assert result == model.date_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_datetime", + depends=["AiosqliteTestPydanticFunctions::get_many_date_iter"], + ) + async def test_get_many_datetime(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + result = await queries.get_many_datetime(conn=aiosqlite_conn, id_=model.id_, datetime_test=model.datetime_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], datetime.datetime) + + assert result[0] == model.datetime_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_datetime_iter", + depends=["AiosqliteTestPydanticFunctions::get_many_datetime"], + ) + async def test_get_many_datetime_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_datetime(conn=aiosqlite_conn, id_=model.id_, datetime_test=model.datetime_test): + assert result is not None + assert isinstance(result, datetime.datetime) + + assert result == model.datetime_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_timestamp", + depends=["AiosqliteTestPydanticFunctions::get_many_datetime_iter"], + ) + async def test_get_many_timestamp(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + result = await queries.get_many_timestamp(conn=aiosqlite_conn, id_=model.id_, timestamp_test=model.timestamp_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], datetime.datetime) + + assert result[0] == model.timestamp_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_timestamp_iter", + depends=["AiosqliteTestPydanticFunctions::get_many_timestamp"], + ) + async def test_get_many_timestamp_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_timestamp(conn=aiosqlite_conn, id_=model.id_, timestamp_test=model.timestamp_test): + assert result is not None + assert isinstance(result, datetime.datetime) + + assert result == model.timestamp_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_bool", + depends=["AiosqliteTestPydanticFunctions::get_many_timestamp_iter"], + ) + async def test_get_many_bool(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + result = await queries.get_many_bool(conn=aiosqlite_conn, id_=model.id_, bool_test=model.bool_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], bool) + + assert result[0] == model.bool_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_bool_iter", + depends=["AiosqliteTestPydanticFunctions::get_many_bool"], + ) + async def test_get_many_bool_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_bool(conn=aiosqlite_conn, id_=model.id_, bool_test=model.bool_test): + assert result is not None + assert isinstance(result, bool) + + assert result == model.bool_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_boolean", + depends=["AiosqliteTestPydanticFunctions::get_many_bool_iter"], + ) + async def test_get_many_boolean(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + result = await queries.get_many_boolean(conn=aiosqlite_conn, id_=model.id_, boolean_test=model.boolean_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], bool) + + assert result[0] == model.boolean_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_boolean_iter", + depends=["AiosqliteTestPydanticFunctions::get_many_boolean"], + ) + async def test_get_many_boolean_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_boolean(conn=aiosqlite_conn, id_=model.id_, boolean_test=model.boolean_test): + assert result is not None + assert isinstance(result, bool) + + assert result == model.boolean_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_decimal", + depends=["AiosqliteTestPydanticFunctions::get_many_boolean_iter"], + ) + async def test_get_many_decimal(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + result = await queries.get_many_decimal(conn=aiosqlite_conn, id_=model.id_, decimal_test=model.decimal_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], decimal.Decimal) + + assert result[0] == model.decimal_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_decimal_iter", + depends=["AiosqliteTestPydanticFunctions::get_many_decimal"], + ) + async def test_get_many_decimal_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_decimal(conn=aiosqlite_conn, id_=model.id_, decimal_test=model.decimal_test): + assert result is not None + assert isinstance(result, decimal.Decimal) + + assert result == model.decimal_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_blob", + depends=["AiosqliteTestPydanticFunctions::get_many_decimal_iter"], + ) + async def test_get_many_blob(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + result = await queries.get_many_blob(conn=aiosqlite_conn, id_=model.id_, blob_test=model.blob_test) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], memoryview) + + assert result[0] == model.blob_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_blob_iter", + depends=["AiosqliteTestPydanticFunctions::get_many_blob"], + ) + async def test_get_many_blob_iter(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + async for result in queries.get_many_blob(conn=aiosqlite_conn, id_=model.id_, blob_test=model.blob_test): + assert result is not None + assert isinstance(result, memoryview) + + assert result == model.blob_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::insert_result", + depends=["AiosqliteTestPydanticFunctions::get_many_blob_iter"], + ) + async def test_insert_result( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.insert_result_one_sqlite_type( + conn=aiosqlite_conn, + id_=model.id_ + 1, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + assert isinstance(result, aiosqlite.Cursor) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::update_result", + depends=["AiosqliteTestPydanticFunctions::insert_result"], + ) + async def test_update_result( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.update_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 1) + assert isinstance(result, aiosqlite.Cursor) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::delete_result", + depends=["AiosqliteTestPydanticFunctions::update_result"], + ) + async def test_delete_result( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.delete_result_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 1) + assert isinstance(result, aiosqlite.Cursor) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::insert_rows", depends=["AiosqliteTestPydanticFunctions::delete_result"]) + async def test_insert_rows( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.insert_rows_one_sqlite_type( + conn=aiosqlite_conn, + id_=model.id_ + 2, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + assert isinstance(result, int) + assert result == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::update_rows", depends=["AiosqliteTestPydanticFunctions::insert_rows"]) + async def test_update_rows( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.update_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 2) + assert isinstance(result, int) + assert result == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="AiosqliteTestPydanticFunctions::delete_rows", depends=["AiosqliteTestPydanticFunctions::update_rows"]) + async def test_delete_rows( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.delete_rows_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 2) + assert isinstance(result, int) + assert result == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::create_table_rows", + depends=["AiosqliteTestPydanticFunctions::delete_rows"], + ) + async def test_create_table_rows( + self, + aiosqlite_conn: aiosqlite.Connection, + ) -> None: + result = await queries.create_rows_table(conn=aiosqlite_conn) + assert isinstance(result, int) + await aiosqlite_conn.execute("DROP TABLE test_create_rows_table;") + await aiosqlite_conn.commit() + assert result == -1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::insert_last_id", + depends=["AiosqliteTestPydanticFunctions::create_table_rows"], + ) + async def test_insert_last_id( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.insert_last_id_one_sqlite_type( + conn=aiosqlite_conn, + id_=model.id_ + 3, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + assert isinstance(result, int) + assert result == model.id_ + 3 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::update_last_id", + depends=["AiosqliteTestPydanticFunctions::insert_last_id"], + ) + async def test_update_last_id( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.update_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 3) + assert isinstance(result, int) + assert result == model.id_ + 3 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::delete_last_id", + depends=["AiosqliteTestPydanticFunctions::update_last_id"], + ) + async def test_delete_last_id( + self, + aiosqlite_conn: aiosqlite.Connection, + model: models.TestSqliteType, + ) -> None: + result = await queries.delete_last_id_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_ + 3) + assert isinstance(result, int) + assert result == model.id_ + 3 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::delete_sqlite_type", + depends=["AiosqliteTestPydanticFunctions::delete_last_id"], + ) + async def test_delete_sqlite_type(self, aiosqlite_conn: aiosqlite.Connection, model: models.TestSqliteType) -> None: + await queries.delete_one_sqlite_type(conn=aiosqlite_conn, id_=model.id_) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::delete_inner_sqlite_type", + depends=["AiosqliteTestPydanticFunctions::delete_sqlite_type"], + ) + async def test_delete_inner_sqlite_type(self, aiosqlite_conn: aiosqlite.Connection, inner_model: models.TestInnerSqliteType) -> None: + await queries.delete_one_test_inner_sqlite_type(conn=aiosqlite_conn, table_id=inner_model.table_id) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::insert_type_override", + ) + async def test_insert_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + await queries.insert_type_override(conn=aiosqlite_conn, id_=override_model.id_, text_test=override_model.text_test) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_one_type_override", + depends=["AiosqliteTestPydanticFunctions::insert_type_override"], + ) + async def test_get_one_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id_) + assert result is not None + assert result == override_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_one_type_override_none", + depends=["AiosqliteTestPydanticFunctions::get_one_type_override"], + ) + async def test_get_one_type_override_none(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=aiosqlite_conn, id_=override_model.id_ - 1) + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_type_override", + depends=["AiosqliteTestPydanticFunctions::get_one_type_override_none"], + ) + async def test_get_many_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_type_override(conn=aiosqlite_conn, id_=override_model.id_) + assert isinstance(result, collections.abc.Sequence) + assert result[0] == override_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_one_text_type_override", + depends=["AiosqliteTestPydanticFunctions::get_many_type_override"], + ) + async def test_get_one_text_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id_) + assert result is not None + assert result == override_model.text_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_one_text_type_override_none", + depends=["AiosqliteTestPydanticFunctions::get_one_text_type_override"], + ) + async def test_get_one_text_type_override_none(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=aiosqlite_conn, id_=override_model.id_ - 1) + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::get_many_text_type_override", + depends=["AiosqliteTestPydanticFunctions::get_one_text_type_override_none"], + ) + async def test_get_many_text_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_text_type_override(conn=aiosqlite_conn, id_=override_model.id_) + assert isinstance(result, collections.abc.Sequence) + assert result[0] == override_model.text_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="AiosqliteTestPydanticFunctions::delete_type_override", + depends=["AiosqliteTestPydanticFunctions::get_many_text_type_override"], + ) + async def test_delete_type_override(self, aiosqlite_conn: aiosqlite.Connection, override_model: models.TestTypeOverride) -> None: + await queries.delete_type_override(conn=aiosqlite_conn, id_=override_model.id_) diff --git a/test/driver_aiosqlite/schema.sql b/test/driver_aiosqlite/schema.sql index bf423e35..3f101cac 100644 --- a/test/driver_aiosqlite/schema.sql +++ b/test/driver_aiosqlite/schema.sql @@ -1,32 +1,32 @@ CREATE TABLE IF NOT EXISTS test_sqlite_types ( - /* ───────────── Integer family ───────────── */ + /* ------------- Integer family ------------- */ id integer PRIMARY KEY NOT NULL, - int_test int NOT NULL, -- covers integer / mediumint … - bigint_test bigint NOT NULL, -- covers unsignedbigint … + int_test int NOT NULL, -- covers integer / mediumint ... + bigint_test bigint NOT NULL, -- covers unsignedbigint ... smallint_test smallint NOT NULL, tinyint_test tinyint NOT NULL, int2_test int2 NOT NULL, int8_test int8 NOT NULL, bigserial_test bigserial NOT NULL, - /* ───────────── Binary (blob) ───────────── */ + /* ------------- Binary (blob) ------------- */ blob_test blob NOT NULL, - /* ───────────── Floating-point / numeric ───────────── */ + /* ------------- Floating-point / numeric ------------- */ real_test real NOT NULL, double_test double NOT NULL, double_precision_test double precision NOT NULL, float_test float NOT NULL, numeric_test numeric NOT NULL, - /* ───────────── Exact numeric (decimal) ───────────── */ + /* ------------- Exact numeric (decimal) ------------- */ decimal_test decimal NOT NULL, - /* ───────────── Boolean ───────────── */ + /* ------------- Boolean ------------- */ boolean_test boolean NOT NULL, bool_test bool NOT NULL, - /* ───────────── Date & time ───────────── */ + /* ------------- Date & time ------------- */ date_test date NOT NULL, datetime_test datetime NOT NULL, timestamp_test timestamp NOT NULL, - /* ───────────── Character / text ───────────── */ + /* ------------- Character / text ------------- */ character_test character(10) NOT NULL, varchar_test varchar(255) NOT NULL, varyingcharacter_test varyingcharacter (255) NOT NULL, @@ -40,33 +40,33 @@ CREATE TABLE IF NOT EXISTS test_sqlite_types -- split CREATE TABLE IF NOT EXISTS test_inner_sqlite_types ( - /* ───────────── Integer family ───────────── */ + /* ------------- Integer family ------------- */ table_id integer PRIMARY KEY NOT NULL, - int_test int , -- covers integer / mediumint … - bigint_test bigint , -- covers unsignedbigint … + int_test int , -- covers integer / mediumint ... + bigint_test bigint , -- covers unsignedbigint ... smallint_test smallint , tinyint_test tinyint , int2_test int2 , int8_test int8 , bigserial_test bigserial , - /* ───────────── Binary (blob) ───────────── */ + /* ------------- Binary (blob) ------------- */ blob_test blob , - /* ───────────── Floating-point / numeric ───────────── */ + /* ------------- Floating-point / numeric ------------- */ real_test real , double_test double , double_precision_test double precision , float_test float , numeric_test numeric , - /* ───────────── Exact numeric (decimal) ───────────── */ + /* ------------- Exact numeric (decimal) ------------- */ decimal_test decimal , - /* ───────────── Boolean ───────────── */ + /* ------------- Boolean ------------- */ boolean_test boolean , bool_test bool , - /* ───────────── Date & time ───────────── */ + /* ------------- Date & time ------------- */ date_test date , datetime_test datetime , timestamp_test timestamp , - /* ───────────── Character / text ───────────── */ + /* ------------- Character / text ------------- */ character_test character(10) , varchar_test varchar(255) , varyingcharacter_test varyingcharacter (255) , diff --git a/test/driver_aiosqlite/sqlc-gen-better-python.wasm b/test/driver_aiosqlite/sqlc-gen-better-python.wasm index 56caaa4b..a0a8faab 100644 Binary files a/test/driver_aiosqlite/sqlc-gen-better-python.wasm and b/test/driver_aiosqlite/sqlc-gen-better-python.wasm differ diff --git a/test/driver_aiosqlite/sqlc.yaml b/test/driver_aiosqlite/sqlc.yaml index 157a0463..d4a616da 100644 --- a/test/driver_aiosqlite/sqlc.yaml +++ b/test/driver_aiosqlite/sqlc.yaml @@ -3,7 +3,7 @@ plugins: - name: python wasm: url: file://sqlc-gen-better-python.wasm - sha256: ee7bd0c07b784b80ea8c5853d9a6a04c51a7abbfd2663f470e9a5d2f623b967e + sha256: 0d564b87865b4733c9a41bd318277973c130fc02c32b5bfdb2a0b662f36148da sql: - schema: schema.sql queries: queries.sql @@ -129,3 +129,45 @@ sql: package: UserString type: UserString + - schema: schema.sql + queries: queries.sql + engine: sqlite + codegen: + - out: /pydantic/classes + plugin: python + options: + package: test.driver_aiosqlite.pydantic.classes + sql_driver: aiosqlite + model_type: pydantic + emit_classes: true + omit_unused_models: true + emit_init_file: true + docstrings: google + overrides: + - column: test_type_override.text_test + py_type: + import: collections + package: UserString + type: UserString + - schema: schema.sql + queries: queries.sql + engine: sqlite + codegen: + - out: /pydantic/functions + plugin: python + options: + package: test.driver_aiosqlite.pydantic.functions + sql_driver: aiosqlite + model_type: pydantic + emit_classes: false + omit_unused_models: true + emit_init_file: true + docstrings: google + + overrides: + - column: test_type_override.text_test + py_type: + import: collections + package: UserString + type: UserString + diff --git a/test/driver_asyncpg/attrs/classes/__init__.py b/test/driver_asyncpg/attrs/classes/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_asyncpg/attrs/classes/__init__.py +++ b/test/driver_asyncpg/attrs/classes/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_asyncpg/attrs/classes/enums.py b/test/driver_asyncpg/attrs/classes/enums.py new file mode 100644 index 00000000..d49ac611 --- /dev/null +++ b/test/driver_asyncpg/attrs/classes/enums.py @@ -0,0 +1,23 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing enums.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("TestMood",) + +import enum +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +class TestMood(enum.StrEnum): + """Enum representing TestMood.""" + + SAD = "sad" + OK = "ok" + HAPPY = "happy" diff --git a/test/driver_asyncpg/attrs/classes/models.py b/test/driver_asyncpg/attrs/classes/models.py index 3c99c99c..72e67f93 100644 --- a/test/driver_asyncpg/attrs/classes/models.py +++ b/test/driver_asyncpg/attrs/classes/models.py @@ -1,11 +1,14 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( + "TestEnumOverride", + "TestEnumType", "TestInnerPostgresType", "TestPostgresType", "TestTypeOverride", @@ -16,12 +19,45 @@ if typing.TYPE_CHECKING: from collections import UserString + from test.driver_asyncpg.attrs.classes import enums import collections.abc import datetime import decimal import uuid +@attrs.define() +class TestEnumOverride: + """Model representing TestEnumOverride. + + Attributes + ---------- + id_ : int + mood_test : str + + """ + + id_: int + mood_test: str + + +@attrs.define() +class TestEnumType: + """Model representing TestEnumType. + + Attributes + ---------- + id_ : int + mood : enums.TestMood + maybe_mood : enums.TestMood | None + + """ + + id_: int + mood: enums.TestMood + maybe_mood: enums.TestMood | None + + @attrs.define() class TestInnerPostgresType: """Model representing TestInnerPostgresType. @@ -111,7 +147,7 @@ class TestPostgresType: Attributes ---------- - id : int + id_ : int serial_test : int serial4_test : int bigserial_test : int @@ -150,7 +186,7 @@ class TestPostgresType: """ - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -194,10 +230,10 @@ class TestTypeOverride: Attributes ---------- - id : int + id_ : int text_test : UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_asyncpg/attrs/classes/queries.py b/test/driver_asyncpg/attrs/classes/queries.py index 7332b465..b609dedb 100644 --- a/test/driver_asyncpg/attrs/classes/queries.py +++ b/test/driver_asyncpg/attrs/classes/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -15,7 +17,6 @@ from collections import UserString import attrs -import datetime import operator import typing @@ -23,38 +24,25 @@ import asyncpg import asyncpg.cursor import collections.abc + import datetime import decimal import uuid - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None - ConnectionLike: typing.TypeAlias = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] +from test.driver_asyncpg.attrs.classes import enums from test.driver_asyncpg.attrs.classes import models -@attrs.define() -class GetAllEmbeddedTestPostgresTypeRow: - """Model representing GetAllEmbeddedTestPostgresTypeRow. - - Attributes - ---------- - test_postgres_type : models.TestPostgresType - test_inner_postgres_type : models.TestInnerPostgresType - - """ - - test_postgres_type: models.TestPostgresType - test_inner_postgres_type: models.TestInnerPostgresType - - @attrs.define() class GetEmbeddedTestPostgresTypeRow: """Model representing GetEmbeddedTestPostgresTypeRow. Attributes ---------- - id : int + id_ : int serial_test : int serial4_test : int bigserial_test : int @@ -94,7 +82,7 @@ class GetEmbeddedTestPostgresTypeRow: """ - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -133,65 +121,98 @@ class GetEmbeddedTestPostgresTypeRow: test_inner_postgres_type: models.TestInnerPostgresType +@attrs.define() +class GetAllEmbeddedTestPostgresTypeRow: + """Model representing GetAllEmbeddedTestPostgresTypeRow. + + Attributes + ---------- + test_postgres_type : models.TestPostgresType + test_inner_postgres_type : models.TestInnerPostgresType + + """ + + test_postgres_type: models.TestPostgresType + test_inner_postgres_type: models.TestInnerPostgresType + + @attrs.define() class TestCopyFromParams: """Model representing TestCopyFromParams. Attributes ---------- - id : int + id_ : int float_test : float int_test : int """ - id: int + id_: int float_test: float int_test: int -CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec -INSERT INTO test_inner_postgres_types (table_id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) -VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) +GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one +SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_inner_postgres_types +WHERE table_id = $1 LIMIT 1 +""" + +GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 +""" + +GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 """ CREATE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresType :exec @@ -238,6 +259,62 @@ class TestCopyFromParams: $33, $34, $35, $36) """ +CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec +INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec +DELETE +FROM test_inner_postgres_types +WHERE test_inner_postgres_types.table_id = $1 +""" + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateResultOneTestPostgresType :execresult INSERT INTO test_postgres_types (id, serial_test, @@ -282,6 +359,18 @@ class TestCopyFromParams: $33, $34, $35, $36) """ +UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateRowsOneTestPostgresType :execrows INSERT INTO test_postgres_types (id, serial_test, @@ -326,6 +415,18 @@ class TestCopyFromParams: $33, $34, $35, $36) """ +UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows CREATE TABLE test_create_rows_table ( @@ -334,28 +435,32 @@ class TestCopyFromParams: ) """ -DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom +INSERT INTO test_copy_from (id, + float_test, int_test) +VALUES ($1, $2, $3) """ -DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec +INSERT INTO test_type_override ( + id, text_test +) VALUES ($1 ,$2) """ -DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec -DELETE -FROM test_inner_postgres_types -WHERE test_inner_postgres_types.table_id = $1 +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = $1 """ -DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 """ DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec @@ -364,113 +469,37 @@ class TestCopyFromParams: WHERE test_type_override.id = $1 """ -GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one -SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id -WHERE test_postgres_types.id = $1 +INSERT_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: InsertOneTestEnumType :exec +INSERT INTO test_enum_types (id, mood, maybe_mood) +VALUES ($1, $2, $3) """ -GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one -SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id -WHERE test_postgres_types.id = $1 -""" - -GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many -SELECT bytea_test -FROM test_postgres_types -WHERE id = $1 LIMIT 2 -""" - -GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types +GET_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: GetOneTestEnumType :one +SELECT id, mood, maybe_mood +FROM test_enum_types WHERE id = $1 """ -GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types +GET_ONE_TEST_ENUM_VALUE: typing.Final[str] = """-- name: GetOneTestEnumValue :one +SELECT mood +FROM test_enum_types WHERE id = $1 """ -GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many -SELECT timestamp_test -FROM test_postgres_types -WHERE id = $1 LIMIT 2 -""" - -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 +GET_MANY_TEST_ENUM_TYPES: typing.Final[str] = """-- name: GetManyTestEnumTypes :many +SELECT id, mood, maybe_mood +FROM test_enum_types +ORDER BY id """ -GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one -SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_inner_postgres_types -WHERE table_id = $1 LIMIT 1 -""" - -GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one -SELECT bytea_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one -SELECT timestamp_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = $1 -""" - -INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec -INSERT INTO test_type_override ( - id, text_test -) VALUES ($1 ,$2) -""" - -TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom -INSERT INTO test_copy_from (id, - float_test, int_test) -VALUES ($1, $2, $3) -""" - -UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult -UPDATE test_postgres_types -SET serial_test = 187 -WHERE test_postgres_types.id = $1 -""" - -UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows -UPDATE test_postgres_types -SET serial_test = 187 -WHERE test_postgres_types.id = $1 +DELETE_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: DeleteOneTestEnumType :execrows +DELETE +FROM test_enum_types +WHERE id = $1 """ -T = typing.TypeVar("T") - - -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db. Parameters @@ -523,9 +552,11 @@ def __await__( collections.abc.Sequence[T] A sequence of decoded objects of type `T`. """ + async def _wrapper() -> collections.abc.Sequence[T]: result = await self._conn.fetch(self._sql, *self._args) return [self._decode_hook(row) for row in result] + return _wrapper().__await__() async def __anext__(self) -> T: @@ -580,7 +611,754 @@ def conn(self) -> ConnectionLike: """ return self._conn - async def create_one_test_postgres_inner_type(self, *, table_id: int, serial_test: int | None, serial4_test: int | None, bigserial_test: int | None, smallserial_test: int | None, int_test: int | None, bigint_test: int | None, smallint_test: int | None, float_test: float | None, double_precision_test: float | None, real_test: float | None, numeric_test: decimal.Decimal | None, money_test: str | None, bool_test: bool | None, json_test: str | None, jsonb_test: str | None, bytea_test: memoryview | None, date_test: datetime.date | None, time_test: datetime.time | None, timetz_test: datetime.time | None, timestamp_test: datetime.datetime | None, timestamptz_test: datetime.datetime | None, interval_test: datetime.timedelta | None, text_test: str | None, varchar_test: str | None, bpchar_test: str | None, char_test: str | None, citext_test: str | None, uuid_test: uuid.UUID | None, inet_test: str | None, cidr_test: str | None, macaddr_test: str | None, macaddr8_test: str | None, ltree_test: str | None, lquery_test: str | None, ltxtquery_test: str | None) -> None: + async def get_one_test_postgres_type(self, *, id_: int) -> models.TestPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + models.TestPostgresType + Result fetched from the db. Will be `None` if not found. + + """ + row = await self._conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + async def get_one_inner_test_postgres_type(self, *, table_id: int) -> models.TestInnerPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + + ```sql + SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_inner_postgres_types + WHERE table_id = $1 LIMIT 1 + ``` + + Parameters + ---------- + table_id : int + + Returns + ------- + models.TestInnerPostgresType + Result fetched from the db. Will be `None` if not found. + + """ + row = await self._conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + if row is None: + return None + return models.TestInnerPostgresType( + table_id=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]) if row[16] is not None else None, + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]) if row[29] is not None else None, + cidr_test=str(row[30]) if row[30] is not None else None, + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + async def get_one_test_timestamp_postgres_type(self, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. + + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + datetime.datetime + Result fetched from the db. Will be `None` if not found. + + """ + row = await self._conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) + if row is None: + return None + return row[0] + + async def get_one_test_bytea_postgres_type(self, *, id_: int) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + memoryview + Result fetched from the db. Will be `None` if not found. + + """ + row = await self._conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) + if row is None: + return None + return memoryview(row[0]) + + def get_many_test_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + QueryResults[models.TestPostgresType] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(self._conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + + def get_many_test_iterator_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + QueryResults[models.TestPostgresType] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(self._conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) + + def get_many_test_timestamp_postgres_type(self, *, id_: int) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. + + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + QueryResults[datetime.datetime] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + return QueryResults(self._conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + + def get_many_test_bytea_postgres_type(self, *, id_: int) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + QueryResults[memoryview] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: asyncpg.Record) -> memoryview: + return memoryview(row[0]) + + return QueryResults(self._conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + + async def get_embedded_test_postgres_type(self, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + GetEmbeddedTestPostgresTypeRow + Result fetched from the db. Will be `None` if not found. + + """ + row = await self._conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetEmbeddedTestPostgresTypeRow( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + async def get_all_embedded_test_postgres_type(self, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + GetAllEmbeddedTestPostgresTypeRow + Result fetched from the db. Will be `None` if not found. + + """ + row = await self._conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetAllEmbeddedTestPostgresTypeRow( + test_postgres_type=models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ), + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + async def create_one_test_postgres_type( + self, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, + ) -> None: + """Execute SQL query with `name: CreateOneTestPostgresType :exec`. + + ```sql + INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Parameters + ---------- + id_ : int + serial_test : int + serial4_test : int + bigserial_test : int + smallserial_test : int + int_test : int + bigint_test : int + smallint_test : int + float_test : float + double_precision_test : float + real_test : float + numeric_test : decimal.Decimal + money_test : str + bool_test : bool + json_test : str + jsonb_test : str + bytea_test : memoryview + date_test : datetime.date + time_test : datetime.time + timetz_test : datetime.time + timestamp_test : datetime.datetime + timestamptz_test : datetime.datetime + interval_test : datetime.timedelta + text_test : str + varchar_test : str + bpchar_test : str + char_test : str + citext_test : str + uuid_test : uuid.UUID + inet_test : str + cidr_test : str + macaddr_test : str + macaddr8_test : str + ltree_test : str + lquery_test : str + ltxtquery_test : str + + """ + await self._conn.execute( + CREATE_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + async def create_one_test_postgres_inner_type( + self, + *, + table_id: int, + serial_test: int | None, + serial4_test: int | None, + bigserial_test: int | None, + smallserial_test: int | None, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + float_test: float | None, + double_precision_test: float | None, + real_test: float | None, + numeric_test: decimal.Decimal | None, + money_test: str | None, + bool_test: bool | None, + json_test: str | None, + jsonb_test: str | None, + bytea_test: memoryview | None, + date_test: datetime.date | None, + time_test: datetime.time | None, + timetz_test: datetime.time | None, + timestamp_test: datetime.datetime | None, + timestamptz_test: datetime.datetime | None, + interval_test: datetime.timedelta | None, + text_test: str | None, + varchar_test: str | None, + bpchar_test: str | None, + char_test: str | None, + citext_test: str | None, + uuid_test: uuid.UUID | None, + inet_test: str | None, + cidr_test: str | None, + macaddr_test: str | None, + macaddr8_test: str | None, + ltree_test: str | None, + lquery_test: str | None, + ltxtquery_test: str | None, + ) -> None: """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. ```sql @@ -663,102 +1441,122 @@ async def create_one_test_postgres_inner_type(self, *, table_id: int, serial_tes macaddr_test : str | None macaddr8_test : str | None ltree_test : str | None - lquery_test : str | None - ltxtquery_test : str | None - - """ - await self._conn.execute(CREATE_ONE_TEST_POSTGRES_INNER_TYPE, table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) - - async def create_one_test_postgres_type(self, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> None: - """Execute SQL query with `name: CreateOneTestPostgresType :exec`. - - ```sql - INSERT INTO test_postgres_types (id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) + lquery_test : str | None + ltxtquery_test : str | None + + """ + await self._conn.execute( + CREATE_ONE_TEST_POSTGRES_INNER_TYPE, + table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + async def delete_one_test_postgres_type(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 ``` Parameters ---------- id_ : int - serial_test : int - serial4_test : int - bigserial_test : int - smallserial_test : int - int_test : int - bigint_test : int - smallint_test : int - float_test : float - double_precision_test : float - real_test : float - numeric_test : decimal.Decimal - money_test : str - bool_test : bool - json_test : str - jsonb_test : str - bytea_test : memoryview - date_test : datetime.date - time_test : datetime.time - timetz_test : datetime.time - timestamp_test : datetime.datetime - timestamptz_test : datetime.datetime - interval_test : datetime.timedelta - text_test : str - varchar_test : str - bpchar_test : str - char_test : str - citext_test : str - uuid_test : uuid.UUID - inet_test : str - cidr_test : str - macaddr_test : str - macaddr8_test : str - ltree_test : str - lquery_test : str - ltxtquery_test : str """ - await self._conn.execute(CREATE_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + await self._conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) + + async def delete_one_test_postgres_inner_type(self, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. + + ```sql + DELETE + FROM test_inner_postgres_types + WHERE test_inner_postgres_types.table_id = $1 + ``` + + Parameters + ---------- + table_id : int + + """ + await self._conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) - async def create_result_one_test_postgres_type(self, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> str: + async def create_result_one_test_postgres_type( + self, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, + ) -> str: """Execute and return the result of SQL query with `name: CreateResultOneTestPostgresType :execresult`. ```sql @@ -850,9 +1648,128 @@ async def create_result_one_test_postgres_type(self, *, id_: int, serial_test: i The result returned when executing the query. """ - return await self._conn.execute(CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + return await self._conn.execute( + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + async def update_result_test_postgres_type(self, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. + + ```sql + UPDATE test_postgres_types + SET serial_test = 187 + WHERE test_postgres_types.id = $1 + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + str + The result returned when executing the query. + + """ + return await self._conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) + + async def delete_one_result_test_postgres_type(self, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + str + The result returned when executing the query. + + """ + return await self._conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) - async def create_rows_one_test_postgres_type(self, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> int: + async def create_rows_one_test_postgres_type( + self, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, + ) -> int: """Execute SQL query with `name: CreateRowsOneTestPostgresType :execrows` and return the number of affected rows. ```sql @@ -924,172 +1841,73 @@ async def create_rows_one_test_postgres_type(self, *, id_: int, serial_test: int timestamp_test : datetime.datetime timestamptz_test : datetime.datetime interval_test : datetime.timedelta - text_test : str - varchar_test : str - bpchar_test : str - char_test : str - citext_test : str - uuid_test : uuid.UUID - inet_test : str - cidr_test : str - macaddr_test : str - macaddr8_test : str - ltree_test : str - lquery_test : str - ltxtquery_test : str - - Returns - ------- - int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - - """ - r = await self._conn.execute(CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) - return int(n) if (n := r.split()[-1]).isdigit() else 0 - - async def create_rows_table(self) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. - - ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Returns - ------- - int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - - """ - r = await self._conn.execute(CREATE_ROWS_TABLE) - return int(n) if (n := r.split()[-1]).isdigit() else 0 - - async def delete_one_result_test_postgres_type(self, *, id_: int) -> str: - """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. - - ```sql - DELETE - FROM test_postgres_types - WHERE test_postgres_types.id = $1 - ``` - - Parameters - ---------- - id_ : int - - Returns - ------- - str - The result returned when executing the query. - - """ - return await self._conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) - - async def delete_one_rows_test_postgres_type(self, *, id_: int) -> int: - """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. - - ```sql - DELETE - FROM test_postgres_types - WHERE test_postgres_types.id = $1 - ``` - - Parameters - ---------- - id_ : int - - Returns - ------- - int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - - """ - r = await self._conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) - return int(n) if (n := r.split()[-1]).isdigit() else 0 - - async def delete_one_test_postgres_inner_type(self, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. - - ```sql - DELETE - FROM test_inner_postgres_types - WHERE test_inner_postgres_types.table_id = $1 - ``` - - Parameters - ---------- - table_id : int - - """ - await self._conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) - - async def delete_one_test_postgres_type(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. - - ```sql - DELETE - FROM test_postgres_types - WHERE test_postgres_types.id = $1 - ``` - - Parameters - ---------- - id_ : int - - """ - await self._conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) - - async def delete_type_override(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. - - ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = $1 - ``` - - Parameters - ---------- - id_ : int - - """ - await self._conn.execute(DELETE_TYPE_OVERRIDE, id_) - - async def get_all_embedded_test_postgres_type(self, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: - """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. - - ```sql - SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test - FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id - WHERE test_postgres_types.id = $1 - ``` - - Parameters - ---------- - id_ : int + text_test : str + varchar_test : str + bpchar_test : str + char_test : str + citext_test : str + uuid_test : uuid.UUID + inet_test : str + cidr_test : str + macaddr_test : str + macaddr8_test : str + ltree_test : str + lquery_test : str + ltxtquery_test : str Returns ------- - GetAllEmbeddedTestPostgresTypeRow - Result fetched from the db. Will be `None` if not found. + int + The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - row = await self._conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return GetAllEmbeddedTestPostgresTypeRow(test_postgres_type=models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]), test_inner_postgres_type=models.TestInnerPostgresType(table_id=row[36], serial_test=row[37], serial4_test=row[38], bigserial_test=row[39], smallserial_test=row[40], int_test=row[41], bigint_test=row[42], smallint_test=row[43], float_test=row[44], double_precision_test=row[45], real_test=row[46], numeric_test=row[47], money_test=row[48], bool_test=row[49], json_test=row[50], jsonb_test=row[51], bytea_test=memoryview(row[52]) if row[52] is not None else None, date_test=row[53], time_test=row[54], timetz_test=row[55], timestamp_test=row[56], timestamptz_test=row[57], interval_test=row[58], text_test=row[59], varchar_test=row[60], bpchar_test=row[61], char_test=row[62], citext_test=row[63], uuid_test=row[64], inet_test=str(row[65]) if row[65] is not None else None, cidr_test=str(row[66]) if row[66] is not None else None, macaddr_test=row[67], macaddr8_test=row[68], ltree_test=row[69], lquery_test=row[70], ltxtquery_test=row[71])) + r = await self._conn.execute( + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + return int(n) if (n := r.split()[-1]).isdigit() else 0 - async def get_embedded_test_postgres_type(self, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: - """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. + async def update_rows_test_postgres_type(self, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test - FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + UPDATE test_postgres_types + SET serial_test = 187 WHERE test_postgres_types.id = $1 ``` @@ -1099,22 +1917,20 @@ async def get_embedded_test_postgres_type(self, *, id_: int) -> GetEmbeddedTestP Returns ------- - GetEmbeddedTestPostgresTypeRow - Result fetched from the db. Will be `None` if not found. + int + The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - row = await self._conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return GetEmbeddedTestPostgresTypeRow(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35], test_inner_postgres_type=models.TestInnerPostgresType(table_id=row[36], serial_test=row[37], serial4_test=row[38], bigserial_test=row[39], smallserial_test=row[40], int_test=row[41], bigint_test=row[42], smallint_test=row[43], float_test=row[44], double_precision_test=row[45], real_test=row[46], numeric_test=row[47], money_test=row[48], bool_test=row[49], json_test=row[50], jsonb_test=row[51], bytea_test=memoryview(row[52]) if row[52] is not None else None, date_test=row[53], time_test=row[54], timetz_test=row[55], timestamp_test=row[56], timestamptz_test=row[57], interval_test=row[58], text_test=row[59], varchar_test=row[60], bpchar_test=row[61], char_test=row[62], citext_test=row[63], uuid_test=row[64], inet_test=str(row[65]) if row[65] is not None else None, cidr_test=str(row[66]) if row[66] is not None else None, macaddr_test=row[67], macaddr8_test=row[68], ltree_test=row[69], lquery_test=row[70], ltxtquery_test=row[71])) + r = await self._conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (n := r.split()[-1]).isdigit() else 0 - def get_many_test_bytea_postgres_type(self, *, id_: int) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. + async def delete_one_rows_test_postgres_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT bytea_test + DELETE FROM test_postgres_types - WHERE id = $1 LIMIT 2 + WHERE test_postgres_types.id = $1 ``` Parameters @@ -1123,86 +1939,73 @@ def get_many_test_bytea_postgres_type(self, *, id_: int) -> QueryResults[memoryv Returns ------- - QueryResults[memoryview] - Helper class that allows both iteration and normal fetching of data from the db. + int + The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - def _decode_hook(row: asyncpg.Record) -> memoryview: - return memoryview(row[0]) - return QueryResults[memoryview](self._conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + r = await self._conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (n := r.split()[-1]).isdigit() else 0 - def get_many_test_iterator_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: - """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. + async def create_rows_table(self) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) ``` - Parameters - ---------- - id_ : int - Returns ------- - QueryResults[models.TestPostgresType] - Helper class that allows both iteration and normal fetching of data from the db. + int + The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) - return QueryResults[models.TestPostgresType](self._conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) - - def get_many_test_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: - """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. + r = await self._conn.execute(CREATE_ROWS_TABLE) + return int(n) if (n := r.split()[-1]).isdigit() else 0 - ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 - ``` + async def test_copy_from(self, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. Parameters ---------- - id_ : int + params : collections.abc.Sequence[TestCopyFromParams] + A list of params for rows that should be inserted. Returns ------- - QueryResults[models.TestPostgresType] - Helper class that allows both iteration and normal fetching of data from the db. + int + The number of affected rows. """ - def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) - return QueryResults[models.TestPostgresType](self._conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + records = [(param.id_, param.float_test, param.int_test) for param in params] + r = await self._conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) + return int(n) if (n := r.split()[-1]).isdigit() else 0 - def get_many_test_timestamp_postgres_type(self, *, id_: int) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. + async def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: + """Execute SQL query with `name: InsertTypeOverride :exec`. ```sql - SELECT timestamp_test - FROM test_postgres_types - WHERE id = $1 LIMIT 2 + INSERT INTO test_type_override ( + id, text_test + ) VALUES ($1 ,$2) ``` Parameters ---------- id_ : int - - Returns - ------- - QueryResults[datetime.datetime] - Helper class that allows both iteration and normal fetching of data from the db. + text_test : UserString | None """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + await self._conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test) if text_test is not None else None) - def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + SELECT id, text_test FROM test_type_override WHERE id = $1 ``` Parameters @@ -1211,11 +2014,14 @@ def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString]: Returns ------- - QueryResults[UserString] - Helper class that allows both iteration and normal fetching of data from the db. + models.TestTypeOverride + Result fetched from the db. Will be `None` if not found. """ - return QueryResults[UserString](self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, operator.itemgetter(0), id_) + row = await self._conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. @@ -1234,41 +2040,39 @@ def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOve Helper class that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: asyncpg.Record) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - return QueryResults[models.TestTypeOverride](self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - async def get_one_inner_test_postgres_type(self, *, table_id: int) -> models.TestInnerPostgresType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + return QueryResults(self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + async def get_one_text_type_override(self, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_inner_postgres_types - WHERE table_id = $1 LIMIT 1 + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 ``` Parameters ---------- - table_id : int + id_ : int Returns ------- - models.TestInnerPostgresType + UserString Result fetched from the db. Will be `None` if not found. """ - row = await self._conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + row = await self._conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) if row is None: return None - return models.TestInnerPostgresType(table_id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]) if row[16] is not None else None, date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]) if row[29] is not None else None, cidr_test=str(row[30]) if row[30] is not None else None, macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) + return UserString(row[0]) if row[0] is not None else None - async def get_one_test_bytea_postgres_type(self, *, id_: int) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. + def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. ```sql - SELECT bytea_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 ``` Parameters @@ -1277,68 +2081,56 @@ async def get_one_test_bytea_postgres_type(self, *, id_: int) -> memoryview | No Returns ------- - memoryview - Result fetched from the db. Will be `None` if not found. + QueryResults[UserString | None] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await self._conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) - if row is None: - return None - return memoryview(row[0]) - async def get_one_test_postgres_type(self, *, id_: int) -> models.TestPostgresType | None: - """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. + def _decode_hook(row: asyncpg.Record) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + async def delete_type_override(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + DELETE + FROM test_type_override + WHERE test_type_override.id = $1 ``` Parameters ---------- id_ : int - Returns - ------- - models.TestPostgresType - Result fetched from the db. Will be `None` if not found. - """ - row = await self._conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) + await self._conn.execute(DELETE_TYPE_OVERRIDE, id_) - async def get_one_test_timestamp_postgres_type(self, *, id_: int) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. + async def insert_one_test_enum_type(self, *, id_: int, mood: enums.TestMood, maybe_mood: enums.TestMood | None) -> None: + """Execute SQL query with `name: InsertOneTestEnumType :exec`. ```sql - SELECT timestamp_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + INSERT INTO test_enum_types (id, mood, maybe_mood) + VALUES ($1, $2, $3) ``` Parameters ---------- id_ : int - - Returns - ------- - datetime.datetime - Result fetched from the db. Will be `None` if not found. + mood : enums.TestMood + maybe_mood : enums.TestMood | None """ - row = await self._conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) - if row is None: - return None - return row[0] + await self._conn.execute(INSERT_ONE_TEST_ENUM_TYPE, id_, mood, maybe_mood) - async def get_one_text_type_override(self, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + async def get_one_test_enum_type(self, *, id_: int) -> models.TestEnumType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumType :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + SELECT id, mood, maybe_mood + FROM test_enum_types + WHERE id = $1 ``` Parameters @@ -1347,20 +2139,22 @@ async def get_one_text_type_override(self, *, id_: int) -> UserString | None: Returns ------- - UserString + models.TestEnumType Result fetched from the db. Will be `None` if not found. """ - row = await self._conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) + row = await self._conn.fetchrow(GET_ONE_TEST_ENUM_TYPE, id_) if row is None: return None - return row[0] + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) - async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + async def get_one_test_enum_value(self, *, id_: int) -> enums.TestMood | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumValue :one`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = $1 + SELECT mood + FROM test_enum_types + WHERE id = $1 ``` Parameters @@ -1369,81 +2163,43 @@ async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | Returns ------- - models.TestTypeOverride + enums.TestMood Result fetched from the db. Will be `None` if not found. """ - row = await self._conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + row = await self._conn.fetchrow(GET_ONE_TEST_ENUM_VALUE, id_) if row is None: return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + return enums.TestMood(row[0]) - async def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: - """Execute SQL query with `name: InsertTypeOverride :exec`. + def get_many_test_enum_types(self) -> QueryResults[models.TestEnumType]: + """Fetch many from the db using the SQL query with `name: GetManyTestEnumTypes :many`. ```sql - INSERT INTO test_type_override ( - id, text_test - ) VALUES ($1 ,$2) + SELECT id, mood, maybe_mood + FROM test_enum_types + ORDER BY id ``` - Parameters - ---------- - id_ : int - text_test : UserString | None - - """ - await self._conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test)) - - async def test_copy_from(self, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: - """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. - - Parameters - ---------- - params : collections.abc.Sequence[TestCopyFromParams] - A list of params for rows that should be inserted. - Returns ------- - int - The number of affected rows. + QueryResults[models.TestEnumType] + Helper class that allows both iteration and normal fetching of data from the db. """ - records = [ - (param.id, param.float_test, param.int_test) - for param in params - ] - r = await self._conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) - return int(n) if (n := r.split()[-1]).isdigit() else 0 - - async def update_result_test_postgres_type(self, *, id_: int) -> str: - """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. - - ```sql - UPDATE test_postgres_types - SET serial_test = 187 - WHERE test_postgres_types.id = $1 - ``` - - Parameters - ---------- - id_ : int - Returns - ------- - str - The result returned when executing the query. + def _decode_hook(row: asyncpg.Record) -> models.TestEnumType: + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) - """ - return await self._conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) + return QueryResults(self._conn, GET_MANY_TEST_ENUM_TYPES, _decode_hook) - async def update_rows_test_postgres_type(self, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. + async def delete_one_test_enum_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneTestEnumType :execrows` and return the number of affected rows. ```sql - UPDATE test_postgres_types - SET serial_test = 187 - WHERE test_postgres_types.id = $1 + DELETE + FROM test_enum_types + WHERE id = $1 ``` Parameters @@ -1456,5 +2212,5 @@ async def update_rows_test_postgres_type(self, *, id_: int) -> int: The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - r = await self._conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + r = await self._conn.execute(DELETE_ONE_TEST_ENUM_TYPE, id_) return int(n) if (n := r.split()[-1]).isdigit() else 0 diff --git a/test/driver_asyncpg/attrs/classes/queries_copy_override.py b/test/driver_asyncpg/attrs/classes/queries_copy_override.py new file mode 100644 index 00000000..b16a4b15 --- /dev/null +++ b/test/driver_asyncpg/attrs/classes/queries_copy_override.py @@ -0,0 +1,125 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_copy_override.sql +"""Module containing queries from file queries_copy_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "CopyOverrideRowsParams", + "QueriesCopyOverride", +) + +import attrs +import decimal +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import collections.abc + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + + +@attrs.define() +class CopyOverrideRowsParams: + """Model representing CopyOverrideRowsParams. + + Attributes + ---------- + id_ : int + amount : float + + """ + + id_: int + amount: float + + +COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CopyOverrideRows :copyfrom +INSERT INTO test_copy_override (id, amount) VALUES ($1, $2) +""" + +COUNT_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CountCopyOverrideRows :one +SELECT count(*) FROM test_copy_override +""" + +DELETE_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: DeleteCopyOverrideRows :exec +DELETE FROM test_copy_override +""" + + +class QueriesCopyOverride: + """Queries from file queries_copy_override.sql. + + Parameters + ---------- + conn : ConnectionLike + The connection object used to execute queries. + + """ + + __slots__ = ("_conn",) + + def __init__(self, conn: ConnectionLike) -> None: + """Initialize the instance using the connection.""" + self._conn = conn + + @property + def conn(self) -> ConnectionLike: + """Connection object used to make queries. + + Returns + ------- + ConnectionLike + + """ + return self._conn + + async def copy_override_rows(self, *, params: collections.abc.Sequence[CopyOverrideRowsParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: CopyOverrideRows :copyfrom` and return the number of affected rows. + + Parameters + ---------- + params : collections.abc.Sequence[CopyOverrideRowsParams] + A list of params for rows that should be inserted. + + Returns + ------- + int + The number of affected rows. + + """ + records = [(param.id_, decimal.Decimal(param.amount)) for param in params] + r = await self._conn.copy_records_to_table("test_copy_override", columns=["id", "amount"], records=records) + return int(n) if (n := r.split()[-1]).isdigit() else 0 + + async def count_copy_override_rows(self) -> int | None: + """Fetch one from the db using the SQL query with `name: CountCopyOverrideRows :one`. + + ```sql + SELECT count(*) FROM test_copy_override + ``` + + Returns + ------- + int + Result fetched from the db. Will be `None` if not found. + + """ + row = await self._conn.fetchrow(COUNT_COPY_OVERRIDE_ROWS) + if row is None: + return None + return row[0] + + async def delete_copy_override_rows(self) -> None: + """Execute SQL query with `name: DeleteCopyOverrideRows :exec`. + + ```sql + DELETE FROM test_copy_override + ``` + + """ + await self._conn.execute(DELETE_COPY_OVERRIDE_ROWS) diff --git a/test/driver_asyncpg/attrs/classes/queries_enum_override.py b/test/driver_asyncpg/attrs/classes/queries_enum_override.py new file mode 100644 index 00000000..6959ce8e --- /dev/null +++ b/test/driver_asyncpg/attrs/classes/queries_enum_override.py @@ -0,0 +1,239 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_enum_override.sql +"""Module containing queries from file queries_enum_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "QueriesEnumOverride", + "QueryResults", +) + +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import asyncpg.cursor + import collections.abc + + type QueryResultsArgsType = int | float | str | memoryview | collections.abc.Sequence[QueryResultsArgsType] | None + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + +from test.driver_asyncpg.attrs.classes import enums +from test.driver_asyncpg.attrs.classes import models + + +INSERT_ENUM_OVERRIDE: typing.Final[str] = """-- name: InsertEnumOverride :exec +INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) +""" + +GET_ENUM_OVERRIDE_MOOD: typing.Final[str] = """-- name: GetEnumOverrideMood :one +SELECT mood_test FROM test_enum_override WHERE id = $1 +""" + +LIST_ENUM_OVERRIDE_BY_IDS: typing.Final[str] = """-- name: ListEnumOverrideByIds :many +SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) +""" + +COUNT_ENUM_OVERRIDE_BY_MOODS: typing.Final[str] = """-- name: CountEnumOverrideByMoods :one +SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db. + + Parameters + ---------- + conn + The connection object of type `ConnectionLike` used to execute queries. + sql + The SQL statement that will be executed when fetching/iterating. + decode_hook + A callback that turns an `asyncpg.Record` object into `T` that will be returned. + *args + Arguments that should be sent when executing the sql query. + + """ + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: ConnectionLike, + sql: str, + decode_hook: collections.abc.Callable[[asyncpg.Record], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance.""" + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: asyncpg.cursor.CursorFactory[asyncpg.Record] | None = None + self._iterator: asyncpg.cursor.CursorIterator[asyncpg.Record] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns + ------- + QueryResults[T] + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns + ------- + collections.abc.Sequence[T] + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await self._conn.fetch(self._sql, *self._args) + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an asyncpg cursor. + + Returns + ------- + T + The next decoded result. + + Raises + ------ + StopAsyncIteration + When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor = self._conn.cursor(self._sql, *self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +class QueriesEnumOverride: + """Queries from file queries_enum_override.sql. + + Parameters + ---------- + conn : ConnectionLike + The connection object used to execute queries. + + """ + + __slots__ = ("_conn",) + + def __init__(self, conn: ConnectionLike) -> None: + """Initialize the instance using the connection.""" + self._conn = conn + + @property + def conn(self) -> ConnectionLike: + """Connection object used to make queries. + + Returns + ------- + ConnectionLike + + """ + return self._conn + + async def insert_enum_override(self, *, id_: int, mood_test: str) -> None: + """Execute SQL query with `name: InsertEnumOverride :exec`. + + ```sql + INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) + ``` + + Parameters + ---------- + id_ : int + mood_test : str + + """ + await self._conn.execute(INSERT_ENUM_OVERRIDE, id_, enums.TestMood(mood_test)) + + async def get_enum_override_mood(self, *, id_: int) -> str | None: + """Fetch one from the db using the SQL query with `name: GetEnumOverrideMood :one`. + + ```sql + SELECT mood_test FROM test_enum_override WHERE id = $1 + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + str + Result fetched from the db. Will be `None` if not found. + + """ + row = await self._conn.fetchrow(GET_ENUM_OVERRIDE_MOOD, id_) + if row is None: + return None + return str(row[0]) + + def list_enum_override_by_ids(self, *, dollar_1: collections.abc.Sequence[int]) -> QueryResults[models.TestEnumOverride]: + """Fetch many from the db using the SQL query with `name: ListEnumOverrideByIds :many`. + + ```sql + SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) + ``` + + Parameters + ---------- + dollar_1 : collections.abc.Sequence[int] + + Returns + ------- + QueryResults[models.TestEnumOverride] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestEnumOverride: + return models.TestEnumOverride(id_=row[0], mood_test=str(row[1])) + + return QueryResults(self._conn, LIST_ENUM_OVERRIDE_BY_IDS, _decode_hook, dollar_1) + + async def count_enum_override_by_moods(self, *, dollar_1: collections.abc.Sequence[enums.TestMood]) -> int | None: + """Fetch one from the db using the SQL query with `name: CountEnumOverrideByMoods :one`. + + ```sql + SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) + ``` + + Parameters + ---------- + dollar_1 : collections.abc.Sequence[enums.TestMood] + + Returns + ------- + int + Result fetched from the db. Will be `None` if not found. + + """ + row = await self._conn.fetchrow(COUNT_ENUM_OVERRIDE_BY_MOODS, dollar_1) + if row is None: + return None + return row[0] diff --git a/test/driver_asyncpg/attrs/functions/__init__.py b/test/driver_asyncpg/attrs/functions/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_asyncpg/attrs/functions/__init__.py +++ b/test/driver_asyncpg/attrs/functions/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_asyncpg/attrs/functions/enums.py b/test/driver_asyncpg/attrs/functions/enums.py new file mode 100644 index 00000000..d49ac611 --- /dev/null +++ b/test/driver_asyncpg/attrs/functions/enums.py @@ -0,0 +1,23 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing enums.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("TestMood",) + +import enum +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +class TestMood(enum.StrEnum): + """Enum representing TestMood.""" + + SAD = "sad" + OK = "ok" + HAPPY = "happy" diff --git a/test/driver_asyncpg/attrs/functions/models.py b/test/driver_asyncpg/attrs/functions/models.py index 3c99c99c..3317389a 100644 --- a/test/driver_asyncpg/attrs/functions/models.py +++ b/test/driver_asyncpg/attrs/functions/models.py @@ -1,11 +1,14 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( + "TestEnumOverride", + "TestEnumType", "TestInnerPostgresType", "TestPostgresType", "TestTypeOverride", @@ -16,12 +19,45 @@ if typing.TYPE_CHECKING: from collections import UserString + from test.driver_asyncpg.attrs.functions import enums import collections.abc import datetime import decimal import uuid +@attrs.define() +class TestEnumOverride: + """Model representing TestEnumOverride. + + Attributes + ---------- + id_ : int + mood_test : str + + """ + + id_: int + mood_test: str + + +@attrs.define() +class TestEnumType: + """Model representing TestEnumType. + + Attributes + ---------- + id_ : int + mood : enums.TestMood + maybe_mood : enums.TestMood | None + + """ + + id_: int + mood: enums.TestMood + maybe_mood: enums.TestMood | None + + @attrs.define() class TestInnerPostgresType: """Model representing TestInnerPostgresType. @@ -111,7 +147,7 @@ class TestPostgresType: Attributes ---------- - id : int + id_ : int serial_test : int serial4_test : int bigserial_test : int @@ -150,7 +186,7 @@ class TestPostgresType: """ - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -194,10 +230,10 @@ class TestTypeOverride: Attributes ---------- - id : int + id_ : int text_test : UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_asyncpg/attrs/functions/queries.py b/test/driver_asyncpg/attrs/functions/queries.py index 5c0c6618..ce91f192 100644 --- a/test/driver_asyncpg/attrs/functions/queries.py +++ b/test/driver_asyncpg/attrs/functions/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -17,12 +19,14 @@ "create_rows_table", "delete_one_result_test_postgres_type", "delete_one_rows_test_postgres_type", + "delete_one_test_enum_type", "delete_one_test_postgres_inner_type", "delete_one_test_postgres_type", "delete_type_override", "get_all_embedded_test_postgres_type", "get_embedded_test_postgres_type", "get_many_test_bytea_postgres_type", + "get_many_test_enum_types", "get_many_test_iterator_postgres_type", "get_many_test_postgres_type", "get_many_test_timestamp_postgres_type", @@ -30,10 +34,13 @@ "get_many_type_override", "get_one_inner_test_postgres_type", "get_one_test_bytea_postgres_type", + "get_one_test_enum_type", + "get_one_test_enum_value", "get_one_test_postgres_type", "get_one_test_timestamp_postgres_type", "get_one_text_type_override", "get_one_type_override", + "insert_one_test_enum_type", "insert_type_override", "test_copy_from", "update_result_test_postgres_type", @@ -42,7 +49,6 @@ from collections import UserString import attrs -import datetime import operator import typing @@ -50,38 +56,25 @@ import asyncpg import asyncpg.cursor import collections.abc + import datetime import decimal import uuid - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None - ConnectionLike: typing.TypeAlias = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] +from test.driver_asyncpg.attrs.functions import enums from test.driver_asyncpg.attrs.functions import models -@attrs.define() -class GetAllEmbeddedTestPostgresTypeRow: - """Model representing GetAllEmbeddedTestPostgresTypeRow. - - Attributes - ---------- - test_postgres_type : models.TestPostgresType - test_inner_postgres_type : models.TestInnerPostgresType - - """ - - test_postgres_type: models.TestPostgresType - test_inner_postgres_type: models.TestInnerPostgresType - - @attrs.define() class GetEmbeddedTestPostgresTypeRow: """Model representing GetEmbeddedTestPostgresTypeRow. Attributes ---------- - id : int + id_ : int serial_test : int serial4_test : int bigserial_test : int @@ -121,7 +114,7 @@ class GetEmbeddedTestPostgresTypeRow: """ - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -160,65 +153,98 @@ class GetEmbeddedTestPostgresTypeRow: test_inner_postgres_type: models.TestInnerPostgresType +@attrs.define() +class GetAllEmbeddedTestPostgresTypeRow: + """Model representing GetAllEmbeddedTestPostgresTypeRow. + + Attributes + ---------- + test_postgres_type : models.TestPostgresType + test_inner_postgres_type : models.TestInnerPostgresType + + """ + + test_postgres_type: models.TestPostgresType + test_inner_postgres_type: models.TestInnerPostgresType + + @attrs.define() class TestCopyFromParams: """Model representing TestCopyFromParams. Attributes ---------- - id : int + id_ : int float_test : float int_test : int """ - id: int + id_: int float_test: float int_test: int -CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec -INSERT INTO test_inner_postgres_types (table_id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) -VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) +GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one +SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_inner_postgres_types +WHERE table_id = $1 LIMIT 1 +""" + +GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 +""" + +GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 """ CREATE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresType :exec @@ -265,6 +291,62 @@ class TestCopyFromParams: $33, $34, $35, $36) """ +CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec +INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec +DELETE +FROM test_inner_postgres_types +WHERE test_inner_postgres_types.table_id = $1 +""" + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateResultOneTestPostgresType :execresult INSERT INTO test_postgres_types (id, serial_test, @@ -309,6 +391,18 @@ class TestCopyFromParams: $33, $34, $35, $36) """ +UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateRowsOneTestPostgresType :execrows INSERT INTO test_postgres_types (id, serial_test, @@ -353,6 +447,18 @@ class TestCopyFromParams: $33, $34, $35, $36) """ +UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows CREATE TABLE test_create_rows_table ( @@ -361,28 +467,32 @@ class TestCopyFromParams: ) """ -DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom +INSERT INTO test_copy_from (id, + float_test, int_test) +VALUES ($1, $2, $3) """ -DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec +INSERT INTO test_type_override ( + id, text_test +) VALUES ($1 ,$2) """ -DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec -DELETE -FROM test_inner_postgres_types -WHERE test_inner_postgres_types.table_id = $1 +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = $1 """ -DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 """ DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec @@ -391,113 +501,37 @@ class TestCopyFromParams: WHERE test_type_override.id = $1 """ -GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one -SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id -WHERE test_postgres_types.id = $1 -""" - -GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one -SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id -WHERE test_postgres_types.id = $1 -""" - -GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many -SELECT bytea_test -FROM test_postgres_types -WHERE id = $1 LIMIT 2 +INSERT_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: InsertOneTestEnumType :exec +INSERT INTO test_enum_types (id, mood, maybe_mood) +VALUES ($1, $2, $3) """ -GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types +GET_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: GetOneTestEnumType :one +SELECT id, mood, maybe_mood +FROM test_enum_types WHERE id = $1 """ -GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types +GET_ONE_TEST_ENUM_VALUE: typing.Final[str] = """-- name: GetOneTestEnumValue :one +SELECT mood +FROM test_enum_types WHERE id = $1 """ -GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many -SELECT timestamp_test -FROM test_postgres_types -WHERE id = $1 LIMIT 2 -""" - -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one -SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_inner_postgres_types -WHERE table_id = $1 LIMIT 1 -""" - -GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one -SELECT bytea_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one -SELECT timestamp_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = $1 -""" - -INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec -INSERT INTO test_type_override ( - id, text_test -) VALUES ($1 ,$2) -""" - -TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom -INSERT INTO test_copy_from (id, - float_test, int_test) -VALUES ($1, $2, $3) -""" - -UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult -UPDATE test_postgres_types -SET serial_test = 187 -WHERE test_postgres_types.id = $1 +GET_MANY_TEST_ENUM_TYPES: typing.Final[str] = """-- name: GetManyTestEnumTypes :many +SELECT id, mood, maybe_mood +FROM test_enum_types +ORDER BY id """ -UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows -UPDATE test_postgres_types -SET serial_test = 187 -WHERE test_postgres_types.id = $1 +DELETE_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: DeleteOneTestEnumType :execrows +DELETE +FROM test_enum_types +WHERE id = $1 """ -T = typing.TypeVar("T") - - -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db. Parameters @@ -550,9 +584,11 @@ def __await__( collections.abc.Sequence[T] A sequence of decoded objects of type `T`. """ + async def _wrapper() -> collections.abc.Sequence[T]: result = await self._conn.fetch(self._sql, *self._args) return [self._decode_hook(row) for row in result] + return _wrapper().__await__() async def __anext__(self) -> T: @@ -580,173 +616,692 @@ async def __anext__(self) -> T: return self._decode_hook(record) -async def create_one_test_postgres_inner_type(conn: ConnectionLike, *, table_id: int, serial_test: int | None, serial4_test: int | None, bigserial_test: int | None, smallserial_test: int | None, int_test: int | None, bigint_test: int | None, smallint_test: int | None, float_test: float | None, double_precision_test: float | None, real_test: float | None, numeric_test: decimal.Decimal | None, money_test: str | None, bool_test: bool | None, json_test: str | None, jsonb_test: str | None, bytea_test: memoryview | None, date_test: datetime.date | None, time_test: datetime.time | None, timetz_test: datetime.time | None, timestamp_test: datetime.datetime | None, timestamptz_test: datetime.datetime | None, interval_test: datetime.timedelta | None, text_test: str | None, varchar_test: str | None, bpchar_test: str | None, char_test: str | None, citext_test: str | None, uuid_test: uuid.UUID | None, inet_test: str | None, cidr_test: str | None, macaddr_test: str | None, macaddr8_test: str | None, ltree_test: str | None, lquery_test: str | None, ltxtquery_test: str | None) -> None: - """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. +async def get_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> models.TestPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. ```sql - INSERT INTO test_inner_postgres_types (table_id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 ``` Parameters ---------- conn : ConnectionLike Connection object of type `ConnectionLike` used to execute the query. - table_id : int - serial_test : int | None - serial4_test : int | None - bigserial_test : int | None - smallserial_test : int | None - int_test : int | None - bigint_test : int | None - smallint_test : int | None - float_test : float | None - double_precision_test : float | None - real_test : float | None - numeric_test : decimal.Decimal | None - money_test : str | None - bool_test : bool | None - json_test : str | None - jsonb_test : str | None - bytea_test : memoryview | None - date_test : datetime.date | None - time_test : datetime.time | None - timetz_test : datetime.time | None - timestamp_test : datetime.datetime | None - timestamptz_test : datetime.datetime | None - interval_test : datetime.timedelta | None - text_test : str | None - varchar_test : str | None - bpchar_test : str | None - char_test : str | None - citext_test : str | None - uuid_test : uuid.UUID | None - inet_test : str | None - cidr_test : str | None - macaddr_test : str | None - macaddr8_test : str | None - ltree_test : str | None - lquery_test : str | None - ltxtquery_test : str | None + id_ : int + + Returns + ------- + models.TestPostgresType + Result fetched from the db. Will be `None` if not found. """ - await conn.execute(CREATE_ONE_TEST_POSTGRES_INNER_TYPE, table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + row = await conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) -async def create_one_test_postgres_type(conn: ConnectionLike, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> None: - """Execute SQL query with `name: CreateOneTestPostgresType :exec`. +async def get_one_inner_test_postgres_type(conn: ConnectionLike, *, table_id: int) -> models.TestInnerPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. ```sql - INSERT INTO test_postgres_types (id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) + SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_inner_postgres_types + WHERE table_id = $1 LIMIT 1 ``` Parameters ---------- conn : ConnectionLike Connection object of type `ConnectionLike` used to execute the query. - id_ : int - serial_test : int - serial4_test : int - bigserial_test : int - smallserial_test : int - int_test : int - bigint_test : int - smallint_test : int - float_test : float - double_precision_test : float - real_test : float - numeric_test : decimal.Decimal - money_test : str - bool_test : bool - json_test : str - jsonb_test : str - bytea_test : memoryview - date_test : datetime.date - time_test : datetime.time - timetz_test : datetime.time - timestamp_test : datetime.datetime - timestamptz_test : datetime.datetime - interval_test : datetime.timedelta - text_test : str + table_id : int + + Returns + ------- + models.TestInnerPostgresType + Result fetched from the db. Will be `None` if not found. + + """ + row = await conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + if row is None: + return None + return models.TestInnerPostgresType( + table_id=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]) if row[16] is not None else None, + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]) if row[29] is not None else None, + cidr_test=str(row[30]) if row[30] is not None else None, + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + +async def get_one_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. + + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + + Returns + ------- + datetime.datetime + Result fetched from the db. Will be `None` if not found. + + """ + row = await conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) + if row is None: + return None + return row[0] + + +async def get_one_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + + Returns + ------- + memoryview + Result fetched from the db. Will be `None` if not found. + + """ + row = await conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) + if row is None: + return None + return memoryview(row[0]) + + +def get_many_test_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + + Returns + ------- + QueryResults[models.TestPostgresType] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + + +def get_many_test_iterator_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + + Returns + ------- + QueryResults[models.TestPostgresType] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) + + +def get_many_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. + + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + + Returns + ------- + QueryResults[datetime.datetime] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + return QueryResults(conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + + +def get_many_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + + Returns + ------- + QueryResults[memoryview] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: asyncpg.Record) -> memoryview: + return memoryview(row[0]) + + return QueryResults(conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + + +async def get_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + + Returns + ------- + GetEmbeddedTestPostgresTypeRow + Result fetched from the db. Will be `None` if not found. + + """ + row = await conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetEmbeddedTestPostgresTypeRow( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + +async def get_all_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + + Returns + ------- + GetAllEmbeddedTestPostgresTypeRow + Result fetched from the db. Will be `None` if not found. + + """ + row = await conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetAllEmbeddedTestPostgresTypeRow( + test_postgres_type=models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ), + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + +async def create_one_test_postgres_type( + conn: ConnectionLike, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, +) -> None: + """Execute SQL query with `name: CreateOneTestPostgresType :exec`. + + ```sql + INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + serial_test : int + serial4_test : int + bigserial_test : int + smallserial_test : int + int_test : int + bigint_test : int + smallint_test : int + float_test : float + double_precision_test : float + real_test : float + numeric_test : decimal.Decimal + money_test : str + bool_test : bool + json_test : str + jsonb_test : str + bytea_test : memoryview + date_test : datetime.date + time_test : datetime.time + timetz_test : datetime.time + timestamp_test : datetime.datetime + timestamptz_test : datetime.datetime + interval_test : datetime.timedelta + text_test : str varchar_test : str bpchar_test : str char_test : str @@ -761,10 +1316,294 @@ async def create_one_test_postgres_type(conn: ConnectionLike, *, id_: int, seria ltxtquery_test : str """ - await conn.execute(CREATE_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + await conn.execute( + CREATE_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + +async def create_one_test_postgres_inner_type( + conn: ConnectionLike, + *, + table_id: int, + serial_test: int | None, + serial4_test: int | None, + bigserial_test: int | None, + smallserial_test: int | None, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + float_test: float | None, + double_precision_test: float | None, + real_test: float | None, + numeric_test: decimal.Decimal | None, + money_test: str | None, + bool_test: bool | None, + json_test: str | None, + jsonb_test: str | None, + bytea_test: memoryview | None, + date_test: datetime.date | None, + time_test: datetime.time | None, + timetz_test: datetime.time | None, + timestamp_test: datetime.datetime | None, + timestamptz_test: datetime.datetime | None, + interval_test: datetime.timedelta | None, + text_test: str | None, + varchar_test: str | None, + bpchar_test: str | None, + char_test: str | None, + citext_test: str | None, + uuid_test: uuid.UUID | None, + inet_test: str | None, + cidr_test: str | None, + macaddr_test: str | None, + macaddr8_test: str | None, + ltree_test: str | None, + lquery_test: str | None, + ltxtquery_test: str | None, +) -> None: + """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. + + ```sql + INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + table_id : int + serial_test : int | None + serial4_test : int | None + bigserial_test : int | None + smallserial_test : int | None + int_test : int | None + bigint_test : int | None + smallint_test : int | None + float_test : float | None + double_precision_test : float | None + real_test : float | None + numeric_test : decimal.Decimal | None + money_test : str | None + bool_test : bool | None + json_test : str | None + jsonb_test : str | None + bytea_test : memoryview | None + date_test : datetime.date | None + time_test : datetime.time | None + timetz_test : datetime.time | None + timestamp_test : datetime.datetime | None + timestamptz_test : datetime.datetime | None + interval_test : datetime.timedelta | None + text_test : str | None + varchar_test : str | None + bpchar_test : str | None + char_test : str | None + citext_test : str | None + uuid_test : uuid.UUID | None + inet_test : str | None + cidr_test : str | None + macaddr_test : str | None + macaddr8_test : str | None + ltree_test : str | None + lquery_test : str | None + ltxtquery_test : str | None + + """ + await conn.execute( + CREATE_ONE_TEST_POSTGRES_INNER_TYPE, + table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + +async def delete_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + + """ + await conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) + + +async def delete_one_test_postgres_inner_type(conn: ConnectionLike, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. + + ```sql + DELETE + FROM test_inner_postgres_types + WHERE test_inner_postgres_types.table_id = $1 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + table_id : int + + """ + await conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) -async def create_result_one_test_postgres_type(conn: ConnectionLike, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> str: +async def create_result_one_test_postgres_type( + conn: ConnectionLike, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, +) -> str: """Execute and return the result of SQL query with `name: CreateResultOneTestPostgresType :execresult`. ```sql @@ -858,10 +1697,135 @@ async def create_result_one_test_postgres_type(conn: ConnectionLike, *, id_: int The result returned when executing the query. """ - return await conn.execute(CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + return await conn.execute( + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + +async def update_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. + + ```sql + UPDATE test_postgres_types + SET serial_test = 187 + WHERE test_postgres_types.id = $1 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + + Returns + ------- + str + The result returned when executing the query. + + """ + return await conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) + + +async def delete_one_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + + Returns + ------- + str + The result returned when executing the query. + + """ + return await conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) -async def create_rows_one_test_postgres_type(conn: ConnectionLike, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> int: +async def create_rows_one_test_postgres_type( + conn: ConnectionLike, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, +) -> int: """Execute SQL query with `name: CreateRowsOneTestPostgresType :execrows` and return the number of affected rows. ```sql @@ -935,197 +1899,74 @@ async def create_rows_one_test_postgres_type(conn: ConnectionLike, *, id_: int, timestamp_test : datetime.datetime timestamptz_test : datetime.datetime interval_test : datetime.timedelta - text_test : str - varchar_test : str - bpchar_test : str - char_test : str - citext_test : str - uuid_test : uuid.UUID - inet_test : str - cidr_test : str - macaddr_test : str - macaddr8_test : str - ltree_test : str - lquery_test : str - ltxtquery_test : str - - Returns - ------- - int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - - """ - r = await conn.execute(CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) - return int(n) if (n := r.split()[-1]).isdigit() else 0 - - -async def create_rows_table(conn: ConnectionLike) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. - - ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Parameters - ---------- - conn : ConnectionLike - Connection object of type `ConnectionLike` used to execute the query. - - Returns - ------- - int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - - """ - r = await conn.execute(CREATE_ROWS_TABLE) - return int(n) if (n := r.split()[-1]).isdigit() else 0 - - -async def delete_one_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: - """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. - - ```sql - DELETE - FROM test_postgres_types - WHERE test_postgres_types.id = $1 - ``` - - Parameters - ---------- - conn : ConnectionLike - Connection object of type `ConnectionLike` used to execute the query. - id_ : int - - Returns - ------- - str - The result returned when executing the query. - - """ - return await conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) - - -async def delete_one_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: - """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. - - ```sql - DELETE - FROM test_postgres_types - WHERE test_postgres_types.id = $1 - ``` - - Parameters - ---------- - conn : ConnectionLike - Connection object of type `ConnectionLike` used to execute the query. - id_ : int - - Returns - ------- - int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - - """ - r = await conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) - return int(n) if (n := r.split()[-1]).isdigit() else 0 - - -async def delete_one_test_postgres_inner_type(conn: ConnectionLike, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. - - ```sql - DELETE - FROM test_inner_postgres_types - WHERE test_inner_postgres_types.table_id = $1 - ``` - - Parameters - ---------- - conn : ConnectionLike - Connection object of type `ConnectionLike` used to execute the query. - table_id : int - - """ - await conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) - - -async def delete_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. - - ```sql - DELETE - FROM test_postgres_types - WHERE test_postgres_types.id = $1 - ``` - - Parameters - ---------- - conn : ConnectionLike - Connection object of type `ConnectionLike` used to execute the query. - id_ : int - - """ - await conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) - - -async def delete_type_override(conn: ConnectionLike, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. - - ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = $1 - ``` - - Parameters - ---------- - conn : ConnectionLike - Connection object of type `ConnectionLike` used to execute the query. - id_ : int - - """ - await conn.execute(DELETE_TYPE_OVERRIDE, id_) - - -async def get_all_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: - """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. - - ```sql - SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test - FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id - WHERE test_postgres_types.id = $1 - ``` - - Parameters - ---------- - conn : ConnectionLike - Connection object of type `ConnectionLike` used to execute the query. - id_ : int + text_test : str + varchar_test : str + bpchar_test : str + char_test : str + citext_test : str + uuid_test : uuid.UUID + inet_test : str + cidr_test : str + macaddr_test : str + macaddr8_test : str + ltree_test : str + lquery_test : str + ltxtquery_test : str Returns ------- - GetAllEmbeddedTestPostgresTypeRow - Result fetched from the db. Will be `None` if not found. + int + The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - row = await conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return GetAllEmbeddedTestPostgresTypeRow(test_postgres_type=models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]), test_inner_postgres_type=models.TestInnerPostgresType(table_id=row[36], serial_test=row[37], serial4_test=row[38], bigserial_test=row[39], smallserial_test=row[40], int_test=row[41], bigint_test=row[42], smallint_test=row[43], float_test=row[44], double_precision_test=row[45], real_test=row[46], numeric_test=row[47], money_test=row[48], bool_test=row[49], json_test=row[50], jsonb_test=row[51], bytea_test=memoryview(row[52]) if row[52] is not None else None, date_test=row[53], time_test=row[54], timetz_test=row[55], timestamp_test=row[56], timestamptz_test=row[57], interval_test=row[58], text_test=row[59], varchar_test=row[60], bpchar_test=row[61], char_test=row[62], citext_test=row[63], uuid_test=row[64], inet_test=str(row[65]) if row[65] is not None else None, cidr_test=str(row[66]) if row[66] is not None else None, macaddr_test=row[67], macaddr8_test=row[68], ltree_test=row[69], lquery_test=row[70], ltxtquery_test=row[71])) + r = await conn.execute( + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + return int(n) if (n := r.split()[-1]).isdigit() else 0 -async def get_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: - """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. +async def update_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test - FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + UPDATE test_postgres_types + SET serial_test = 187 WHERE test_postgres_types.id = $1 ``` @@ -1137,23 +1978,21 @@ async def get_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> Returns ------- - GetEmbeddedTestPostgresTypeRow - Result fetched from the db. Will be `None` if not found. + int + The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - row = await conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return GetEmbeddedTestPostgresTypeRow(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35], test_inner_postgres_type=models.TestInnerPostgresType(table_id=row[36], serial_test=row[37], serial4_test=row[38], bigserial_test=row[39], smallserial_test=row[40], int_test=row[41], bigint_test=row[42], smallint_test=row[43], float_test=row[44], double_precision_test=row[45], real_test=row[46], numeric_test=row[47], money_test=row[48], bool_test=row[49], json_test=row[50], jsonb_test=row[51], bytea_test=memoryview(row[52]) if row[52] is not None else None, date_test=row[53], time_test=row[54], timetz_test=row[55], timestamp_test=row[56], timestamptz_test=row[57], interval_test=row[58], text_test=row[59], varchar_test=row[60], bpchar_test=row[61], char_test=row[62], citext_test=row[63], uuid_test=row[64], inet_test=str(row[65]) if row[65] is not None else None, cidr_test=str(row[66]) if row[66] is not None else None, macaddr_test=row[67], macaddr8_test=row[68], ltree_test=row[69], lquery_test=row[70], ltxtquery_test=row[71])) + r = await conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (n := r.split()[-1]).isdigit() else 0 -def get_many_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. +async def delete_one_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT bytea_test + DELETE FROM test_postgres_types - WHERE id = $1 LIMIT 2 + WHERE test_postgres_types.id = $1 ``` Parameters @@ -1164,74 +2003,68 @@ def get_many_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> Quer Returns ------- - QueryResults[memoryview] - Helper class that allows both iteration and normal fetching of data from the db. + int + The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - def _decode_hook(row: asyncpg.Record) -> memoryview: - return memoryview(row[0]) - return QueryResults[memoryview](conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + r = await conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (n := r.split()[-1]).isdigit() else 0 -def get_many_test_iterator_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: - """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. +async def create_rows_table(conn: ConnectionLike) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) ``` Parameters ---------- conn : ConnectionLike Connection object of type `ConnectionLike` used to execute the query. - id_ : int Returns ------- - QueryResults[models.TestPostgresType] - Helper class that allows both iteration and normal fetching of data from the db. + int + The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) - return QueryResults[models.TestPostgresType](conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) - + r = await conn.execute(CREATE_ROWS_TABLE) + return int(n) if (n := r.split()[-1]).isdigit() else 0 -def get_many_test_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: - """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. - ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 - ``` +async def test_copy_from(conn: ConnectionLike, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. Parameters ---------- conn : ConnectionLike Connection object of type `ConnectionLike` used to execute the query. - id_ : int + params : collections.abc.Sequence[TestCopyFromParams] + A list of params for rows that should be inserted. Returns ------- - QueryResults[models.TestPostgresType] - Helper class that allows both iteration and normal fetching of data from the db. + int + The number of affected rows. """ - def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) - return QueryResults[models.TestPostgresType](conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + records = [(param.id_, param.float_test, param.int_test) for param in params] + r = await conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) + return int(n) if (n := r.split()[-1]).isdigit() else 0 -def get_many_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. +async def insert_type_override(conn: ConnectionLike, *, id_: int, text_test: UserString | None) -> None: + """Execute SQL query with `name: InsertTypeOverride :exec`. ```sql - SELECT timestamp_test - FROM test_postgres_types - WHERE id = $1 LIMIT 2 + INSERT INTO test_type_override ( + id, text_test + ) VALUES ($1 ,$2) ``` Parameters @@ -1239,21 +2072,17 @@ def get_many_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> conn : ConnectionLike Connection object of type `ConnectionLike` used to execute the query. id_ : int - - Returns - ------- - QueryResults[datetime.datetime] - Helper class that allows both iteration and normal fetching of data from the db. + text_test : UserString | None """ - return QueryResults[datetime.datetime](conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + await conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test) if text_test is not None else None) -def get_many_text_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. +async def get_one_type_override(conn: ConnectionLike, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + SELECT id, text_test FROM test_type_override WHERE id = $1 ``` Parameters @@ -1264,11 +2093,14 @@ def get_many_text_type_override(conn: ConnectionLike, *, id_: int) -> QueryResul Returns ------- - QueryResults[UserString] - Helper class that allows both iteration and normal fetching of data from the db. + models.TestTypeOverride + Result fetched from the db. Will be `None` if not found. """ - return QueryResults[UserString](conn, GET_MANY_TEXT_TYPE_OVERRIDE, operator.itemgetter(0), id_) + row = await conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) def get_many_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestTypeOverride]: @@ -1290,45 +2122,43 @@ def get_many_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[mo Helper class that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: asyncpg.Record) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - return QueryResults[models.TestTypeOverride](conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + return QueryResults(conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) -async def get_one_inner_test_postgres_type(conn: ConnectionLike, *, table_id: int) -> models.TestInnerPostgresType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + +async def get_one_text_type_override(conn: ConnectionLike, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_inner_postgres_types - WHERE table_id = $1 LIMIT 1 + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 ``` Parameters ---------- conn : ConnectionLike Connection object of type `ConnectionLike` used to execute the query. - table_id : int + id_ : int Returns ------- - models.TestInnerPostgresType + UserString Result fetched from the db. Will be `None` if not found. """ - row = await conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + row = await conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) if row is None: return None - return models.TestInnerPostgresType(table_id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]) if row[16] is not None else None, date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]) if row[29] is not None else None, cidr_test=str(row[30]) if row[30] is not None else None, macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) + return UserString(row[0]) if row[0] is not None else None -async def get_one_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. +def get_many_text_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. ```sql - SELECT bytea_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 ``` Parameters @@ -1339,23 +2169,24 @@ async def get_one_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> Returns ------- - memoryview - Result fetched from the db. Will be `None` if not found. + QueryResults[UserString | None] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = await conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) - if row is None: - return None - return memoryview(row[0]) + def _decode_hook(row: asyncpg.Record) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) -async def get_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> models.TestPostgresType | None: - """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. + +async def delete_type_override(conn: ConnectionLike, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + DELETE + FROM test_type_override + WHERE test_type_override.id = $1 ``` Parameters @@ -1364,25 +2195,16 @@ async def get_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> model Connection object of type `ConnectionLike` used to execute the query. id_ : int - Returns - ------- - models.TestPostgresType - Result fetched from the db. Will be `None` if not found. - """ - row = await conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) + await conn.execute(DELETE_TYPE_OVERRIDE, id_) -async def get_one_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. +async def insert_one_test_enum_type(conn: ConnectionLike, *, id_: int, mood: enums.TestMood, maybe_mood: enums.TestMood | None) -> None: + """Execute SQL query with `name: InsertOneTestEnumType :exec`. ```sql - SELECT timestamp_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + INSERT INTO test_enum_types (id, mood, maybe_mood) + VALUES ($1, $2, $3) ``` Parameters @@ -1390,24 +2212,20 @@ async def get_one_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int conn : ConnectionLike Connection object of type `ConnectionLike` used to execute the query. id_ : int - - Returns - ------- - datetime.datetime - Result fetched from the db. Will be `None` if not found. + mood : enums.TestMood + maybe_mood : enums.TestMood | None """ - row = await conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) - if row is None: - return None - return row[0] + await conn.execute(INSERT_ONE_TEST_ENUM_TYPE, id_, mood, maybe_mood) -async def get_one_text_type_override(conn: ConnectionLike, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. +async def get_one_test_enum_type(conn: ConnectionLike, *, id_: int) -> models.TestEnumType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumType :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + SELECT id, mood, maybe_mood + FROM test_enum_types + WHERE id = $1 ``` Parameters @@ -1418,21 +2236,23 @@ async def get_one_text_type_override(conn: ConnectionLike, *, id_: int) -> UserS Returns ------- - UserString + models.TestEnumType Result fetched from the db. Will be `None` if not found. """ - row = await conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) + row = await conn.fetchrow(GET_ONE_TEST_ENUM_TYPE, id_) if row is None: return None - return row[0] + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) -async def get_one_type_override(conn: ConnectionLike, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. +async def get_one_test_enum_value(conn: ConnectionLike, *, id_: int) -> enums.TestMood | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumValue :one`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = $1 + SELECT mood + FROM test_enum_types + WHERE id = $1 ``` Parameters @@ -1443,91 +2263,50 @@ async def get_one_type_override(conn: ConnectionLike, *, id_: int) -> models.Tes Returns ------- - models.TestTypeOverride + enums.TestMood Result fetched from the db. Will be `None` if not found. """ - row = await conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + row = await conn.fetchrow(GET_ONE_TEST_ENUM_VALUE, id_) if row is None: return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + return enums.TestMood(row[0]) -async def insert_type_override(conn: ConnectionLike, *, id_: int, text_test: UserString | None) -> None: - """Execute SQL query with `name: InsertTypeOverride :exec`. +def get_many_test_enum_types(conn: ConnectionLike) -> QueryResults[models.TestEnumType]: + """Fetch many from the db using the SQL query with `name: GetManyTestEnumTypes :many`. ```sql - INSERT INTO test_type_override ( - id, text_test - ) VALUES ($1 ,$2) + SELECT id, mood, maybe_mood + FROM test_enum_types + ORDER BY id ``` Parameters ---------- conn : ConnectionLike Connection object of type `ConnectionLike` used to execute the query. - id_ : int - text_test : UserString | None - - """ - await conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test)) - - -async def test_copy_from(conn: ConnectionLike, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: - """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. - - Parameters - ---------- - conn : ConnectionLike - Connection object of type `ConnectionLike` used to execute the query. - params : collections.abc.Sequence[TestCopyFromParams] - A list of params for rows that should be inserted. Returns ------- - int - The number of affected rows. + QueryResults[models.TestEnumType] + Helper class that allows both iteration and normal fetching of data from the db. """ - records = [ - (param.id, param.float_test, param.int_test) - for param in params - ] - r = await conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) - return int(n) if (n := r.split()[-1]).isdigit() else 0 - - -async def update_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: - """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. - - ```sql - UPDATE test_postgres_types - SET serial_test = 187 - WHERE test_postgres_types.id = $1 - ``` - - Parameters - ---------- - conn : ConnectionLike - Connection object of type `ConnectionLike` used to execute the query. - id_ : int - Returns - ------- - str - The result returned when executing the query. + def _decode_hook(row: asyncpg.Record) -> models.TestEnumType: + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) - """ - return await conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) + return QueryResults(conn, GET_MANY_TEST_ENUM_TYPES, _decode_hook) -async def update_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. +async def delete_one_test_enum_type(conn: ConnectionLike, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneTestEnumType :execrows` and return the number of affected rows. ```sql - UPDATE test_postgres_types - SET serial_test = 187 - WHERE test_postgres_types.id = $1 + DELETE + FROM test_enum_types + WHERE id = $1 ``` Parameters @@ -1542,5 +2321,5 @@ async def update_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> i The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - r = await conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + r = await conn.execute(DELETE_ONE_TEST_ENUM_TYPE, id_) return int(n) if (n := r.split()[-1]).isdigit() else 0 diff --git a/test/driver_asyncpg/attrs/functions/queries_copy_override.py b/test/driver_asyncpg/attrs/functions/queries_copy_override.py new file mode 100644 index 00000000..95c27e54 --- /dev/null +++ b/test/driver_asyncpg/attrs/functions/queries_copy_override.py @@ -0,0 +1,114 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_copy_override.sql +"""Module containing queries from file queries_copy_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "CopyOverrideRowsParams", + "copy_override_rows", + "count_copy_override_rows", + "delete_copy_override_rows", +) + +import attrs +import decimal +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import collections.abc + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + + +@attrs.define() +class CopyOverrideRowsParams: + """Model representing CopyOverrideRowsParams. + + Attributes + ---------- + id_ : int + amount : float + + """ + + id_: int + amount: float + + +COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CopyOverrideRows :copyfrom +INSERT INTO test_copy_override (id, amount) VALUES ($1, $2) +""" + +COUNT_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CountCopyOverrideRows :one +SELECT count(*) FROM test_copy_override +""" + +DELETE_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: DeleteCopyOverrideRows :exec +DELETE FROM test_copy_override +""" + + +async def copy_override_rows(conn: ConnectionLike, *, params: collections.abc.Sequence[CopyOverrideRowsParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: CopyOverrideRows :copyfrom` and return the number of affected rows. + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + params : collections.abc.Sequence[CopyOverrideRowsParams] + A list of params for rows that should be inserted. + + Returns + ------- + int + The number of affected rows. + + """ + records = [(param.id_, decimal.Decimal(param.amount)) for param in params] + r = await conn.copy_records_to_table("test_copy_override", columns=["id", "amount"], records=records) + return int(n) if (n := r.split()[-1]).isdigit() else 0 + + +async def count_copy_override_rows(conn: ConnectionLike) -> int | None: + """Fetch one from the db using the SQL query with `name: CountCopyOverrideRows :one`. + + ```sql + SELECT count(*) FROM test_copy_override + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + + Returns + ------- + int + Result fetched from the db. Will be `None` if not found. + + """ + row = await conn.fetchrow(COUNT_COPY_OVERRIDE_ROWS) + if row is None: + return None + return row[0] + + +async def delete_copy_override_rows(conn: ConnectionLike) -> None: + """Execute SQL query with `name: DeleteCopyOverrideRows :exec`. + + ```sql + DELETE FROM test_copy_override + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + + """ + await conn.execute(DELETE_COPY_OVERRIDE_ROWS) diff --git a/test/driver_asyncpg/attrs/functions/queries_enum_override.py b/test/driver_asyncpg/attrs/functions/queries_enum_override.py new file mode 100644 index 00000000..e4666c8d --- /dev/null +++ b/test/driver_asyncpg/attrs/functions/queries_enum_override.py @@ -0,0 +1,226 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_enum_override.sql +"""Module containing queries from file queries_enum_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "QueryResults", + "count_enum_override_by_moods", + "get_enum_override_mood", + "insert_enum_override", + "list_enum_override_by_ids", +) + +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import asyncpg.cursor + import collections.abc + + type QueryResultsArgsType = int | float | str | memoryview | collections.abc.Sequence[QueryResultsArgsType] | None + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + +from test.driver_asyncpg.attrs.functions import enums +from test.driver_asyncpg.attrs.functions import models + + +INSERT_ENUM_OVERRIDE: typing.Final[str] = """-- name: InsertEnumOverride :exec +INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) +""" + +GET_ENUM_OVERRIDE_MOOD: typing.Final[str] = """-- name: GetEnumOverrideMood :one +SELECT mood_test FROM test_enum_override WHERE id = $1 +""" + +LIST_ENUM_OVERRIDE_BY_IDS: typing.Final[str] = """-- name: ListEnumOverrideByIds :many +SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) +""" + +COUNT_ENUM_OVERRIDE_BY_MOODS: typing.Final[str] = """-- name: CountEnumOverrideByMoods :one +SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db. + + Parameters + ---------- + conn + The connection object of type `ConnectionLike` used to execute queries. + sql + The SQL statement that will be executed when fetching/iterating. + decode_hook + A callback that turns an `asyncpg.Record` object into `T` that will be returned. + *args + Arguments that should be sent when executing the sql query. + + """ + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: ConnectionLike, + sql: str, + decode_hook: collections.abc.Callable[[asyncpg.Record], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance.""" + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: asyncpg.cursor.CursorFactory[asyncpg.Record] | None = None + self._iterator: asyncpg.cursor.CursorIterator[asyncpg.Record] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns + ------- + QueryResults[T] + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns + ------- + collections.abc.Sequence[T] + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await self._conn.fetch(self._sql, *self._args) + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an asyncpg cursor. + + Returns + ------- + T + The next decoded result. + + Raises + ------ + StopAsyncIteration + When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor = self._conn.cursor(self._sql, *self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +async def insert_enum_override(conn: ConnectionLike, *, id_: int, mood_test: str) -> None: + """Execute SQL query with `name: InsertEnumOverride :exec`. + + ```sql + INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + mood_test : str + + """ + await conn.execute(INSERT_ENUM_OVERRIDE, id_, enums.TestMood(mood_test)) + + +async def get_enum_override_mood(conn: ConnectionLike, *, id_: int) -> str | None: + """Fetch one from the db using the SQL query with `name: GetEnumOverrideMood :one`. + + ```sql + SELECT mood_test FROM test_enum_override WHERE id = $1 + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + id_ : int + + Returns + ------- + str + Result fetched from the db. Will be `None` if not found. + + """ + row = await conn.fetchrow(GET_ENUM_OVERRIDE_MOOD, id_) + if row is None: + return None + return str(row[0]) + + +def list_enum_override_by_ids(conn: ConnectionLike, *, dollar_1: collections.abc.Sequence[int]) -> QueryResults[models.TestEnumOverride]: + """Fetch many from the db using the SQL query with `name: ListEnumOverrideByIds :many`. + + ```sql + SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + dollar_1 : collections.abc.Sequence[int] + + Returns + ------- + QueryResults[models.TestEnumOverride] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestEnumOverride: + return models.TestEnumOverride(id_=row[0], mood_test=str(row[1])) + + return QueryResults(conn, LIST_ENUM_OVERRIDE_BY_IDS, _decode_hook, dollar_1) + + +async def count_enum_override_by_moods(conn: ConnectionLike, *, dollar_1: collections.abc.Sequence[enums.TestMood]) -> int | None: + """Fetch one from the db using the SQL query with `name: CountEnumOverrideByMoods :one`. + + ```sql + SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) + ``` + + Parameters + ---------- + conn : ConnectionLike + Connection object of type `ConnectionLike` used to execute the query. + dollar_1 : collections.abc.Sequence[enums.TestMood] + + Returns + ------- + int + Result fetched from the db. Will be `None` if not found. + + """ + row = await conn.fetchrow(COUNT_ENUM_OVERRIDE_BY_MOODS, dollar_1) + if row is None: + return None + return row[0] diff --git a/test/driver_asyncpg/attrs/test_attrs_classes.py b/test/driver_asyncpg/attrs/test_attrs_classes.py index a2b9fcdd..93662532 100644 --- a/test/driver_asyncpg/attrs/test_attrs_classes.py +++ b/test/driver_asyncpg/attrs/test_attrs_classes.py @@ -42,12 +42,12 @@ class TestAttrsClasses: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestPostgresType: return models.TestPostgresType( - id=random.randint(1, 1000000), + id_=random.randint(1, 1000000), serial_test=1, serial4_test=2, bigserial_test=3, @@ -66,9 +66,9 @@ def model(self) -> models.TestPostgresType: bytea_test=memoryview(b"\x00\x01\x02hello"), date_test=datetime.date(2025, 1, 1), time_test=datetime.time(14, 30, 0), - timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.timezone.utc), + timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.UTC), timestamp_test=datetime.datetime(2025, 1, 1, 14, 30, 0), - timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.timezone.utc), + timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.UTC), interval_test=datetime.timedelta(days=1, hours=2, minutes=30), text_test="Lorem ipsum", varchar_test="Example varchar", @@ -88,7 +88,7 @@ def model(self) -> models.TestPostgresType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestPostgresType) -> models.TestInnerPostgresType: return models.TestInnerPostgresType( - table_id=model.id, + table_id=model.id_, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -134,7 +134,7 @@ async def queries_obj(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> @pytest.mark.dependency(name="TestAttrsClasses::create") async def test_create(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: await queries_obj.create_one_test_postgres_type( - id_=model.id, + id_=model.id_, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -217,7 +217,7 @@ async def test_create_inner(self, queries_obj: queries.Queries, inner_model: mod @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestAttrsClasses::create_inner"], name="TestAttrsClasses::get_one") async def test_get_one(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_one_test_postgres_type(id_=model.id) + result = await queries_obj.get_one_test_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, models.TestPostgresType) @@ -249,20 +249,16 @@ async def test_get_one_inner_none(self, queries_obj: queries.Queries) -> None: assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestAttrsClasses::get_one_inner_none"], name="TestAttrsClasses::get_one_timestamp" - ) + @pytest.mark.dependency(depends=["TestAttrsClasses::get_one_inner_none"], name="TestAttrsClasses::get_one_timestamp") async def test_get_one_timestamp(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_one_test_timestamp_postgres_type(id_=model.id) + result = await queries_obj.get_one_test_timestamp_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestAttrsClasses::get_one_timestamp"], name="TestAttrsClasses::get_one_timestamp_none" - ) + @pytest.mark.dependency(depends=["TestAttrsClasses::get_one_timestamp"], name="TestAttrsClasses::get_one_timestamp_none") async def test_get_one_timestamp_none(self, queries_obj: queries.Queries) -> None: result = await queries_obj.get_one_test_timestamp_postgres_type(id_=0) @@ -271,7 +267,7 @@ async def test_get_one_timestamp_none(self, queries_obj: queries.Queries) -> Non @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestAttrsClasses::get_one_timestamp"], name="TestAttrsClasses::get_one_bytea") async def test_get_one_bytea(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_one_test_bytea_postgres_type(id_=model.id) + result = await queries_obj.get_one_test_bytea_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, memoryview) @@ -287,7 +283,7 @@ async def test_get_one_bytea_none(self, queries_obj: queries.Queries) -> None: @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestAttrsClasses::get_one_bytea"], name="TestAttrsClasses::get_many") async def test_get_many(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_many_test_postgres_type(id_=model.id) + result = await queries_obj.get_many_test_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -299,7 +295,7 @@ async def test_get_many(self, queries_obj: queries.Queries, model: models.TestPo @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestAttrsClasses::get_many"], name="TestAttrsClasses::get_many_timestamp") async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_many_test_timestamp_postgres_type(id_=model.id) + result = await queries_obj.get_many_test_timestamp_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -310,7 +306,7 @@ async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: mod @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestAttrsClasses::get_many_timestamp"], name="TestAttrsClasses::get_many_bytea") async def test_get_many_bytea(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_many_test_bytea_postgres_type(id_=model.id) + result = await queries_obj.get_many_test_bytea_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -326,13 +322,13 @@ async def test_get_embedded( model: models.TestPostgresType, inner_model: models.TestInnerPostgresType, ) -> None: - result = await queries_obj.get_embedded_test_postgres_type(id_=model.id) + result = await queries_obj.get_embedded_test_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, queries.GetEmbeddedTestPostgresTypeRow) assert isinstance(result.test_inner_postgres_type, models.TestInnerPostgresType) - assert result.id == model.id + assert result.id_ == model.id_ assert result.serial_test == model.serial_test assert result.serial4_test == model.serial4_test assert result.bigserial_test == model.bigserial_test @@ -389,7 +385,7 @@ async def test_get_all_embedded( model: models.TestPostgresType, inner_model: models.TestInnerPostgresType, ) -> None: - result = await queries_obj.get_all_embedded_test_postgres_type(id_=model.id) + result = await queries_obj.get_all_embedded_test_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, queries.GetAllEmbeddedTestPostgresTypeRow) @@ -401,9 +397,7 @@ async def test_get_all_embedded( assert result.test_inner_postgres_type == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestAttrsClasses::get_all_embedded"], name="TestAttrsClasses::get_all_embedded_none" - ) + @pytest.mark.dependency(depends=["TestAttrsClasses::get_all_embedded"], name="TestAttrsClasses::get_all_embedded_none") async def test_get_all_embedded_none( self, queries_obj: queries.Queries, @@ -419,7 +413,7 @@ async def test_get_many_iterator( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - results = queries_obj.get_many_test_iterator_postgres_type(id_=model.id) + results = queries_obj.get_many_test_iterator_postgres_type(id_=model.id_) async with queries_obj.conn.transaction(): async for result in results: assert result is not None @@ -434,7 +428,7 @@ async def test_delete( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - await queries_obj.delete_one_test_postgres_type(id_=model.id) + await queries_obj.delete_one_test_postgres_type(id_=model.id_) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestAttrsClasses::delete"], name="TestAttrsClasses::delete_inner") @@ -453,7 +447,7 @@ async def test_create_result( model: models.TestPostgresType, ) -> None: result = await queries_obj.create_result_one_test_postgres_type( - id_=model.id + 1, + id_=model.id_ + 1, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -500,7 +494,7 @@ async def test_update_result( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - result = await queries_obj.update_result_test_postgres_type(id_=model.id + 1) + result = await queries_obj.update_result_test_postgres_type(id_=model.id_ + 1) assert result == "UPDATE 1" @@ -511,7 +505,7 @@ async def test_delete_result( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - result = await queries_obj.delete_one_result_test_postgres_type(id_=model.id + 1) + result = await queries_obj.delete_one_result_test_postgres_type(id_=model.id_ + 1) assert result == "DELETE 1" @@ -523,7 +517,7 @@ async def test_create_rows( model: models.TestPostgresType, ) -> None: result = await queries_obj.create_rows_one_test_postgres_type( - id_=model.id + 1, + id_=model.id_ + 1, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -570,7 +564,7 @@ async def test_update_rows( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - result = await queries_obj.update_rows_test_postgres_type(id_=model.id + 1) + result = await queries_obj.update_rows_test_postgres_type(id_=model.id_ + 1) assert result == 1 @@ -581,7 +575,7 @@ async def test_delete_rows( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - result = await queries_obj.delete_one_rows_test_postgres_type(id_=model.id + 1) + result = await queries_obj.delete_one_rows_test_postgres_type(id_=model.id_ + 1) assert result == 1 @@ -596,7 +590,7 @@ async def test_copy_from( num = 3 rows: list[queries.TestCopyFromParams] = [ queries.TestCopyFromParams( - id=i, + id_=i, int_test=model.int_test, float_test=model.float_test, ) @@ -623,20 +617,16 @@ async def test_create_table( @pytest.mark.dependency( name="TestAttrsClasses::insert_type_override", ) - async def test_insert_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - await queries_obj.insert_type_override(id_=override_model.id, text_test=override_model.text_test) + async def test_insert_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.insert_type_override(id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="TestAttrsClasses::get_one_type_override", depends=["TestAttrsClasses::insert_type_override"], ) - async def test_get_one_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_type_override(id_=override_model.id) + async def test_get_one_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_) assert result is not None assert result == override_model @@ -645,10 +635,8 @@ async def test_get_one_type_override( name="TestAttrsClasses::get_one_type_override_none", depends=["TestAttrsClasses::get_one_type_override"], ) - async def test_get_one_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_type_override(id_=override_model.id - 1) + async def test_get_one_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -656,10 +644,8 @@ async def test_get_one_type_override_none( name="TestAttrsClasses::get_many_type_override", depends=["TestAttrsClasses::get_one_type_override_none"], ) - async def test_get_many_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_many_type_override(id_=override_model.id) + async def test_get_many_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_type_override(id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model @@ -668,10 +654,8 @@ async def test_get_many_type_override( name="TestAttrsClasses::get_one_text_type_override", depends=["TestAttrsClasses::get_many_type_override"], ) - async def test_get_one_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_text_type_override(id_=override_model.id) + async def test_get_one_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -680,10 +664,8 @@ async def test_get_one_text_type_override( name="TestAttrsClasses::get_one_text_type_override_none", depends=["TestAttrsClasses::get_one_text_type_override"], ) - async def test_get_one_text_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_text_type_override(id_=override_model.id - 1) + async def test_get_one_text_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -691,10 +673,8 @@ async def test_get_one_text_type_override_none( name="TestAttrsClasses::get_many_text_type_override", depends=["TestAttrsClasses::get_one_text_type_override_none"], ) - async def test_get_many_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_many_text_type_override(id_=override_model.id) + async def test_get_many_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_text_type_override(id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model.text_test @@ -703,7 +683,5 @@ async def test_get_many_text_type_override( name="TestAttrsClasses::delete_type_override", depends=["TestAttrsClasses::get_many_text_type_override"], ) - async def test_delete_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - await queries_obj.delete_type_override(id_=override_model.id) + async def test_delete_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.delete_type_override(id_=override_model.id_) diff --git a/test/driver_asyncpg/attrs/test_attrs_functions.py b/test/driver_asyncpg/attrs/test_attrs_functions.py index 622b52f8..f9168706 100644 --- a/test/driver_asyncpg/attrs/test_attrs_functions.py +++ b/test/driver_asyncpg/attrs/test_attrs_functions.py @@ -41,12 +41,12 @@ class TestAttrsFunctions: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestPostgresType: return models.TestPostgresType( - id=random.randint(1, 1000000), + id_=random.randint(1, 1000000), serial_test=1, serial4_test=2, bigserial_test=3, @@ -65,9 +65,9 @@ def model(self) -> models.TestPostgresType: bytea_test=memoryview(b"\x00\x01\x02hello"), date_test=datetime.date(2025, 1, 1), time_test=datetime.time(14, 30, 0), - timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.timezone.utc), + timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.UTC), timestamp_test=datetime.datetime(2025, 1, 1, 14, 30, 0), - timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.timezone.utc), + timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.UTC), interval_test=datetime.timedelta(days=1, hours=2, minutes=30), text_test="Lorem ipsum", varchar_test="Example varchar", @@ -87,7 +87,7 @@ def model(self) -> models.TestPostgresType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestPostgresType) -> models.TestInnerPostgresType: return models.TestInnerPostgresType( - table_id=model.id, + table_id=model.id_, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -134,7 +134,7 @@ async def test_create( ) -> None: await queries.create_one_test_postgres_type( conn=asyncpg_conn, - id_=model.id, + id_=model.id_, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -226,7 +226,7 @@ async def test_get_one( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_one_test_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_one_test_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, models.TestPostgresType) @@ -258,9 +258,7 @@ async def test_get_one_inner( assert result == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestAttrsFunctions::get_one_inner"], name="TestAttrsFunctions::get_one_inner_none" - ) + @pytest.mark.dependency(depends=["TestAttrsFunctions::get_one_inner"], name="TestAttrsFunctions::get_one_inner_none") async def test_get_one_inner_none( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], @@ -270,22 +268,18 @@ async def test_get_one_inner_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestAttrsFunctions::get_one_inner_none"], name="TestAttrsFunctions::get_one_timestamp" - ) + @pytest.mark.dependency(depends=["TestAttrsFunctions::get_one_inner_none"], name="TestAttrsFunctions::get_one_timestamp") async def test_get_one_timestamp( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_one_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_one_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestAttrsFunctions::get_one_timestamp"], name="TestAttrsFunctions::get_one_timestamp_none" - ) + @pytest.mark.dependency(depends=["TestAttrsFunctions::get_one_timestamp"], name="TestAttrsFunctions::get_one_timestamp_none") async def test_get_one_timestamp_none( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], @@ -295,24 +289,20 @@ async def test_get_one_timestamp_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestAttrsFunctions::get_one_timestamp_none"], name="TestAttrsFunctions::get_one_bytea" - ) + @pytest.mark.dependency(depends=["TestAttrsFunctions::get_one_timestamp_none"], name="TestAttrsFunctions::get_one_bytea") async def test_get_one_bytea( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_one_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_one_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, memoryview) assert result == model.bytea_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestAttrsFunctions::get_one_bytea"], name="TestAttrsFunctions::get_one_bytea_none" - ) + @pytest.mark.dependency(depends=["TestAttrsFunctions::get_one_bytea"], name="TestAttrsFunctions::get_one_bytea_none") async def test_get_one_bytea_none( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], @@ -328,7 +318,7 @@ async def test_get_many( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_many_test_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_many_test_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -344,7 +334,7 @@ async def test_get_many_timestamp( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_many_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_many_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -362,7 +352,7 @@ async def test_get_many_bytea( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_many_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_many_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -378,13 +368,13 @@ async def test_get_embedded( model: models.TestPostgresType, inner_model: models.TestInnerPostgresType, ) -> None: - result = await queries.get_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, queries.GetEmbeddedTestPostgresTypeRow) assert isinstance(result.test_inner_postgres_type, models.TestInnerPostgresType) - assert result.id == model.id + assert result.id_ == model.id_ assert result.serial_test == model.serial_test assert result.serial4_test == model.serial4_test assert result.bigserial_test == model.bigserial_test @@ -433,16 +423,14 @@ async def test_get_embedded_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestAttrsFunctions::get_embedded_none"], name="TestAttrsFunctions::get_all_embedded" - ) + @pytest.mark.dependency(depends=["TestAttrsFunctions::get_embedded_none"], name="TestAttrsFunctions::get_all_embedded") async def test_get_all_embedded( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, inner_model: models.TestInnerPostgresType, ) -> None: - result = await queries.get_all_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_all_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, queries.GetAllEmbeddedTestPostgresTypeRow) @@ -454,9 +442,7 @@ async def test_get_all_embedded( assert result.test_inner_postgres_type == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestAttrsFunctions::get_all_embedded"], name="TestAttrsFunctions::get_all_embedded_none" - ) + @pytest.mark.dependency(depends=["TestAttrsFunctions::get_all_embedded"], name="TestAttrsFunctions::get_all_embedded_none") async def test_get_all_embedded_none( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], @@ -475,13 +461,13 @@ async def test_get_many_iterator( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - results = queries.get_many_test_iterator_postgres_type(conn=asyncpg_conn, id_=model.id) + results = queries.get_many_test_iterator_postgres_type(conn=asyncpg_conn, id_=model.id_) async with asyncpg_conn.transaction(): async for result in results: assert result is not None assert isinstance(result, models.TestPostgresType) - assert result.id == model.id + assert result.id_ == model.id_ assert result.serial_test == model.serial_test assert result.serial4_test == model.serial4_test assert result.bigserial_test == model.bigserial_test @@ -525,7 +511,7 @@ async def test_delete( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - await queries.delete_one_test_postgres_type(conn=asyncpg_conn, id_=model.id) + await queries.delete_one_test_postgres_type(conn=asyncpg_conn, id_=model.id_) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestAttrsFunctions::delete"], name="TestAttrsFunctions::delete_inner") @@ -545,7 +531,7 @@ async def test_create_result( ) -> None: result = await queries.create_result_one_test_postgres_type( conn=asyncpg_conn, - id_=model.id + 1, + id_=model.id_ + 1, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -592,7 +578,7 @@ async def test_update_result( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.update_result_test_postgres_type(conn=asyncpg_conn, id_=model.id + 1) + result = await queries.update_result_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) assert result == "UPDATE 1" @@ -603,7 +589,7 @@ async def test_delete_result( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.delete_one_result_test_postgres_type(conn=asyncpg_conn, id_=model.id + 1) + result = await queries.delete_one_result_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) assert result == "DELETE 1" @@ -616,7 +602,7 @@ async def test_create_rows( ) -> None: result = await queries.create_rows_one_test_postgres_type( conn=asyncpg_conn, - id_=model.id + 1, + id_=model.id_ + 1, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -663,7 +649,7 @@ async def test_update_rows( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.update_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id + 1) + result = await queries.update_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) assert result == 1 @@ -674,7 +660,7 @@ async def test_delete_rows( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.delete_one_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id + 1) + result = await queries.delete_one_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) assert result == 1 @@ -688,7 +674,7 @@ async def test_copy_from( num = 3 rows: list[queries.TestCopyFromParams] = [ queries.TestCopyFromParams( - id=i, + id_=i, int_test=model.int_test, float_test=model.float_test, ) @@ -714,20 +700,16 @@ async def test_create_table( @pytest.mark.dependency( name="TestAttrsFunctions::insert_type_override", ) - async def test_insert_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - await queries.insert_type_override(conn=asyncpg_conn, id_=override_model.id, text_test=override_model.text_test) + async def test_insert_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + await queries.insert_type_override(conn=asyncpg_conn, id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="TestAttrsFunctions::get_one_type_override", depends=["TestAttrsFunctions::insert_type_override"], ) - async def test_get_one_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_get_one_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id_) assert result is not None assert result == override_model @@ -736,10 +718,8 @@ async def test_get_one_type_override( name="TestAttrsFunctions::get_one_type_override_none", depends=["TestAttrsFunctions::get_one_type_override"], ) - async def test_get_one_type_override_none( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id - 1) + async def test_get_one_type_override_none(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -747,10 +727,8 @@ async def test_get_one_type_override_none( name="TestAttrsFunctions::get_many_type_override", depends=["TestAttrsFunctions::get_one_type_override_none"], ) - async def test_get_many_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_many_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_get_many_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_type_override(conn=asyncpg_conn, id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model @@ -759,10 +737,8 @@ async def test_get_many_type_override( name="TestAttrsFunctions::get_one_text_type_override", depends=["TestAttrsFunctions::get_many_type_override"], ) - async def test_get_one_text_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_get_one_text_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -771,10 +747,8 @@ async def test_get_one_text_type_override( name="TestAttrsFunctions::get_one_text_type_override_none", depends=["TestAttrsFunctions::get_one_text_type_override"], ) - async def test_get_one_text_type_override_none( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id - 1) + async def test_get_one_text_type_override_none(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -782,10 +756,8 @@ async def test_get_one_text_type_override_none( name="TestAttrsFunctions::get_many_text_type_override", depends=["TestAttrsFunctions::get_one_text_type_override_none"], ) - async def test_get_many_text_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_many_text_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_get_many_text_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_text_type_override(conn=asyncpg_conn, id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model.text_test @@ -794,7 +766,5 @@ async def test_get_many_text_type_override( name="TestAttrsFunctions::delete_type_override", depends=["TestAttrsFunctions::get_many_text_type_override"], ) - async def test_delete_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - await queries.delete_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_delete_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + await queries.delete_type_override(conn=asyncpg_conn, id_=override_model.id_) diff --git a/test/driver_asyncpg/dataclass/classes/__init__.py b/test/driver_asyncpg/dataclass/classes/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_asyncpg/dataclass/classes/__init__.py +++ b/test/driver_asyncpg/dataclass/classes/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_asyncpg/dataclass/classes/enums.py b/test/driver_asyncpg/dataclass/classes/enums.py new file mode 100644 index 00000000..d49ac611 --- /dev/null +++ b/test/driver_asyncpg/dataclass/classes/enums.py @@ -0,0 +1,23 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing enums.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("TestMood",) + +import enum +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +class TestMood(enum.StrEnum): + """Enum representing TestMood.""" + + SAD = "sad" + OK = "ok" + HAPPY = "happy" diff --git a/test/driver_asyncpg/dataclass/classes/models.py b/test/driver_asyncpg/dataclass/classes/models.py index 7cc9cf46..d03e0d3a 100644 --- a/test/driver_asyncpg/dataclass/classes/models.py +++ b/test/driver_asyncpg/dataclass/classes/models.py @@ -1,11 +1,14 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( + "TestEnumOverride", + "TestEnumType", "TestInnerPostgresType", "TestPostgresType", "TestTypeOverride", @@ -16,12 +19,41 @@ if typing.TYPE_CHECKING: from collections import UserString + from test.driver_asyncpg.dataclass.classes import enums import collections.abc import datetime import decimal import uuid +@dataclasses.dataclass() +class TestEnumOverride: + """Model representing TestEnumOverride. + + Attributes: + id_: int + mood_test: str + """ + + id_: int + mood_test: str + + +@dataclasses.dataclass() +class TestEnumType: + """Model representing TestEnumType. + + Attributes: + id_: int + mood: enums.TestMood + maybe_mood: enums.TestMood | None + """ + + id_: int + mood: enums.TestMood + maybe_mood: enums.TestMood | None + + @dataclasses.dataclass() class TestInnerPostgresType: """Model representing TestInnerPostgresType. @@ -108,7 +140,7 @@ class TestPostgresType: """Model representing TestPostgresType. Attributes: - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -146,7 +178,7 @@ class TestPostgresType: ltxtquery_test: str """ - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -189,9 +221,9 @@ class TestTypeOverride: """Model representing TestTypeOverride. Attributes: - id: int + id_: int text_test: UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_asyncpg/dataclass/classes/queries.py b/test/driver_asyncpg/dataclass/classes/queries.py index 2efd7cb1..3d68530b 100644 --- a/test/driver_asyncpg/dataclass/classes/queries.py +++ b/test/driver_asyncpg/dataclass/classes/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -15,7 +17,6 @@ from collections import UserString import dataclasses -import datetime import operator import typing @@ -23,35 +24,24 @@ import asyncpg import asyncpg.cursor import collections.abc + import datetime import decimal import uuid - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None - ConnectionLike: typing.TypeAlias = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] +from test.driver_asyncpg.dataclass.classes import enums from test.driver_asyncpg.dataclass.classes import models -@dataclasses.dataclass() -class GetAllEmbeddedTestPostgresTypeRow: - """Model representing GetAllEmbeddedTestPostgresTypeRow. - - Attributes: - test_postgres_type: models.TestPostgresType - test_inner_postgres_type: models.TestInnerPostgresType - """ - - test_postgres_type: models.TestPostgresType - test_inner_postgres_type: models.TestInnerPostgresType - - @dataclasses.dataclass() class GetEmbeddedTestPostgresTypeRow: """Model representing GetEmbeddedTestPostgresTypeRow. Attributes: - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -90,7 +80,7 @@ class GetEmbeddedTestPostgresTypeRow: test_inner_postgres_type: models.TestInnerPostgresType """ - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -129,63 +119,94 @@ class GetEmbeddedTestPostgresTypeRow: test_inner_postgres_type: models.TestInnerPostgresType +@dataclasses.dataclass() +class GetAllEmbeddedTestPostgresTypeRow: + """Model representing GetAllEmbeddedTestPostgresTypeRow. + + Attributes: + test_postgres_type: models.TestPostgresType + test_inner_postgres_type: models.TestInnerPostgresType + """ + + test_postgres_type: models.TestPostgresType + test_inner_postgres_type: models.TestInnerPostgresType + + @dataclasses.dataclass() class TestCopyFromParams: """Model representing TestCopyFromParams. Attributes: - id: int + id_: int float_test: float int_test: int """ - id: int + id_: int float_test: float int_test: int -CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec -INSERT INTO test_inner_postgres_types (table_id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) -VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) +GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one +SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_inner_postgres_types +WHERE table_id = $1 LIMIT 1 +""" + +GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 +""" + +GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 """ CREATE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresType :exec @@ -232,6 +253,62 @@ class TestCopyFromParams: $33, $34, $35, $36) """ +CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec +INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec +DELETE +FROM test_inner_postgres_types +WHERE test_inner_postgres_types.table_id = $1 +""" + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateResultOneTestPostgresType :execresult INSERT INTO test_postgres_types (id, serial_test, @@ -276,6 +353,18 @@ class TestCopyFromParams: $33, $34, $35, $36) """ +UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateRowsOneTestPostgresType :execrows INSERT INTO test_postgres_types (id, serial_test, @@ -320,6 +409,18 @@ class TestCopyFromParams: $33, $34, $35, $36) """ +UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows CREATE TABLE test_create_rows_table ( @@ -328,28 +429,32 @@ class TestCopyFromParams: ) """ -DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom +INSERT INTO test_copy_from (id, + float_test, int_test) +VALUES ($1, $2, $3) """ -DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec +INSERT INTO test_type_override ( + id, text_test +) VALUES ($1 ,$2) """ -DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec -DELETE -FROM test_inner_postgres_types -WHERE test_inner_postgres_types.table_id = $1 +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = $1 """ -DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 """ DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec @@ -358,113 +463,37 @@ class TestCopyFromParams: WHERE test_type_override.id = $1 """ -GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one -SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id -WHERE test_postgres_types.id = $1 +INSERT_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: InsertOneTestEnumType :exec +INSERT INTO test_enum_types (id, mood, maybe_mood) +VALUES ($1, $2, $3) """ -GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one -SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id -WHERE test_postgres_types.id = $1 -""" - -GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many -SELECT bytea_test -FROM test_postgres_types -WHERE id = $1 LIMIT 2 -""" - -GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types +GET_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: GetOneTestEnumType :one +SELECT id, mood, maybe_mood +FROM test_enum_types WHERE id = $1 """ -GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types +GET_ONE_TEST_ENUM_VALUE: typing.Final[str] = """-- name: GetOneTestEnumValue :one +SELECT mood +FROM test_enum_types WHERE id = $1 """ -GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many -SELECT timestamp_test -FROM test_postgres_types -WHERE id = $1 LIMIT 2 -""" - -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one -SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_inner_postgres_types -WHERE table_id = $1 LIMIT 1 -""" - -GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one -SELECT bytea_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one -SELECT timestamp_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = $1 -""" - -INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec -INSERT INTO test_type_override ( - id, text_test -) VALUES ($1 ,$2) -""" - -TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom -INSERT INTO test_copy_from (id, - float_test, int_test) -VALUES ($1, $2, $3) +GET_MANY_TEST_ENUM_TYPES: typing.Final[str] = """-- name: GetManyTestEnumTypes :many +SELECT id, mood, maybe_mood +FROM test_enum_types +ORDER BY id """ -UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult -UPDATE test_postgres_types -SET serial_test = 187 -WHERE test_postgres_types.id = $1 -""" - -UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows -UPDATE test_postgres_types -SET serial_test = 187 -WHERE test_postgres_types.id = $1 +DELETE_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: DeleteOneTestEnumType :execrows +DELETE +FROM test_enum_types +WHERE id = $1 """ -T = typing.TypeVar("T") - - -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db.""" __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") @@ -511,9 +540,11 @@ def __await__( Returns: A sequence of decoded objects of type `T`. """ + async def _wrapper() -> collections.abc.Sequence[T]: result = await self._conn.fetch(self._sql, *self._args) return [self._decode_hook(row) for row in result] + return _wrapper().__await__() async def __anext__(self) -> T: @@ -560,182 +591,549 @@ def conn(self) -> ConnectionLike: """ return self._conn - async def create_one_test_postgres_inner_type(self, *, table_id: int, serial_test: int | None, serial4_test: int | None, bigserial_test: int | None, smallserial_test: int | None, int_test: int | None, bigint_test: int | None, smallint_test: int | None, float_test: float | None, double_precision_test: float | None, real_test: float | None, numeric_test: decimal.Decimal | None, money_test: str | None, bool_test: bool | None, json_test: str | None, jsonb_test: str | None, bytea_test: memoryview | None, date_test: datetime.date | None, time_test: datetime.time | None, timetz_test: datetime.time | None, timestamp_test: datetime.datetime | None, timestamptz_test: datetime.datetime | None, interval_test: datetime.timedelta | None, text_test: str | None, varchar_test: str | None, bpchar_test: str | None, char_test: str | None, citext_test: str | None, uuid_test: uuid.UUID | None, inet_test: str | None, cidr_test: str | None, macaddr_test: str | None, macaddr8_test: str | None, ltree_test: str | None, lquery_test: str | None, ltxtquery_test: str | None) -> None: - """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. + async def get_one_test_postgres_type(self, *, id_: int) -> models.TestPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. ```sql - INSERT INTO test_inner_postgres_types (table_id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Args: + id_: int. + + Returns: + Result of type `models.TestPostgresType` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + async def get_one_inner_test_postgres_type(self, *, table_id: int) -> models.TestInnerPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + + ```sql + SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_inner_postgres_types + WHERE table_id = $1 LIMIT 1 ``` Args: table_id: int. - serial_test: int | None. - serial4_test: int | None. - bigserial_test: int | None. - smallserial_test: int | None. - int_test: int | None. - bigint_test: int | None. - smallint_test: int | None. - float_test: float | None. - double_precision_test: float | None. - real_test: float | None. - numeric_test: decimal.Decimal | None. - money_test: str | None. - bool_test: bool | None. - json_test: str | None. - jsonb_test: str | None. - bytea_test: memoryview | None. - date_test: datetime.date | None. - time_test: datetime.time | None. - timetz_test: datetime.time | None. - timestamp_test: datetime.datetime | None. - timestamptz_test: datetime.datetime | None. - interval_test: datetime.timedelta | None. - text_test: str | None. - varchar_test: str | None. - bpchar_test: str | None. - char_test: str | None. - citext_test: str | None. - uuid_test: uuid.UUID | None. - inet_test: str | None. - cidr_test: str | None. - macaddr_test: str | None. - macaddr8_test: str | None. - ltree_test: str | None. - lquery_test: str | None. - ltxtquery_test: str | None. + + Returns: + Result of type `models.TestInnerPostgresType` fetched from the db. Will be `None` if not found. """ - await self._conn.execute(CREATE_ONE_TEST_POSTGRES_INNER_TYPE, table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + row = await self._conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + if row is None: + return None + return models.TestInnerPostgresType( + table_id=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]) if row[16] is not None else None, + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]) if row[29] is not None else None, + cidr_test=str(row[30]) if row[30] is not None else None, + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) - async def create_one_test_postgres_type(self, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> None: - """Execute SQL query with `name: CreateOneTestPostgresType :exec`. + async def get_one_test_timestamp_postgres_type(self, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. ```sql - INSERT INTO test_postgres_types (id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 ``` Args: id_: int. - serial_test: int. - serial4_test: int. - bigserial_test: int. - smallserial_test: int. - int_test: int. - bigint_test: int. - smallint_test: int. - float_test: float. - double_precision_test: float. - real_test: float. - numeric_test: decimal.Decimal. - money_test: str. - bool_test: bool. - json_test: str. - jsonb_test: str. - bytea_test: memoryview. - date_test: datetime.date. - time_test: datetime.time. - timetz_test: datetime.time. - timestamp_test: datetime.datetime. - timestamptz_test: datetime.datetime. - interval_test: datetime.timedelta. - text_test: str. - varchar_test: str. - bpchar_test: str. - char_test: str. - citext_test: str. - uuid_test: uuid.UUID. - inet_test: str. - cidr_test: str. - macaddr_test: str. - macaddr8_test: str. - ltree_test: str. - lquery_test: str. - ltxtquery_test: str. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) + if row is None: + return None + return row[0] + + async def get_one_test_bytea_postgres_type(self, *, id_: int) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Args: + id_: int. + + Returns: + Result of type `memoryview` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) + if row is None: + return None + return memoryview(row[0]) + + def get_many_test_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestPostgresType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(self._conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + + def get_many_test_iterator_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestPostgresType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(self._conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) + + def get_many_test_timestamp_postgres_type(self, *, id_: int) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. + + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + + def get_many_test_bytea_postgres_type(self, *, id_: int) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> memoryview: + return memoryview(row[0]) + + return QueryResults(self._conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + + async def get_embedded_test_postgres_type(self, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Args: + id_: int. + + Returns: + Result of type `GetEmbeddedTestPostgresTypeRow` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetEmbeddedTestPostgresTypeRow( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + async def get_all_embedded_test_postgres_type(self, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Args: + id_: int. + + Returns: + Result of type `GetAllEmbeddedTestPostgresTypeRow` fetched from the db. Will be `None` if not found. """ - await self._conn.execute(CREATE_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + row = await self._conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetAllEmbeddedTestPostgresTypeRow( + test_postgres_type=models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ), + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) - async def create_result_one_test_postgres_type(self, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> str: - """Execute and return the result of SQL query with `name: CreateResultOneTestPostgresType :execresult`. + async def create_one_test_postgres_type( + self, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, + ) -> None: + """Execute SQL query with `name: CreateOneTestPostgresType :exec`. ```sql INSERT INTO test_postgres_types (id, @@ -818,14 +1216,280 @@ async def create_result_one_test_postgres_type(self, *, id_: int, serial_test: i ltree_test: str. lquery_test: str. ltxtquery_test: str. + """ + await self._conn.execute( + CREATE_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) - Returns: - The result of type `str` returned when executing the query. + async def create_one_test_postgres_inner_type( + self, + *, + table_id: int, + serial_test: int | None, + serial4_test: int | None, + bigserial_test: int | None, + smallserial_test: int | None, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + float_test: float | None, + double_precision_test: float | None, + real_test: float | None, + numeric_test: decimal.Decimal | None, + money_test: str | None, + bool_test: bool | None, + json_test: str | None, + jsonb_test: str | None, + bytea_test: memoryview | None, + date_test: datetime.date | None, + time_test: datetime.time | None, + timetz_test: datetime.time | None, + timestamp_test: datetime.datetime | None, + timestamptz_test: datetime.datetime | None, + interval_test: datetime.timedelta | None, + text_test: str | None, + varchar_test: str | None, + bpchar_test: str | None, + char_test: str | None, + citext_test: str | None, + uuid_test: uuid.UUID | None, + inet_test: str | None, + cidr_test: str | None, + macaddr_test: str | None, + macaddr8_test: str | None, + ltree_test: str | None, + lquery_test: str | None, + ltxtquery_test: str | None, + ) -> None: + """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. + + ```sql + INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Args: + table_id: int. + serial_test: int | None. + serial4_test: int | None. + bigserial_test: int | None. + smallserial_test: int | None. + int_test: int | None. + bigint_test: int | None. + smallint_test: int | None. + float_test: float | None. + double_precision_test: float | None. + real_test: float | None. + numeric_test: decimal.Decimal | None. + money_test: str | None. + bool_test: bool | None. + json_test: str | None. + jsonb_test: str | None. + bytea_test: memoryview | None. + date_test: datetime.date | None. + time_test: datetime.time | None. + timetz_test: datetime.time | None. + timestamp_test: datetime.datetime | None. + timestamptz_test: datetime.datetime | None. + interval_test: datetime.timedelta | None. + text_test: str | None. + varchar_test: str | None. + bpchar_test: str | None. + char_test: str | None. + citext_test: str | None. + uuid_test: uuid.UUID | None. + inet_test: str | None. + cidr_test: str | None. + macaddr_test: str | None. + macaddr8_test: str | None. + ltree_test: str | None. + lquery_test: str | None. + ltxtquery_test: str | None. """ - return await self._conn.execute(CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + await self._conn.execute( + CREATE_ONE_TEST_POSTGRES_INNER_TYPE, + table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) - async def create_rows_one_test_postgres_type(self, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> int: - """Execute SQL query with `name: CreateRowsOneTestPostgresType :execrows` and return the number of affected rows. + async def delete_one_test_postgres_type(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + + Args: + id_: int. + """ + await self._conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) + + async def delete_one_test_postgres_inner_type(self, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. + + ```sql + DELETE + FROM test_inner_postgres_types + WHERE test_inner_postgres_types.table_id = $1 + ``` + + Args: + table_id: int. + """ + await self._conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) + + async def create_result_one_test_postgres_type( + self, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, + ) -> str: + """Execute and return the result of SQL query with `name: CreateResultOneTestPostgresType :execresult`. ```sql INSERT INTO test_postgres_types (id, @@ -910,34 +1574,54 @@ async def create_rows_one_test_postgres_type(self, *, id_: int, serial_test: int ltxtquery_test: str. Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + The result of type `str` returned when executing the query. """ - r = await self._conn.execute(CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - - async def create_rows_table(self) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. - - ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL + return await self._conn.execute( + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, ) - ``` - - Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. - """ - r = await self._conn.execute(CREATE_ROWS_TABLE) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - async def delete_one_result_test_postgres_type(self, *, id_: int) -> str: - """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. + async def update_result_test_postgres_type(self, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. ```sql - DELETE - FROM test_postgres_types + UPDATE test_postgres_types + SET serial_test = 187 WHERE test_postgres_types.id = $1 ``` @@ -947,10 +1631,10 @@ async def delete_one_result_test_postgres_type(self, *, id_: int) -> str: Returns: The result of type `str` returned when executing the query. """ - return await self._conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) + return await self._conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) - async def delete_one_rows_test_postgres_type(self, *, id_: int) -> int: - """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. + async def delete_one_result_test_postgres_type(self, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. ```sql DELETE @@ -962,81 +1646,184 @@ async def delete_one_rows_test_postgres_type(self, *, id_: int) -> int: id_: int. Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. - """ - r = await self._conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - - async def delete_one_test_postgres_inner_type(self, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. - - ```sql - DELETE - FROM test_inner_postgres_types - WHERE test_inner_postgres_types.table_id = $1 - ``` - - Args: - table_id: int. - """ - await self._conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) - - async def delete_one_test_postgres_type(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. - - ```sql - DELETE - FROM test_postgres_types - WHERE test_postgres_types.id = $1 - ``` - - Args: - id_: int. - """ - await self._conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) - - async def delete_type_override(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. - - ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = $1 - ``` - - Args: - id_: int. + The result of type `str` returned when executing the query. """ - await self._conn.execute(DELETE_TYPE_OVERRIDE, id_) + return await self._conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) - async def get_all_embedded_test_postgres_type(self, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: - """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. + async def create_rows_one_test_postgres_type( + self, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, + ) -> int: + """Execute SQL query with `name: CreateRowsOneTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test - FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id - WHERE test_postgres_types.id = $1 + INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) ``` Args: id_: int. + serial_test: int. + serial4_test: int. + bigserial_test: int. + smallserial_test: int. + int_test: int. + bigint_test: int. + smallint_test: int. + float_test: float. + double_precision_test: float. + real_test: float. + numeric_test: decimal.Decimal. + money_test: str. + bool_test: bool. + json_test: str. + jsonb_test: str. + bytea_test: memoryview. + date_test: datetime.date. + time_test: datetime.time. + timetz_test: datetime.time. + timestamp_test: datetime.datetime. + timestamptz_test: datetime.datetime. + interval_test: datetime.timedelta. + text_test: str. + varchar_test: str. + bpchar_test: str. + char_test: str. + citext_test: str. + uuid_test: uuid.UUID. + inet_test: str. + cidr_test: str. + macaddr_test: str. + macaddr8_test: str. + ltree_test: str. + lquery_test: str. + ltxtquery_test: str. Returns: - Result of type `GetAllEmbeddedTestPostgresTypeRow` fetched from the db. Will be `None` if not found. + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - row = await self._conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return GetAllEmbeddedTestPostgresTypeRow(test_postgres_type=models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]), test_inner_postgres_type=models.TestInnerPostgresType(table_id=row[36], serial_test=row[37], serial4_test=row[38], bigserial_test=row[39], smallserial_test=row[40], int_test=row[41], bigint_test=row[42], smallint_test=row[43], float_test=row[44], double_precision_test=row[45], real_test=row[46], numeric_test=row[47], money_test=row[48], bool_test=row[49], json_test=row[50], jsonb_test=row[51], bytea_test=memoryview(row[52]) if row[52] is not None else None, date_test=row[53], time_test=row[54], timetz_test=row[55], timestamp_test=row[56], timestamptz_test=row[57], interval_test=row[58], text_test=row[59], varchar_test=row[60], bpchar_test=row[61], char_test=row[62], citext_test=row[63], uuid_test=row[64], inet_test=str(row[65]) if row[65] is not None else None, cidr_test=str(row[66]) if row[66] is not None else None, macaddr_test=row[67], macaddr8_test=row[68], ltree_test=row[69], lquery_test=row[70], ltxtquery_test=row[71])) + r = await self._conn.execute( + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - async def get_embedded_test_postgres_type(self, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: - """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. + async def update_rows_test_postgres_type(self, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test - FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + UPDATE test_postgres_types + SET serial_test = 187 WHERE test_postgres_types.id = $1 ``` @@ -1044,101 +1831,92 @@ async def get_embedded_test_postgres_type(self, *, id_: int) -> GetEmbeddedTestP id_: int. Returns: - Result of type `GetEmbeddedTestPostgresTypeRow` fetched from the db. Will be `None` if not found. + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - row = await self._conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return GetEmbeddedTestPostgresTypeRow(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35], test_inner_postgres_type=models.TestInnerPostgresType(table_id=row[36], serial_test=row[37], serial4_test=row[38], bigserial_test=row[39], smallserial_test=row[40], int_test=row[41], bigint_test=row[42], smallint_test=row[43], float_test=row[44], double_precision_test=row[45], real_test=row[46], numeric_test=row[47], money_test=row[48], bool_test=row[49], json_test=row[50], jsonb_test=row[51], bytea_test=memoryview(row[52]) if row[52] is not None else None, date_test=row[53], time_test=row[54], timetz_test=row[55], timestamp_test=row[56], timestamptz_test=row[57], interval_test=row[58], text_test=row[59], varchar_test=row[60], bpchar_test=row[61], char_test=row[62], citext_test=row[63], uuid_test=row[64], inet_test=str(row[65]) if row[65] is not None else None, cidr_test=str(row[66]) if row[66] is not None else None, macaddr_test=row[67], macaddr8_test=row[68], ltree_test=row[69], lquery_test=row[70], ltxtquery_test=row[71])) + r = await self._conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - def get_many_test_bytea_postgres_type(self, *, id_: int) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. + async def delete_one_rows_test_postgres_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT bytea_test + DELETE FROM test_postgres_types - WHERE id = $1 LIMIT 2 + WHERE test_postgres_types.id = $1 ``` Args: id_: int. Returns: - Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - def _decode_hook(row: asyncpg.Record) -> memoryview: - return memoryview(row[0]) - return QueryResults[memoryview](self._conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + r = await self._conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - def get_many_test_iterator_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: - """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. + async def create_rows_table(self) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) ``` - Args: - id_: int. - Returns: - Helper class of type `QueryResults[models.TestPostgresType]` that allows both iteration and normal fetching of data from the db. + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) - return QueryResults[models.TestPostgresType](self._conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) - - def get_many_test_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: - """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. + r = await self._conn.execute(CREATE_ROWS_TABLE) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 - ``` + async def test_copy_from(self, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. Args: - id_: int. + params: collections.abc.Sequence[TestCopyFromParams]. + A list of params for rows that should be inserted. Returns: - Helper class of type `QueryResults[models.TestPostgresType]` that allows both iteration and normal fetching of data from the db. + The number (`int`) of affected rows. """ - def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) - return QueryResults[models.TestPostgresType](self._conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + records = [(param.id_, param.float_test, param.int_test) for param in params] + r = await self._conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - def get_many_test_timestamp_postgres_type(self, *, id_: int) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. + async def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: + """Execute SQL query with `name: InsertTypeOverride :exec`. ```sql - SELECT timestamp_test - FROM test_postgres_types - WHERE id = $1 LIMIT 2 + INSERT INTO test_type_override ( + id, text_test + ) VALUES ($1 ,$2) ``` Args: id_: int. - - Returns: - Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + text_test: UserString | None. """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + await self._conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test) if text_test is not None else None) - def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + SELECT id, text_test FROM test_type_override WHERE id = $1 ``` Args: id_: int. Returns: - Helper class of type `QueryResults[UserString]` that allows both iteration and normal fetching of data from the db. + Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. """ - return QueryResults[UserString](self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, operator.itemgetter(0), id_) + row = await self._conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. @@ -1153,182 +1931,143 @@ def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOve Returns: Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: asyncpg.Record) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - return QueryResults[models.TestTypeOverride](self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - async def get_one_inner_test_postgres_type(self, *, table_id: int) -> models.TestInnerPostgresType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + return QueryResults(self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + async def get_one_text_type_override(self, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_inner_postgres_types - WHERE table_id = $1 LIMIT 1 + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 ``` Args: - table_id: int. + id_: int. Returns: - Result of type `models.TestInnerPostgresType` fetched from the db. Will be `None` if not found. + Result of type `UserString` fetched from the db. Will be `None` if not found. """ - row = await self._conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + row = await self._conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) if row is None: return None - return models.TestInnerPostgresType(table_id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]) if row[16] is not None else None, date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]) if row[29] is not None else None, cidr_test=str(row[30]) if row[30] is not None else None, macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) + return UserString(row[0]) if row[0] is not None else None - async def get_one_test_bytea_postgres_type(self, *, id_: int) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. + def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. ```sql - SELECT bytea_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 ``` Args: id_: int. Returns: - Result of type `memoryview` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[UserString | None]` that allows both iteration and normal fetching of data from the db. """ - row = await self._conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) - if row is None: - return None - return memoryview(row[0]) - async def get_one_test_postgres_type(self, *, id_: int) -> models.TestPostgresType | None: - """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. + def _decode_hook(row: asyncpg.Record) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + async def delete_type_override(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + DELETE + FROM test_type_override + WHERE test_type_override.id = $1 ``` Args: id_: int. - - Returns: - Result of type `models.TestPostgresType` fetched from the db. Will be `None` if not found. """ - row = await self._conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) + await self._conn.execute(DELETE_TYPE_OVERRIDE, id_) - async def get_one_test_timestamp_postgres_type(self, *, id_: int) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. + async def insert_one_test_enum_type(self, *, id_: int, mood: enums.TestMood, maybe_mood: enums.TestMood | None) -> None: + """Execute SQL query with `name: InsertOneTestEnumType :exec`. ```sql - SELECT timestamp_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + INSERT INTO test_enum_types (id, mood, maybe_mood) + VALUES ($1, $2, $3) ``` Args: id_: int. - - Returns: - Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + mood: enums.TestMood. + maybe_mood: enums.TestMood | None. """ - row = await self._conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) - if row is None: - return None - return row[0] + await self._conn.execute(INSERT_ONE_TEST_ENUM_TYPE, id_, mood, maybe_mood) - async def get_one_text_type_override(self, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + async def get_one_test_enum_type(self, *, id_: int) -> models.TestEnumType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumType :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + SELECT id, mood, maybe_mood + FROM test_enum_types + WHERE id = $1 ``` Args: id_: int. Returns: - Result of type `UserString` fetched from the db. Will be `None` if not found. + Result of type `models.TestEnumType` fetched from the db. Will be `None` if not found. """ - row = await self._conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) + row = await self._conn.fetchrow(GET_ONE_TEST_ENUM_TYPE, id_) if row is None: return None - return row[0] + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) - async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + async def get_one_test_enum_value(self, *, id_: int) -> enums.TestMood | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumValue :one`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = $1 + SELECT mood + FROM test_enum_types + WHERE id = $1 ``` Args: id_: int. Returns: - Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. + Result of type `enums.TestMood` fetched from the db. Will be `None` if not found. """ - row = await self._conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + row = await self._conn.fetchrow(GET_ONE_TEST_ENUM_VALUE, id_) if row is None: return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + return enums.TestMood(row[0]) - async def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: - """Execute SQL query with `name: InsertTypeOverride :exec`. + def get_many_test_enum_types(self) -> QueryResults[models.TestEnumType]: + """Fetch many from the db using the SQL query with `name: GetManyTestEnumTypes :many`. ```sql - INSERT INTO test_type_override ( - id, text_test - ) VALUES ($1 ,$2) + SELECT id, mood, maybe_mood + FROM test_enum_types + ORDER BY id ``` - Args: - id_: int. - text_test: UserString | None. - """ - await self._conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test)) - - async def test_copy_from(self, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: - """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. - - Args: - params: collections.abc.Sequence[TestCopyFromParams]. - A list of params for rows that should be inserted. - Returns: - The number (`int`) of affected rows. + Helper class of type `QueryResults[models.TestEnumType]` that allows both iteration and normal fetching of data from the db. """ - records = [ - (param.id, param.float_test, param.int_test) - for param in params - ] - r = await self._conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - - async def update_result_test_postgres_type(self, *, id_: int) -> str: - """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. - - ```sql - UPDATE test_postgres_types - SET serial_test = 187 - WHERE test_postgres_types.id = $1 - ``` - Args: - id_: int. + def _decode_hook(row: asyncpg.Record) -> models.TestEnumType: + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) - Returns: - The result of type `str` returned when executing the query. - """ - return await self._conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) + return QueryResults(self._conn, GET_MANY_TEST_ENUM_TYPES, _decode_hook) - async def update_rows_test_postgres_type(self, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. + async def delete_one_test_enum_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneTestEnumType :execrows` and return the number of affected rows. ```sql - UPDATE test_postgres_types - SET serial_test = 187 - WHERE test_postgres_types.id = $1 + DELETE + FROM test_enum_types + WHERE id = $1 ``` Args: @@ -1337,5 +2076,5 @@ async def update_rows_test_postgres_type(self, *, id_: int) -> int: Returns: The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - r = await self._conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + r = await self._conn.execute(DELETE_ONE_TEST_ENUM_TYPE, id_) return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 diff --git a/test/driver_asyncpg/dataclass/classes/queries_copy_override.py b/test/driver_asyncpg/dataclass/classes/queries_copy_override.py new file mode 100644 index 00000000..326f8a35 --- /dev/null +++ b/test/driver_asyncpg/dataclass/classes/queries_copy_override.py @@ -0,0 +1,112 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_copy_override.sql +"""Module containing queries from file queries_copy_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "CopyOverrideRowsParams", + "QueriesCopyOverride", +) + +import dataclasses +import decimal +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import collections.abc + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + + +@dataclasses.dataclass() +class CopyOverrideRowsParams: + """Model representing CopyOverrideRowsParams. + + Attributes: + id_: int + amount: float + """ + + id_: int + amount: float + + +COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CopyOverrideRows :copyfrom +INSERT INTO test_copy_override (id, amount) VALUES ($1, $2) +""" + +COUNT_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CountCopyOverrideRows :one +SELECT count(*) FROM test_copy_override +""" + +DELETE_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: DeleteCopyOverrideRows :exec +DELETE FROM test_copy_override +""" + + +class QueriesCopyOverride: + """Queries from file queries_copy_override.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: ConnectionLike) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> ConnectionLike: + """Connection object used to make queries. + + Returns: + Connection object of type `ConnectionLike` used to make queries. + """ + return self._conn + + async def copy_override_rows(self, *, params: collections.abc.Sequence[CopyOverrideRowsParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: CopyOverrideRows :copyfrom` and return the number of affected rows. + + Args: + params: collections.abc.Sequence[CopyOverrideRowsParams]. + A list of params for rows that should be inserted. + + Returns: + The number (`int`) of affected rows. + """ + records = [(param.id_, decimal.Decimal(param.amount)) for param in params] + r = await self._conn.copy_records_to_table("test_copy_override", columns=["id", "amount"], records=records) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + async def count_copy_override_rows(self) -> int | None: + """Fetch one from the db using the SQL query with `name: CountCopyOverrideRows :one`. + + ```sql + SELECT count(*) FROM test_copy_override + ``` + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(COUNT_COPY_OVERRIDE_ROWS) + if row is None: + return None + return row[0] + + async def delete_copy_override_rows(self) -> None: + """Execute SQL query with `name: DeleteCopyOverrideRows :exec`. + + ```sql + DELETE FROM test_copy_override + ``` + + """ + await self._conn.execute(DELETE_COPY_OVERRIDE_ROWS) diff --git a/test/driver_asyncpg/dataclass/classes/queries_enum_override.py b/test/driver_asyncpg/dataclass/classes/queries_enum_override.py new file mode 100644 index 00000000..ff12e568 --- /dev/null +++ b/test/driver_asyncpg/dataclass/classes/queries_enum_override.py @@ -0,0 +1,211 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_enum_override.sql +"""Module containing queries from file queries_enum_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "QueriesEnumOverride", + "QueryResults", +) + +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import asyncpg.cursor + import collections.abc + + type QueryResultsArgsType = int | float | str | memoryview | collections.abc.Sequence[QueryResultsArgsType] | None + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + +from test.driver_asyncpg.dataclass.classes import enums +from test.driver_asyncpg.dataclass.classes import models + + +INSERT_ENUM_OVERRIDE: typing.Final[str] = """-- name: InsertEnumOverride :exec +INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) +""" + +GET_ENUM_OVERRIDE_MOOD: typing.Final[str] = """-- name: GetEnumOverrideMood :one +SELECT mood_test FROM test_enum_override WHERE id = $1 +""" + +LIST_ENUM_OVERRIDE_BY_IDS: typing.Final[str] = """-- name: ListEnumOverrideByIds :many +SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) +""" + +COUNT_ENUM_OVERRIDE_BY_MOODS: typing.Final[str] = """-- name: CountEnumOverrideByMoods :one +SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: ConnectionLike, + sql: str, + decode_hook: collections.abc.Callable[[asyncpg.Record], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Args: + conn: + The connection object of type `ConnectionLike` used to execute queries. + sql: + The SQL statement that will be executed when fetching/iterating. + decode_hook: + A callback that turns an `asyncpg.Record` object into `T` that will be returned. + *args: + Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: asyncpg.cursor.CursorFactory[asyncpg.Record] | None = None + self._iterator: asyncpg.cursor.CursorIterator[asyncpg.Record] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns: + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await self._conn.fetch(self._sql, *self._args) + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an asyncpg cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopAsyncIteration: When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor = self._conn.cursor(self._sql, *self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +class QueriesEnumOverride: + """Queries from file queries_enum_override.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: ConnectionLike) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> ConnectionLike: + """Connection object used to make queries. + + Returns: + Connection object of type `ConnectionLike` used to make queries. + """ + return self._conn + + async def insert_enum_override(self, *, id_: int, mood_test: str) -> None: + """Execute SQL query with `name: InsertEnumOverride :exec`. + + ```sql + INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) + ``` + + Args: + id_: int. + mood_test: str. + """ + await self._conn.execute(INSERT_ENUM_OVERRIDE, id_, enums.TestMood(mood_test)) + + async def get_enum_override_mood(self, *, id_: int) -> str | None: + """Fetch one from the db using the SQL query with `name: GetEnumOverrideMood :one`. + + ```sql + SELECT mood_test FROM test_enum_override WHERE id = $1 + ``` + + Args: + id_: int. + + Returns: + Result of type `str` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ENUM_OVERRIDE_MOOD, id_) + if row is None: + return None + return str(row[0]) + + def list_enum_override_by_ids(self, *, dollar_1: collections.abc.Sequence[int]) -> QueryResults[models.TestEnumOverride]: + """Fetch many from the db using the SQL query with `name: ListEnumOverrideByIds :many`. + + ```sql + SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) + ``` + + Args: + dollar_1: collections.abc.Sequence[int]. + + Returns: + Helper class of type `QueryResults[models.TestEnumOverride]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestEnumOverride: + return models.TestEnumOverride(id_=row[0], mood_test=str(row[1])) + + return QueryResults(self._conn, LIST_ENUM_OVERRIDE_BY_IDS, _decode_hook, dollar_1) + + async def count_enum_override_by_moods(self, *, dollar_1: collections.abc.Sequence[enums.TestMood]) -> int | None: + """Fetch one from the db using the SQL query with `name: CountEnumOverrideByMoods :one`. + + ```sql + SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) + ``` + + Args: + dollar_1: collections.abc.Sequence[enums.TestMood]. + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(COUNT_ENUM_OVERRIDE_BY_MOODS, dollar_1) + if row is None: + return None + return row[0] diff --git a/test/driver_asyncpg/dataclass/functions/__init__.py b/test/driver_asyncpg/dataclass/functions/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_asyncpg/dataclass/functions/__init__.py +++ b/test/driver_asyncpg/dataclass/functions/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_asyncpg/dataclass/functions/enums.py b/test/driver_asyncpg/dataclass/functions/enums.py new file mode 100644 index 00000000..d49ac611 --- /dev/null +++ b/test/driver_asyncpg/dataclass/functions/enums.py @@ -0,0 +1,23 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing enums.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("TestMood",) + +import enum +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +class TestMood(enum.StrEnum): + """Enum representing TestMood.""" + + SAD = "sad" + OK = "ok" + HAPPY = "happy" diff --git a/test/driver_asyncpg/dataclass/functions/models.py b/test/driver_asyncpg/dataclass/functions/models.py index 7cc9cf46..33a320c7 100644 --- a/test/driver_asyncpg/dataclass/functions/models.py +++ b/test/driver_asyncpg/dataclass/functions/models.py @@ -1,11 +1,14 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( + "TestEnumOverride", + "TestEnumType", "TestInnerPostgresType", "TestPostgresType", "TestTypeOverride", @@ -16,12 +19,41 @@ if typing.TYPE_CHECKING: from collections import UserString + from test.driver_asyncpg.dataclass.functions import enums import collections.abc import datetime import decimal import uuid +@dataclasses.dataclass() +class TestEnumOverride: + """Model representing TestEnumOverride. + + Attributes: + id_: int + mood_test: str + """ + + id_: int + mood_test: str + + +@dataclasses.dataclass() +class TestEnumType: + """Model representing TestEnumType. + + Attributes: + id_: int + mood: enums.TestMood + maybe_mood: enums.TestMood | None + """ + + id_: int + mood: enums.TestMood + maybe_mood: enums.TestMood | None + + @dataclasses.dataclass() class TestInnerPostgresType: """Model representing TestInnerPostgresType. @@ -108,7 +140,7 @@ class TestPostgresType: """Model representing TestPostgresType. Attributes: - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -146,7 +178,7 @@ class TestPostgresType: ltxtquery_test: str """ - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -189,9 +221,9 @@ class TestTypeOverride: """Model representing TestTypeOverride. Attributes: - id: int + id_: int text_test: UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_asyncpg/dataclass/functions/queries.py b/test/driver_asyncpg/dataclass/functions/queries.py index 88031666..0c2e669e 100644 --- a/test/driver_asyncpg/dataclass/functions/queries.py +++ b/test/driver_asyncpg/dataclass/functions/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -17,12 +19,14 @@ "create_rows_table", "delete_one_result_test_postgres_type", "delete_one_rows_test_postgres_type", + "delete_one_test_enum_type", "delete_one_test_postgres_inner_type", "delete_one_test_postgres_type", "delete_type_override", "get_all_embedded_test_postgres_type", "get_embedded_test_postgres_type", "get_many_test_bytea_postgres_type", + "get_many_test_enum_types", "get_many_test_iterator_postgres_type", "get_many_test_postgres_type", "get_many_test_timestamp_postgres_type", @@ -30,10 +34,13 @@ "get_many_type_override", "get_one_inner_test_postgres_type", "get_one_test_bytea_postgres_type", + "get_one_test_enum_type", + "get_one_test_enum_value", "get_one_test_postgres_type", "get_one_test_timestamp_postgres_type", "get_one_text_type_override", "get_one_type_override", + "insert_one_test_enum_type", "insert_type_override", "test_copy_from", "update_result_test_postgres_type", @@ -42,7 +49,6 @@ from collections import UserString import dataclasses -import datetime import operator import typing @@ -50,35 +56,24 @@ import asyncpg import asyncpg.cursor import collections.abc + import datetime import decimal import uuid - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None - ConnectionLike: typing.TypeAlias = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] +from test.driver_asyncpg.dataclass.functions import enums from test.driver_asyncpg.dataclass.functions import models -@dataclasses.dataclass() -class GetAllEmbeddedTestPostgresTypeRow: - """Model representing GetAllEmbeddedTestPostgresTypeRow. - - Attributes: - test_postgres_type: models.TestPostgresType - test_inner_postgres_type: models.TestInnerPostgresType - """ - - test_postgres_type: models.TestPostgresType - test_inner_postgres_type: models.TestInnerPostgresType - - @dataclasses.dataclass() class GetEmbeddedTestPostgresTypeRow: """Model representing GetEmbeddedTestPostgresTypeRow. Attributes: - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -117,7 +112,7 @@ class GetEmbeddedTestPostgresTypeRow: test_inner_postgres_type: models.TestInnerPostgresType """ - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -156,63 +151,94 @@ class GetEmbeddedTestPostgresTypeRow: test_inner_postgres_type: models.TestInnerPostgresType +@dataclasses.dataclass() +class GetAllEmbeddedTestPostgresTypeRow: + """Model representing GetAllEmbeddedTestPostgresTypeRow. + + Attributes: + test_postgres_type: models.TestPostgresType + test_inner_postgres_type: models.TestInnerPostgresType + """ + + test_postgres_type: models.TestPostgresType + test_inner_postgres_type: models.TestInnerPostgresType + + @dataclasses.dataclass() class TestCopyFromParams: """Model representing TestCopyFromParams. Attributes: - id: int + id_: int float_test: float int_test: int """ - id: int + id_: int float_test: float int_test: int -CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec -INSERT INTO test_inner_postgres_types (table_id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) -VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) +GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one +SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_inner_postgres_types +WHERE table_id = $1 LIMIT 1 +""" + +GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 +""" + +GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 """ CREATE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresType :exec @@ -259,6 +285,62 @@ class TestCopyFromParams: $33, $34, $35, $36) """ +CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec +INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec +DELETE +FROM test_inner_postgres_types +WHERE test_inner_postgres_types.table_id = $1 +""" + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateResultOneTestPostgresType :execresult INSERT INTO test_postgres_types (id, serial_test, @@ -303,6 +385,18 @@ class TestCopyFromParams: $33, $34, $35, $36) """ +UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateRowsOneTestPostgresType :execrows INSERT INTO test_postgres_types (id, serial_test, @@ -347,6 +441,18 @@ class TestCopyFromParams: $33, $34, $35, $36) """ +UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows CREATE TABLE test_create_rows_table ( @@ -355,28 +461,32 @@ class TestCopyFromParams: ) """ -DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom +INSERT INTO test_copy_from (id, + float_test, int_test) +VALUES ($1, $2, $3) """ -DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec +INSERT INTO test_type_override ( + id, text_test +) VALUES ($1 ,$2) """ -DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec -DELETE -FROM test_inner_postgres_types -WHERE test_inner_postgres_types.table_id = $1 +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = $1 """ -DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 """ DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec @@ -385,113 +495,37 @@ class TestCopyFromParams: WHERE test_type_override.id = $1 """ -GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one -SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id -WHERE test_postgres_types.id = $1 +INSERT_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: InsertOneTestEnumType :exec +INSERT INTO test_enum_types (id, mood, maybe_mood) +VALUES ($1, $2, $3) """ -GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one -SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id -WHERE test_postgres_types.id = $1 -""" - -GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many -SELECT bytea_test -FROM test_postgres_types -WHERE id = $1 LIMIT 2 -""" - -GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types +GET_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: GetOneTestEnumType :one +SELECT id, mood, maybe_mood +FROM test_enum_types WHERE id = $1 """ -GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types +GET_ONE_TEST_ENUM_VALUE: typing.Final[str] = """-- name: GetOneTestEnumValue :one +SELECT mood +FROM test_enum_types WHERE id = $1 """ -GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many -SELECT timestamp_test -FROM test_postgres_types -WHERE id = $1 LIMIT 2 -""" - -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one -SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_inner_postgres_types -WHERE table_id = $1 LIMIT 1 -""" - -GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one -SELECT bytea_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one -SELECT timestamp_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = $1 -""" - -INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec -INSERT INTO test_type_override ( - id, text_test -) VALUES ($1 ,$2) -""" - -TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom -INSERT INTO test_copy_from (id, - float_test, int_test) -VALUES ($1, $2, $3) -""" - -UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult -UPDATE test_postgres_types -SET serial_test = 187 -WHERE test_postgres_types.id = $1 +GET_MANY_TEST_ENUM_TYPES: typing.Final[str] = """-- name: GetManyTestEnumTypes :many +SELECT id, mood, maybe_mood +FROM test_enum_types +ORDER BY id """ -UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows -UPDATE test_postgres_types -SET serial_test = 187 -WHERE test_postgres_types.id = $1 +DELETE_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: DeleteOneTestEnumType :execrows +DELETE +FROM test_enum_types +WHERE id = $1 """ -T = typing.TypeVar("T") - - -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db.""" __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") @@ -538,9 +572,11 @@ def __await__( Returns: A sequence of decoded objects of type `T`. """ + async def _wrapper() -> collections.abc.Sequence[T]: result = await self._conn.fetch(self._sql, *self._args) return [self._decode_hook(row) for row in result] + return _wrapper().__await__() async def __anext__(self) -> T: @@ -564,97 +600,578 @@ async def __anext__(self) -> T: return self._decode_hook(record) -async def create_one_test_postgres_inner_type(conn: ConnectionLike, *, table_id: int, serial_test: int | None, serial4_test: int | None, bigserial_test: int | None, smallserial_test: int | None, int_test: int | None, bigint_test: int | None, smallint_test: int | None, float_test: float | None, double_precision_test: float | None, real_test: float | None, numeric_test: decimal.Decimal | None, money_test: str | None, bool_test: bool | None, json_test: str | None, jsonb_test: str | None, bytea_test: memoryview | None, date_test: datetime.date | None, time_test: datetime.time | None, timetz_test: datetime.time | None, timestamp_test: datetime.datetime | None, timestamptz_test: datetime.datetime | None, interval_test: datetime.timedelta | None, text_test: str | None, varchar_test: str | None, bpchar_test: str | None, char_test: str | None, citext_test: str | None, uuid_test: uuid.UUID | None, inet_test: str | None, cidr_test: str | None, macaddr_test: str | None, macaddr8_test: str | None, ltree_test: str | None, lquery_test: str | None, ltxtquery_test: str | None) -> None: - """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. +async def get_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> models.TestPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. ```sql - INSERT INTO test_inner_postgres_types (table_id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `models.TestPostgresType` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + +async def get_one_inner_test_postgres_type(conn: ConnectionLike, *, table_id: int) -> models.TestInnerPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + + ```sql + SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_inner_postgres_types + WHERE table_id = $1 LIMIT 1 ``` Args: conn: Connection object of type `ConnectionLike` used to execute the query. table_id: int. - serial_test: int | None. - serial4_test: int | None. - bigserial_test: int | None. - smallserial_test: int | None. - int_test: int | None. - bigint_test: int | None. - smallint_test: int | None. - float_test: float | None. - double_precision_test: float | None. - real_test: float | None. - numeric_test: decimal.Decimal | None. - money_test: str | None. - bool_test: bool | None. - json_test: str | None. - jsonb_test: str | None. - bytea_test: memoryview | None. - date_test: datetime.date | None. - time_test: datetime.time | None. - timetz_test: datetime.time | None. - timestamp_test: datetime.datetime | None. - timestamptz_test: datetime.datetime | None. - interval_test: datetime.timedelta | None. - text_test: str | None. - varchar_test: str | None. - bpchar_test: str | None. - char_test: str | None. - citext_test: str | None. - uuid_test: uuid.UUID | None. - inet_test: str | None. - cidr_test: str | None. - macaddr_test: str | None. - macaddr8_test: str | None. - ltree_test: str | None. - lquery_test: str | None. - ltxtquery_test: str | None. + + Returns: + Result of type `models.TestInnerPostgresType` fetched from the db. Will be `None` if not found. """ - await conn.execute(CREATE_ONE_TEST_POSTGRES_INNER_TYPE, table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + row = await conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + if row is None: + return None + return models.TestInnerPostgresType( + table_id=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]) if row[16] is not None else None, + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]) if row[29] is not None else None, + cidr_test=str(row[30]) if row[30] is not None else None, + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + +async def get_one_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) + if row is None: + return None + return row[0] -async def create_one_test_postgres_type(conn: ConnectionLike, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> None: + +async def get_one_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `memoryview` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) + if row is None: + return None + return memoryview(row[0]) + + +def get_many_test_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestPostgresType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + + +def get_many_test_iterator_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestPostgresType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) + + +def get_many_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. + + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + + +def get_many_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> memoryview: + return memoryview(row[0]) + + return QueryResults(conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + + +async def get_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `GetEmbeddedTestPostgresTypeRow` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetEmbeddedTestPostgresTypeRow( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + +async def get_all_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `GetAllEmbeddedTestPostgresTypeRow` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetAllEmbeddedTestPostgresTypeRow( + test_postgres_type=models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ), + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + +async def create_one_test_postgres_type( + conn: ConnectionLike, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, +) -> None: """Execute SQL query with `name: CreateOneTestPostgresType :exec`. ```sql @@ -741,49 +1258,126 @@ async def create_one_test_postgres_type(conn: ConnectionLike, *, id_: int, seria lquery_test: str. ltxtquery_test: str. """ - await conn.execute(CREATE_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + await conn.execute( + CREATE_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) -async def create_result_one_test_postgres_type(conn: ConnectionLike, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> str: - """Execute and return the result of SQL query with `name: CreateResultOneTestPostgresType :execresult`. +async def create_one_test_postgres_inner_type( + conn: ConnectionLike, + *, + table_id: int, + serial_test: int | None, + serial4_test: int | None, + bigserial_test: int | None, + smallserial_test: int | None, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + float_test: float | None, + double_precision_test: float | None, + real_test: float | None, + numeric_test: decimal.Decimal | None, + money_test: str | None, + bool_test: bool | None, + json_test: str | None, + jsonb_test: str | None, + bytea_test: memoryview | None, + date_test: datetime.date | None, + time_test: datetime.time | None, + timetz_test: datetime.time | None, + timestamp_test: datetime.datetime | None, + timestamptz_test: datetime.datetime | None, + interval_test: datetime.timedelta | None, + text_test: str | None, + varchar_test: str | None, + bpchar_test: str | None, + char_test: str | None, + citext_test: str | None, + uuid_test: uuid.UUID | None, + inet_test: str | None, + cidr_test: str | None, + macaddr_test: str | None, + macaddr8_test: str | None, + ltree_test: str | None, + lquery_test: str | None, + ltxtquery_test: str | None, +) -> None: + """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. ```sql - INSERT INTO test_postgres_types (id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) + INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, @@ -791,54 +1385,162 @@ async def create_result_one_test_postgres_type(conn: ConnectionLike, *, id_: int $33, $34, $35, $36) ``` + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + table_id: int. + serial_test: int | None. + serial4_test: int | None. + bigserial_test: int | None. + smallserial_test: int | None. + int_test: int | None. + bigint_test: int | None. + smallint_test: int | None. + float_test: float | None. + double_precision_test: float | None. + real_test: float | None. + numeric_test: decimal.Decimal | None. + money_test: str | None. + bool_test: bool | None. + json_test: str | None. + jsonb_test: str | None. + bytea_test: memoryview | None. + date_test: datetime.date | None. + time_test: datetime.time | None. + timetz_test: datetime.time | None. + timestamp_test: datetime.datetime | None. + timestamptz_test: datetime.datetime | None. + interval_test: datetime.timedelta | None. + text_test: str | None. + varchar_test: str | None. + bpchar_test: str | None. + char_test: str | None. + citext_test: str | None. + uuid_test: uuid.UUID | None. + inet_test: str | None. + cidr_test: str | None. + macaddr_test: str | None. + macaddr8_test: str | None. + ltree_test: str | None. + lquery_test: str | None. + ltxtquery_test: str | None. + """ + await conn.execute( + CREATE_ONE_TEST_POSTGRES_INNER_TYPE, + table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + +async def delete_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + Args: conn: Connection object of type `ConnectionLike` used to execute the query. id_: int. - serial_test: int. - serial4_test: int. - bigserial_test: int. - smallserial_test: int. - int_test: int. - bigint_test: int. - smallint_test: int. - float_test: float. - double_precision_test: float. - real_test: float. - numeric_test: decimal.Decimal. - money_test: str. - bool_test: bool. - json_test: str. - jsonb_test: str. - bytea_test: memoryview. - date_test: datetime.date. - time_test: datetime.time. - timetz_test: datetime.time. - timestamp_test: datetime.datetime. - timestamptz_test: datetime.datetime. - interval_test: datetime.timedelta. - text_test: str. - varchar_test: str. - bpchar_test: str. - char_test: str. - citext_test: str. - uuid_test: uuid.UUID. - inet_test: str. - cidr_test: str. - macaddr_test: str. - macaddr8_test: str. - ltree_test: str. - lquery_test: str. - ltxtquery_test: str. + """ + await conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) - Returns: - The result of type `str` returned when executing the query. + +async def delete_one_test_postgres_inner_type(conn: ConnectionLike, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. + + ```sql + DELETE + FROM test_inner_postgres_types + WHERE test_inner_postgres_types.table_id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + table_id: int. """ - return await conn.execute(CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + await conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) -async def create_rows_one_test_postgres_type(conn: ConnectionLike, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> int: - """Execute SQL query with `name: CreateRowsOneTestPostgresType :execrows` and return the number of affected rows. +async def create_result_one_test_postgres_type( + conn: ConnectionLike, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, +) -> str: + """Execute and return the result of SQL query with `name: CreateResultOneTestPostgresType :execresult`. ```sql INSERT INTO test_postgres_types (id, @@ -925,40 +1627,55 @@ async def create_rows_one_test_postgres_type(conn: ConnectionLike, *, id_: int, ltxtquery_test: str. Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + The result of type `str` returned when executing the query. """ - r = await conn.execute(CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - - -async def create_rows_table(conn: ConnectionLike) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. - - ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL + return await conn.execute( + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, ) - ``` - - Args: - conn: - Connection object of type `ConnectionLike` used to execute the query. - - Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. - """ - r = await conn.execute(CREATE_ROWS_TABLE) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 -async def delete_one_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: - """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. +async def update_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. ```sql - DELETE - FROM test_postgres_types + UPDATE test_postgres_types + SET serial_test = 187 WHERE test_postgres_types.id = $1 ``` @@ -970,11 +1687,11 @@ async def delete_one_result_test_postgres_type(conn: ConnectionLike, *, id_: int Returns: The result of type `str` returned when executing the query. """ - return await conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) + return await conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) -async def delete_one_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: - """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. +async def delete_one_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. ```sql DELETE @@ -988,94 +1705,188 @@ async def delete_one_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) id_: int. Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. - """ - r = await conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - - -async def delete_one_test_postgres_inner_type(conn: ConnectionLike, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. - - ```sql - DELETE - FROM test_inner_postgres_types - WHERE test_inner_postgres_types.table_id = $1 - ``` - - Args: - conn: - Connection object of type `ConnectionLike` used to execute the query. - table_id: int. - """ - await conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) - - -async def delete_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. - - ```sql - DELETE - FROM test_postgres_types - WHERE test_postgres_types.id = $1 - ``` - - Args: - conn: - Connection object of type `ConnectionLike` used to execute the query. - id_: int. - """ - await conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) - - -async def delete_type_override(conn: ConnectionLike, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. - - ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = $1 - ``` - - Args: - conn: - Connection object of type `ConnectionLike` used to execute the query. - id_: int. + The result of type `str` returned when executing the query. """ - await conn.execute(DELETE_TYPE_OVERRIDE, id_) + return await conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) -async def get_all_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: - """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. +async def create_rows_one_test_postgres_type( + conn: ConnectionLike, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, +) -> int: + """Execute SQL query with `name: CreateRowsOneTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test - FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id - WHERE test_postgres_types.id = $1 + INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) ``` Args: conn: Connection object of type `ConnectionLike` used to execute the query. id_: int. + serial_test: int. + serial4_test: int. + bigserial_test: int. + smallserial_test: int. + int_test: int. + bigint_test: int. + smallint_test: int. + float_test: float. + double_precision_test: float. + real_test: float. + numeric_test: decimal.Decimal. + money_test: str. + bool_test: bool. + json_test: str. + jsonb_test: str. + bytea_test: memoryview. + date_test: datetime.date. + time_test: datetime.time. + timetz_test: datetime.time. + timestamp_test: datetime.datetime. + timestamptz_test: datetime.datetime. + interval_test: datetime.timedelta. + text_test: str. + varchar_test: str. + bpchar_test: str. + char_test: str. + citext_test: str. + uuid_test: uuid.UUID. + inet_test: str. + cidr_test: str. + macaddr_test: str. + macaddr8_test: str. + ltree_test: str. + lquery_test: str. + ltxtquery_test: str. Returns: - Result of type `GetAllEmbeddedTestPostgresTypeRow` fetched from the db. Will be `None` if not found. + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - row = await conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return GetAllEmbeddedTestPostgresTypeRow(test_postgres_type=models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]), test_inner_postgres_type=models.TestInnerPostgresType(table_id=row[36], serial_test=row[37], serial4_test=row[38], bigserial_test=row[39], smallserial_test=row[40], int_test=row[41], bigint_test=row[42], smallint_test=row[43], float_test=row[44], double_precision_test=row[45], real_test=row[46], numeric_test=row[47], money_test=row[48], bool_test=row[49], json_test=row[50], jsonb_test=row[51], bytea_test=memoryview(row[52]) if row[52] is not None else None, date_test=row[53], time_test=row[54], timetz_test=row[55], timestamp_test=row[56], timestamptz_test=row[57], interval_test=row[58], text_test=row[59], varchar_test=row[60], bpchar_test=row[61], char_test=row[62], citext_test=row[63], uuid_test=row[64], inet_test=str(row[65]) if row[65] is not None else None, cidr_test=str(row[66]) if row[66] is not None else None, macaddr_test=row[67], macaddr8_test=row[68], ltree_test=row[69], lquery_test=row[70], ltxtquery_test=row[71])) + r = await conn.execute( + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 -async def get_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: - """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. +async def update_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test - FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + UPDATE test_postgres_types + SET serial_test = 187 WHERE test_postgres_types.id = $1 ``` @@ -1085,21 +1896,19 @@ async def get_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> id_: int. Returns: - Result of type `GetEmbeddedTestPostgresTypeRow` fetched from the db. Will be `None` if not found. + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - row = await conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return GetEmbeddedTestPostgresTypeRow(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35], test_inner_postgres_type=models.TestInnerPostgresType(table_id=row[36], serial_test=row[37], serial4_test=row[38], bigserial_test=row[39], smallserial_test=row[40], int_test=row[41], bigint_test=row[42], smallint_test=row[43], float_test=row[44], double_precision_test=row[45], real_test=row[46], numeric_test=row[47], money_test=row[48], bool_test=row[49], json_test=row[50], jsonb_test=row[51], bytea_test=memoryview(row[52]) if row[52] is not None else None, date_test=row[53], time_test=row[54], timetz_test=row[55], timestamp_test=row[56], timestamptz_test=row[57], interval_test=row[58], text_test=row[59], varchar_test=row[60], bpchar_test=row[61], char_test=row[62], citext_test=row[63], uuid_test=row[64], inet_test=str(row[65]) if row[65] is not None else None, cidr_test=str(row[66]) if row[66] is not None else None, macaddr_test=row[67], macaddr8_test=row[68], ltree_test=row[69], lquery_test=row[70], ltxtquery_test=row[71])) + r = await conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 -def get_many_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. +async def delete_one_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT bytea_test + DELETE FROM test_postgres_types - WHERE id = $1 LIMIT 2 + WHERE test_postgres_types.id = $1 ``` Args: @@ -1108,82 +1917,74 @@ def get_many_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> Quer id_: int. Returns: - Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - def _decode_hook(row: asyncpg.Record) -> memoryview: - return memoryview(row[0]) - return QueryResults[memoryview](conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + r = await conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 -def get_many_test_iterator_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: - """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. +async def create_rows_table(conn: ConnectionLike) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) ``` Args: conn: Connection object of type `ConnectionLike` used to execute the query. - id_: int. Returns: - Helper class of type `QueryResults[models.TestPostgresType]` that allows both iteration and normal fetching of data from the db. + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) - return QueryResults[models.TestPostgresType](conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) - + r = await conn.execute(CREATE_ROWS_TABLE) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 -def get_many_test_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: - """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. - ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 - ``` +async def test_copy_from(conn: ConnectionLike, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. Args: conn: Connection object of type `ConnectionLike` used to execute the query. - id_: int. + params: collections.abc.Sequence[TestCopyFromParams]. + A list of params for rows that should be inserted. Returns: - Helper class of type `QueryResults[models.TestPostgresType]` that allows both iteration and normal fetching of data from the db. + The number (`int`) of affected rows. """ - def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) - return QueryResults[models.TestPostgresType](conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + records = [(param.id_, param.float_test, param.int_test) for param in params] + r = await conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 -def get_many_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. +async def insert_type_override(conn: ConnectionLike, *, id_: int, text_test: UserString | None) -> None: + """Execute SQL query with `name: InsertTypeOverride :exec`. ```sql - SELECT timestamp_test - FROM test_postgres_types - WHERE id = $1 LIMIT 2 + INSERT INTO test_type_override ( + id, text_test + ) VALUES ($1 ,$2) ``` Args: conn: Connection object of type `ConnectionLike` used to execute the query. id_: int. - - Returns: - Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + text_test: UserString | None. """ - return QueryResults[datetime.datetime](conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + await conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test) if text_test is not None else None) -def get_many_text_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. +async def get_one_type_override(conn: ConnectionLike, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + SELECT id, text_test FROM test_type_override WHERE id = $1 ``` Args: @@ -1192,9 +1993,12 @@ def get_many_text_type_override(conn: ConnectionLike, *, id_: int) -> QueryResul id_: int. Returns: - Helper class of type `QueryResults[UserString]` that allows both iteration and normal fetching of data from the db. + Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. """ - return QueryResults[UserString](conn, GET_MANY_TEXT_TYPE_OVERRIDE, operator.itemgetter(0), id_) + row = await conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) def get_many_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestTypeOverride]: @@ -1212,41 +2016,39 @@ def get_many_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[mo Returns: Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: asyncpg.Record) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - return QueryResults[models.TestTypeOverride](conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + return QueryResults(conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) -async def get_one_inner_test_postgres_type(conn: ConnectionLike, *, table_id: int) -> models.TestInnerPostgresType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + +async def get_one_text_type_override(conn: ConnectionLike, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_inner_postgres_types - WHERE table_id = $1 LIMIT 1 + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 ``` Args: conn: Connection object of type `ConnectionLike` used to execute the query. - table_id: int. + id_: int. Returns: - Result of type `models.TestInnerPostgresType` fetched from the db. Will be `None` if not found. + Result of type `UserString` fetched from the db. Will be `None` if not found. """ - row = await conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + row = await conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) if row is None: return None - return models.TestInnerPostgresType(table_id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]) if row[16] is not None else None, date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]) if row[29] is not None else None, cidr_test=str(row[30]) if row[30] is not None else None, macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) + return UserString(row[0]) if row[0] is not None else None -async def get_one_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. +def get_many_text_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. ```sql - SELECT bytea_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 ``` Args: @@ -1255,65 +2057,57 @@ async def get_one_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> id_: int. Returns: - Result of type `memoryview` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[UserString | None]` that allows both iteration and normal fetching of data from the db. """ - row = await conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) - if row is None: - return None - return memoryview(row[0]) + def _decode_hook(row: asyncpg.Record) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) -async def get_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> models.TestPostgresType | None: - """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. + +async def delete_type_override(conn: ConnectionLike, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + DELETE + FROM test_type_override + WHERE test_type_override.id = $1 ``` Args: conn: Connection object of type `ConnectionLike` used to execute the query. id_: int. - - Returns: - Result of type `models.TestPostgresType` fetched from the db. Will be `None` if not found. """ - row = await conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) + await conn.execute(DELETE_TYPE_OVERRIDE, id_) -async def get_one_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. +async def insert_one_test_enum_type(conn: ConnectionLike, *, id_: int, mood: enums.TestMood, maybe_mood: enums.TestMood | None) -> None: + """Execute SQL query with `name: InsertOneTestEnumType :exec`. ```sql - SELECT timestamp_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + INSERT INTO test_enum_types (id, mood, maybe_mood) + VALUES ($1, $2, $3) ``` Args: conn: Connection object of type `ConnectionLike` used to execute the query. id_: int. - - Returns: - Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + mood: enums.TestMood. + maybe_mood: enums.TestMood | None. """ - row = await conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) - if row is None: - return None - return row[0] + await conn.execute(INSERT_ONE_TEST_ENUM_TYPE, id_, mood, maybe_mood) -async def get_one_text_type_override(conn: ConnectionLike, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. +async def get_one_test_enum_type(conn: ConnectionLike, *, id_: int) -> models.TestEnumType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumType :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + SELECT id, mood, maybe_mood + FROM test_enum_types + WHERE id = $1 ``` Args: @@ -1322,19 +2116,21 @@ async def get_one_text_type_override(conn: ConnectionLike, *, id_: int) -> UserS id_: int. Returns: - Result of type `UserString` fetched from the db. Will be `None` if not found. + Result of type `models.TestEnumType` fetched from the db. Will be `None` if not found. """ - row = await conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) + row = await conn.fetchrow(GET_ONE_TEST_ENUM_TYPE, id_) if row is None: return None - return row[0] + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) -async def get_one_type_override(conn: ConnectionLike, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. +async def get_one_test_enum_value(conn: ConnectionLike, *, id_: int) -> enums.TestMood | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumValue :one`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = $1 + SELECT mood + FROM test_enum_types + WHERE id = $1 ``` Args: @@ -1343,79 +2139,44 @@ async def get_one_type_override(conn: ConnectionLike, *, id_: int) -> models.Tes id_: int. Returns: - Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. + Result of type `enums.TestMood` fetched from the db. Will be `None` if not found. """ - row = await conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + row = await conn.fetchrow(GET_ONE_TEST_ENUM_VALUE, id_) if row is None: return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + return enums.TestMood(row[0]) -async def insert_type_override(conn: ConnectionLike, *, id_: int, text_test: UserString | None) -> None: - """Execute SQL query with `name: InsertTypeOverride :exec`. +def get_many_test_enum_types(conn: ConnectionLike) -> QueryResults[models.TestEnumType]: + """Fetch many from the db using the SQL query with `name: GetManyTestEnumTypes :many`. ```sql - INSERT INTO test_type_override ( - id, text_test - ) VALUES ($1 ,$2) + SELECT id, mood, maybe_mood + FROM test_enum_types + ORDER BY id ``` Args: conn: Connection object of type `ConnectionLike` used to execute the query. - id_: int. - text_test: UserString | None. - """ - await conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test)) - - -async def test_copy_from(conn: ConnectionLike, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: - """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. - - Args: - conn: - Connection object of type `ConnectionLike` used to execute the query. - params: collections.abc.Sequence[TestCopyFromParams]. - A list of params for rows that should be inserted. Returns: - The number (`int`) of affected rows. + Helper class of type `QueryResults[models.TestEnumType]` that allows both iteration and normal fetching of data from the db. """ - records = [ - (param.id, param.float_test, param.int_test) - for param in params - ] - r = await conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - - -async def update_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: - """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. - - ```sql - UPDATE test_postgres_types - SET serial_test = 187 - WHERE test_postgres_types.id = $1 - ``` - Args: - conn: - Connection object of type `ConnectionLike` used to execute the query. - id_: int. + def _decode_hook(row: asyncpg.Record) -> models.TestEnumType: + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) - Returns: - The result of type `str` returned when executing the query. - """ - return await conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) + return QueryResults(conn, GET_MANY_TEST_ENUM_TYPES, _decode_hook) -async def update_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. +async def delete_one_test_enum_type(conn: ConnectionLike, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneTestEnumType :execrows` and return the number of affected rows. ```sql - UPDATE test_postgres_types - SET serial_test = 187 - WHERE test_postgres_types.id = $1 + DELETE + FROM test_enum_types + WHERE id = $1 ``` Args: @@ -1426,5 +2187,5 @@ async def update_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> i Returns: The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - r = await conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + r = await conn.execute(DELETE_ONE_TEST_ENUM_TYPE, id_) return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 diff --git a/test/driver_asyncpg/dataclass/functions/queries_copy_override.py b/test/driver_asyncpg/dataclass/functions/queries_copy_override.py new file mode 100644 index 00000000..0049c340 --- /dev/null +++ b/test/driver_asyncpg/dataclass/functions/queries_copy_override.py @@ -0,0 +1,102 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_copy_override.sql +"""Module containing queries from file queries_copy_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "CopyOverrideRowsParams", + "copy_override_rows", + "count_copy_override_rows", + "delete_copy_override_rows", +) + +import dataclasses +import decimal +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import collections.abc + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + + +@dataclasses.dataclass() +class CopyOverrideRowsParams: + """Model representing CopyOverrideRowsParams. + + Attributes: + id_: int + amount: float + """ + + id_: int + amount: float + + +COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CopyOverrideRows :copyfrom +INSERT INTO test_copy_override (id, amount) VALUES ($1, $2) +""" + +COUNT_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CountCopyOverrideRows :one +SELECT count(*) FROM test_copy_override +""" + +DELETE_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: DeleteCopyOverrideRows :exec +DELETE FROM test_copy_override +""" + + +async def copy_override_rows(conn: ConnectionLike, *, params: collections.abc.Sequence[CopyOverrideRowsParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: CopyOverrideRows :copyfrom` and return the number of affected rows. + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + params: collections.abc.Sequence[CopyOverrideRowsParams]. + A list of params for rows that should be inserted. + + Returns: + The number (`int`) of affected rows. + """ + records = [(param.id_, decimal.Decimal(param.amount)) for param in params] + r = await conn.copy_records_to_table("test_copy_override", columns=["id", "amount"], records=records) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + +async def count_copy_override_rows(conn: ConnectionLike) -> int | None: + """Fetch one from the db using the SQL query with `name: CountCopyOverrideRows :one`. + + ```sql + SELECT count(*) FROM test_copy_override + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(COUNT_COPY_OVERRIDE_ROWS) + if row is None: + return None + return row[0] + + +async def delete_copy_override_rows(conn: ConnectionLike) -> None: + """Execute SQL query with `name: DeleteCopyOverrideRows :exec`. + + ```sql + DELETE FROM test_copy_override + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + """ + await conn.execute(DELETE_COPY_OVERRIDE_ROWS) diff --git a/test/driver_asyncpg/dataclass/functions/queries_enum_override.py b/test/driver_asyncpg/dataclass/functions/queries_enum_override.py new file mode 100644 index 00000000..12f9fd3d --- /dev/null +++ b/test/driver_asyncpg/dataclass/functions/queries_enum_override.py @@ -0,0 +1,202 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_enum_override.sql +"""Module containing queries from file queries_enum_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "QueryResults", + "count_enum_override_by_moods", + "get_enum_override_mood", + "insert_enum_override", + "list_enum_override_by_ids", +) + +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import asyncpg.cursor + import collections.abc + + type QueryResultsArgsType = int | float | str | memoryview | collections.abc.Sequence[QueryResultsArgsType] | None + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + +from test.driver_asyncpg.dataclass.functions import enums +from test.driver_asyncpg.dataclass.functions import models + + +INSERT_ENUM_OVERRIDE: typing.Final[str] = """-- name: InsertEnumOverride :exec +INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) +""" + +GET_ENUM_OVERRIDE_MOOD: typing.Final[str] = """-- name: GetEnumOverrideMood :one +SELECT mood_test FROM test_enum_override WHERE id = $1 +""" + +LIST_ENUM_OVERRIDE_BY_IDS: typing.Final[str] = """-- name: ListEnumOverrideByIds :many +SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) +""" + +COUNT_ENUM_OVERRIDE_BY_MOODS: typing.Final[str] = """-- name: CountEnumOverrideByMoods :one +SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: ConnectionLike, + sql: str, + decode_hook: collections.abc.Callable[[asyncpg.Record], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Args: + conn: + The connection object of type `ConnectionLike` used to execute queries. + sql: + The SQL statement that will be executed when fetching/iterating. + decode_hook: + A callback that turns an `asyncpg.Record` object into `T` that will be returned. + *args: + Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: asyncpg.cursor.CursorFactory[asyncpg.Record] | None = None + self._iterator: asyncpg.cursor.CursorIterator[asyncpg.Record] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns: + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await self._conn.fetch(self._sql, *self._args) + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an asyncpg cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopAsyncIteration: When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor = self._conn.cursor(self._sql, *self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +async def insert_enum_override(conn: ConnectionLike, *, id_: int, mood_test: str) -> None: + """Execute SQL query with `name: InsertEnumOverride :exec`. + + ```sql + INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + mood_test: str. + """ + await conn.execute(INSERT_ENUM_OVERRIDE, id_, enums.TestMood(mood_test)) + + +async def get_enum_override_mood(conn: ConnectionLike, *, id_: int) -> str | None: + """Fetch one from the db using the SQL query with `name: GetEnumOverrideMood :one`. + + ```sql + SELECT mood_test FROM test_enum_override WHERE id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `str` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ENUM_OVERRIDE_MOOD, id_) + if row is None: + return None + return str(row[0]) + + +def list_enum_override_by_ids(conn: ConnectionLike, *, dollar_1: collections.abc.Sequence[int]) -> QueryResults[models.TestEnumOverride]: + """Fetch many from the db using the SQL query with `name: ListEnumOverrideByIds :many`. + + ```sql + SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + dollar_1: collections.abc.Sequence[int]. + + Returns: + Helper class of type `QueryResults[models.TestEnumOverride]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestEnumOverride: + return models.TestEnumOverride(id_=row[0], mood_test=str(row[1])) + + return QueryResults(conn, LIST_ENUM_OVERRIDE_BY_IDS, _decode_hook, dollar_1) + + +async def count_enum_override_by_moods(conn: ConnectionLike, *, dollar_1: collections.abc.Sequence[enums.TestMood]) -> int | None: + """Fetch one from the db using the SQL query with `name: CountEnumOverrideByMoods :one`. + + ```sql + SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + dollar_1: collections.abc.Sequence[enums.TestMood]. + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(COUNT_ENUM_OVERRIDE_BY_MOODS, dollar_1) + if row is None: + return None + return row[0] diff --git a/test/driver_asyncpg/dataclass/test_dataclass_classes.py b/test/driver_asyncpg/dataclass/test_dataclass_classes.py index 00e0bf40..e29d537b 100644 --- a/test/driver_asyncpg/dataclass/test_dataclass_classes.py +++ b/test/driver_asyncpg/dataclass/test_dataclass_classes.py @@ -43,12 +43,12 @@ class TestDataclassClasses: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestPostgresType: return models.TestPostgresType( - id=random.randint(1, 1000000), + id_=random.randint(1, 1000000), serial_test=1, serial4_test=2, bigserial_test=3, @@ -67,9 +67,9 @@ def model(self) -> models.TestPostgresType: bytea_test=memoryview(b"\x00\x01\x02hello"), date_test=datetime.date(2025, 1, 1), time_test=datetime.time(14, 30, 0), - timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.timezone.utc), + timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.UTC), timestamp_test=datetime.datetime(2025, 1, 1, 14, 30, 0), - timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.timezone.utc), + timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.UTC), interval_test=datetime.timedelta(days=1, hours=2, minutes=30), text_test="Lorem ipsum", varchar_test="Example varchar", @@ -89,7 +89,7 @@ def model(self) -> models.TestPostgresType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestPostgresType) -> models.TestInnerPostgresType: return models.TestInnerPostgresType( - table_id=model.id, + table_id=model.id_, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -135,7 +135,7 @@ async def queries_obj(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> @pytest.mark.dependency(name="TestDataclassClasses::create") async def test_create(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: await queries_obj.create_one_test_postgres_type( - id_=model.id, + id_=model.id_, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -218,7 +218,7 @@ async def test_create_inner(self, queries_obj: queries.Queries, inner_model: mod @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestDataclassClasses::create_inner"], name="TestDataclassClasses::get_one") async def test_get_one(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_one_test_postgres_type(id_=model.id) + result = await queries_obj.get_one_test_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, models.TestPostgresType) @@ -243,9 +243,7 @@ async def test_get_one_inner(self, queries_obj: queries.Queries, inner_model: mo assert result == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestDataclassClasses::get_one_inner"], name="TestDataclassClasses::get_one_inner_none" - ) + @pytest.mark.dependency(depends=["TestDataclassClasses::get_one_inner"], name="TestDataclassClasses::get_one_inner_none") async def test_get_one_inner_none(self, queries_obj: queries.Queries) -> None: result = await queries_obj.get_one_inner_test_postgres_type(table_id=0) @@ -257,16 +255,14 @@ async def test_get_one_inner_none(self, queries_obj: queries.Queries) -> None: name="TestDataclassClasses::get_one_timestamp", ) async def test_get_one_timestamp(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_one_test_timestamp_postgres_type(id_=model.id) + result = await queries_obj.get_one_test_timestamp_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestDataclassClasses::get_one_timestamp"], name="TestDataclassClasses::get_one_timestamp_none" - ) + @pytest.mark.dependency(depends=["TestDataclassClasses::get_one_timestamp"], name="TestDataclassClasses::get_one_timestamp_none") async def test_get_one_timestamp_none(self, queries_obj: queries.Queries) -> None: result = await queries_obj.get_one_test_timestamp_postgres_type(id_=0) @@ -278,16 +274,14 @@ async def test_get_one_timestamp_none(self, queries_obj: queries.Queries) -> Non name="TestDataclassClasses::get_one_bytea", ) async def test_get_one_bytea(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_one_test_bytea_postgres_type(id_=model.id) + result = await queries_obj.get_one_test_bytea_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, memoryview) assert result == model.bytea_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestDataclassClasses::get_one_bytea"], name="TestDataclassClasses::get_one_bytea_none" - ) + @pytest.mark.dependency(depends=["TestDataclassClasses::get_one_bytea"], name="TestDataclassClasses::get_one_bytea_none") async def test_get_one_bytea_none(self, queries_obj: queries.Queries) -> None: result = await queries_obj.get_one_test_bytea_postgres_type(id_=0) @@ -296,7 +290,7 @@ async def test_get_one_bytea_none(self, queries_obj: queries.Queries) -> None: @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestDataclassClasses::get_one_bytea_none"], name="TestDataclassClasses::get_many") async def test_get_many(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_many_test_postgres_type(id_=model.id) + result = await queries_obj.get_many_test_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -308,7 +302,7 @@ async def test_get_many(self, queries_obj: queries.Queries, model: models.TestPo @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestDataclassClasses::get_many"], name="TestDataclassClasses::get_many_timestamp") async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_many_test_timestamp_postgres_type(id_=model.id) + result = await queries_obj.get_many_test_timestamp_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -322,7 +316,7 @@ async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: mod name="TestDataclassClasses::get_many_bytea", ) async def test_get_many_bytea(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_many_test_bytea_postgres_type(id_=model.id) + result = await queries_obj.get_many_test_bytea_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -338,13 +332,13 @@ async def test_get_embedded( model: models.TestPostgresType, inner_model: models.TestInnerPostgresType, ) -> None: - result = await queries_obj.get_embedded_test_postgres_type(id_=model.id) + result = await queries_obj.get_embedded_test_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, queries.GetEmbeddedTestPostgresTypeRow) assert isinstance(result.test_inner_postgres_type, models.TestInnerPostgresType) - assert result.id == model.id + assert result.id_ == model.id_ assert result.serial_test == model.serial_test assert result.serial4_test == model.serial4_test assert result.bigserial_test == model.bigserial_test @@ -384,9 +378,7 @@ async def test_get_embedded( assert result.test_inner_postgres_type == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestDataclassClasses::get_embedded"], name="TestDataclassClasses::get_embedded_none" - ) + @pytest.mark.dependency(depends=["TestDataclassClasses::get_embedded"], name="TestDataclassClasses::get_embedded_none") async def test_get_embedded_none( self, queries_obj: queries.Queries, @@ -406,7 +398,7 @@ async def test_get_all_embedded( model: models.TestPostgresType, inner_model: models.TestInnerPostgresType, ) -> None: - result = await queries_obj.get_all_embedded_test_postgres_type(id_=model.id) + result = await queries_obj.get_all_embedded_test_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, queries.GetAllEmbeddedTestPostgresTypeRow) @@ -417,9 +409,7 @@ async def test_get_all_embedded( assert result.test_inner_postgres_type == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestDataclassClasses::get_all_embedded"], name="TestDataclassClasses::get_all_embedded_none" - ) + @pytest.mark.dependency(depends=["TestDataclassClasses::get_all_embedded"], name="TestDataclassClasses::get_all_embedded_none") async def test_get_all_embedded_none( self, queries_obj: queries.Queries, @@ -438,7 +428,7 @@ async def test_get_many_iterator( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - results = queries_obj.get_many_test_iterator_postgres_type(id_=model.id) + results = queries_obj.get_many_test_iterator_postgres_type(id_=model.id_) async with queries_obj.conn.transaction(): async for result in results: assert result is not None @@ -453,7 +443,7 @@ async def test_delete( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - await queries_obj.delete_one_test_postgres_type(id_=model.id) + await queries_obj.delete_one_test_postgres_type(id_=model.id_) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestDataclassClasses::delete"], name="TestDataclassClasses::delete_inner") @@ -472,7 +462,7 @@ async def test_create_result( model: models.TestPostgresType, ) -> None: result = await queries_obj.create_result_one_test_postgres_type( - id_=model.id + 1, + id_=model.id_ + 1, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -519,7 +509,7 @@ async def test_update_result( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - result = await queries_obj.update_result_test_postgres_type(id_=model.id + 1) + result = await queries_obj.update_result_test_postgres_type(id_=model.id_ + 1) assert result == "UPDATE 1" @@ -530,7 +520,7 @@ async def test_delete_result( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - result = await queries_obj.delete_one_result_test_postgres_type(id_=model.id + 1) + result = await queries_obj.delete_one_result_test_postgres_type(id_=model.id_ + 1) assert result == "DELETE 1" @@ -542,7 +532,7 @@ async def test_create_rows( model: models.TestPostgresType, ) -> None: result = await queries_obj.create_rows_one_test_postgres_type( - id_=model.id + 1, + id_=model.id_ + 1, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -589,7 +579,7 @@ async def test_update_rows( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - result = await queries_obj.update_rows_test_postgres_type(id_=model.id + 1) + result = await queries_obj.update_rows_test_postgres_type(id_=model.id_ + 1) assert result == 1 @@ -600,7 +590,7 @@ async def test_delete_rows( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - result = await queries_obj.delete_one_rows_test_postgres_type(id_=model.id + 1) + result = await queries_obj.delete_one_rows_test_postgres_type(id_=model.id_ + 1) assert result == 1 @@ -615,7 +605,7 @@ async def test_copy_from( num = 3 rows: list[queries.TestCopyFromParams] = [ queries.TestCopyFromParams( - id=i, + id_=i, int_test=model.int_test, float_test=model.float_test, ) @@ -642,20 +632,16 @@ async def test_create_table( @pytest.mark.dependency( name="TestDataclassClasses::insert_type_override", ) - async def test_insert_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - await queries_obj.insert_type_override(id_=override_model.id, text_test=override_model.text_test) + async def test_insert_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.insert_type_override(id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="TestDataclassClasses::get_one_type_override", depends=["TestDataclassClasses::insert_type_override"], ) - async def test_get_one_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_type_override(id_=override_model.id) + async def test_get_one_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_) assert result is not None assert result == override_model @@ -664,10 +650,8 @@ async def test_get_one_type_override( name="TestDataclassClasses::get_one_type_override_none", depends=["TestDataclassClasses::get_one_type_override"], ) - async def test_get_one_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_type_override(id_=override_model.id - 1) + async def test_get_one_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -675,10 +659,8 @@ async def test_get_one_type_override_none( name="TestDataclassClasses::get_many_type_override", depends=["TestDataclassClasses::get_one_type_override_none"], ) - async def test_get_many_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_many_type_override(id_=override_model.id) + async def test_get_many_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_type_override(id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model @@ -687,10 +669,8 @@ async def test_get_many_type_override( name="TestDataclassClasses::get_one_text_type_override", depends=["TestDataclassClasses::get_many_type_override"], ) - async def test_get_one_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_text_type_override(id_=override_model.id) + async def test_get_one_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -699,10 +679,8 @@ async def test_get_one_text_type_override( name="TestDataclassClasses::get_one_text_type_override_none", depends=["TestDataclassClasses::get_one_text_type_override"], ) - async def test_get_one_text_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_text_type_override(id_=override_model.id - 1) + async def test_get_one_text_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -710,10 +688,8 @@ async def test_get_one_text_type_override_none( name="TestDataclassClasses::get_many_text_type_override", depends=["TestDataclassClasses::get_one_text_type_override_none"], ) - async def test_get_many_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_many_text_type_override(id_=override_model.id) + async def test_get_many_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_text_type_override(id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model.text_test @@ -722,7 +698,5 @@ async def test_get_many_text_type_override( name="TestDataclassClasses::delete_type_override", depends=["TestDataclassClasses::get_many_text_type_override"], ) - async def test_delete_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - await queries_obj.delete_type_override(id_=override_model.id) + async def test_delete_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.delete_type_override(id_=override_model.id_) diff --git a/test/driver_asyncpg/dataclass/test_dataclass_functions.py b/test/driver_asyncpg/dataclass/test_dataclass_functions.py index 205f6584..5734ec0e 100644 --- a/test/driver_asyncpg/dataclass/test_dataclass_functions.py +++ b/test/driver_asyncpg/dataclass/test_dataclass_functions.py @@ -42,12 +42,12 @@ class TestDataclassFunctions: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestPostgresType: return models.TestPostgresType( - id=random.randint(1, 1000000), + id_=random.randint(1, 1000000), serial_test=1, serial4_test=2, bigserial_test=3, @@ -66,9 +66,9 @@ def model(self) -> models.TestPostgresType: bytea_test=memoryview(b"\x00\x01\x02hello"), date_test=datetime.date(2025, 1, 1), time_test=datetime.time(14, 30, 0), - timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.timezone.utc), + timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.UTC), timestamp_test=datetime.datetime(2025, 1, 1, 14, 30, 0), - timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.timezone.utc), + timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.UTC), interval_test=datetime.timedelta(days=1, hours=2, minutes=30), text_test="Lorem ipsum", varchar_test="Example varchar", @@ -88,7 +88,7 @@ def model(self) -> models.TestPostgresType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestPostgresType) -> models.TestInnerPostgresType: return models.TestInnerPostgresType( - table_id=model.id, + table_id=model.id_, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -135,7 +135,7 @@ async def test_create( ) -> None: await queries.create_one_test_postgres_type( conn=asyncpg_conn, - id_=model.id, + id_=model.id_, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -227,7 +227,7 @@ async def test_get_one( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_one_test_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_one_test_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, models.TestPostgresType) @@ -245,9 +245,7 @@ async def test_get_one_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestDataclassFunctions::get_one_none"], name="TestDataclassFunctions::get_one_inner" - ) + @pytest.mark.dependency(depends=["TestDataclassFunctions::get_one_none"], name="TestDataclassFunctions::get_one_inner") async def test_get_one_inner( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], @@ -261,9 +259,7 @@ async def test_get_one_inner( assert result == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestDataclassFunctions::get_one_inner"], name="TestDataclassFunctions::get_one_inner_none" - ) + @pytest.mark.dependency(depends=["TestDataclassFunctions::get_one_inner"], name="TestDataclassFunctions::get_one_inner_none") async def test_get_one_inner_none( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], @@ -282,7 +278,7 @@ async def test_get_one_timestamp( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_one_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_one_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, datetime.datetime) @@ -311,7 +307,7 @@ async def test_get_one_bytea( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_one_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_one_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, memoryview) @@ -331,15 +327,13 @@ async def test_get_one_bytea_none( assert result is None @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestDataclassFunctions::get_one_bytea_none"], name="TestDataclassFunctions::get_many" - ) + @pytest.mark.dependency(depends=["TestDataclassFunctions::get_one_bytea_none"], name="TestDataclassFunctions::get_many") async def test_get_many( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_many_test_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_many_test_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -358,7 +352,7 @@ async def test_get_many_timestamp( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_many_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_many_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -376,7 +370,7 @@ async def test_get_many_bytea( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_many_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_many_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -395,13 +389,13 @@ async def test_get_embedded( model: models.TestPostgresType, inner_model: models.TestInnerPostgresType, ) -> None: - result = await queries.get_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, queries.GetEmbeddedTestPostgresTypeRow) assert isinstance(result.test_inner_postgres_type, models.TestInnerPostgresType) - assert result.id == model.id + assert result.id_ == model.id_ assert result.serial_test == model.serial_test assert result.serial4_test == model.serial4_test assert result.bigserial_test == model.bigserial_test @@ -464,7 +458,7 @@ async def test_get_all_embedded( model: models.TestPostgresType, inner_model: models.TestInnerPostgresType, ) -> None: - result = await queries.get_all_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_all_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, queries.GetAllEmbeddedTestPostgresTypeRow) @@ -497,7 +491,7 @@ async def test_get_many_iterator( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - results = queries.get_many_test_iterator_postgres_type(conn=asyncpg_conn, id_=model.id) + results = queries.get_many_test_iterator_postgres_type(conn=asyncpg_conn, id_=model.id_) async with asyncpg_conn.transaction(): async for result in results: assert result is not None @@ -515,7 +509,7 @@ async def test_delete( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - await queries.delete_one_test_postgres_type(conn=asyncpg_conn, id_=model.id) + await queries.delete_one_test_postgres_type(conn=asyncpg_conn, id_=model.id_) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestDataclassFunctions::delete"], name="TestDataclassFunctions::delete_inner") @@ -535,7 +529,7 @@ async def test_create_result( ) -> None: result = await queries.create_result_one_test_postgres_type( conn=asyncpg_conn, - id_=model.id + 1, + id_=model.id_ + 1, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -585,7 +579,7 @@ async def test_update_result( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.update_result_test_postgres_type(conn=asyncpg_conn, id_=model.id + 1) + result = await queries.update_result_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) assert result == "UPDATE 1" @@ -599,7 +593,7 @@ async def test_delete_result( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.delete_one_result_test_postgres_type(conn=asyncpg_conn, id_=model.id + 1) + result = await queries.delete_one_result_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) assert result == "DELETE 1" @@ -612,7 +606,7 @@ async def test_create_rows( ) -> None: result = await queries.create_rows_one_test_postgres_type( conn=asyncpg_conn, - id_=model.id + 1, + id_=model.id_ + 1, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -659,7 +653,7 @@ async def test_update_rows( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.update_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id + 1) + result = await queries.update_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) assert result == 1 @@ -670,7 +664,7 @@ async def test_delete_rows( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.delete_one_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id + 1) + result = await queries.delete_one_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) assert result == 1 @@ -684,7 +678,7 @@ async def test_copy_from( num = 3 rows: list[queries.TestCopyFromParams] = [ queries.TestCopyFromParams( - id=i, + id_=i, int_test=model.int_test, float_test=model.float_test, ) @@ -710,20 +704,16 @@ async def test_create_table( @pytest.mark.dependency( name="TestDataclassFunctions::insert_type_override", ) - async def test_insert_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - await queries.insert_type_override(conn=asyncpg_conn, id_=override_model.id, text_test=override_model.text_test) + async def test_insert_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + await queries.insert_type_override(conn=asyncpg_conn, id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="TestDataclassFunctions::get_one_type_override", depends=["TestDataclassFunctions::insert_type_override"], ) - async def test_get_one_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_get_one_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id_) assert result is not None assert result == override_model @@ -732,10 +722,8 @@ async def test_get_one_type_override( name="TestDataclassFunctions::get_one_type_override_none", depends=["TestDataclassFunctions::get_one_type_override"], ) - async def test_get_one_type_override_none( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id - 1) + async def test_get_one_type_override_none(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -743,10 +731,8 @@ async def test_get_one_type_override_none( name="TestDataclassFunctions::get_many_type_override", depends=["TestDataclassFunctions::get_one_type_override_none"], ) - async def test_get_many_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_many_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_get_many_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_type_override(conn=asyncpg_conn, id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model @@ -755,10 +741,8 @@ async def test_get_many_type_override( name="TestDataclassFunctions::get_one_text_type_override", depends=["TestDataclassFunctions::get_many_type_override"], ) - async def test_get_one_text_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_get_one_text_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -767,10 +751,8 @@ async def test_get_one_text_type_override( name="TestDataclassFunctions::get_one_text_type_override_none", depends=["TestDataclassFunctions::get_one_text_type_override"], ) - async def test_get_one_text_type_override_none( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id - 1) + async def test_get_one_text_type_override_none(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -778,10 +760,8 @@ async def test_get_one_text_type_override_none( name="TestDataclassFunctions::get_many_text_type_override", depends=["TestDataclassFunctions::get_one_text_type_override_none"], ) - async def test_get_many_text_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_many_text_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_get_many_text_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_text_type_override(conn=asyncpg_conn, id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model.text_test @@ -790,7 +770,5 @@ async def test_get_many_text_type_override( name="TestDataclassFunctions::delete_type_override", depends=["TestDataclassFunctions::get_many_text_type_override"], ) - async def test_delete_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - await queries.delete_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_delete_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + await queries.delete_type_override(conn=asyncpg_conn, id_=override_model.id_) diff --git a/test/driver_asyncpg/msgspec/classes/__init__.py b/test/driver_asyncpg/msgspec/classes/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_asyncpg/msgspec/classes/__init__.py +++ b/test/driver_asyncpg/msgspec/classes/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_asyncpg/msgspec/classes/enums.py b/test/driver_asyncpg/msgspec/classes/enums.py new file mode 100644 index 00000000..d49ac611 --- /dev/null +++ b/test/driver_asyncpg/msgspec/classes/enums.py @@ -0,0 +1,23 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing enums.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("TestMood",) + +import enum +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +class TestMood(enum.StrEnum): + """Enum representing TestMood.""" + + SAD = "sad" + OK = "ok" + HAPPY = "happy" diff --git a/test/driver_asyncpg/msgspec/classes/models.py b/test/driver_asyncpg/msgspec/classes/models.py index ec0755b3..bca5442e 100644 --- a/test/driver_asyncpg/msgspec/classes/models.py +++ b/test/driver_asyncpg/msgspec/classes/models.py @@ -1,11 +1,14 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( + "TestEnumOverride", + "TestEnumType", "TestInnerPostgresType", "TestPostgresType", "TestTypeOverride", @@ -16,12 +19,39 @@ if typing.TYPE_CHECKING: from collections import UserString + from test.driver_asyncpg.msgspec.classes import enums import collections.abc import datetime import decimal import uuid +class TestEnumOverride(msgspec.Struct): + """Model representing TestEnumOverride. + + Attributes: + id_ -- int + mood_test -- str + """ + + id_: int + mood_test: str + + +class TestEnumType(msgspec.Struct): + """Model representing TestEnumType. + + Attributes: + id_ -- int + mood -- enums.TestMood + maybe_mood -- enums.TestMood | None + """ + + id_: int + mood: enums.TestMood + maybe_mood: enums.TestMood | None + + class TestInnerPostgresType(msgspec.Struct): """Model representing TestInnerPostgresType. @@ -106,7 +136,7 @@ class TestPostgresType(msgspec.Struct): """Model representing TestPostgresType. Attributes: - id -- int + id_ -- int serial_test -- int serial4_test -- int bigserial_test -- int @@ -144,7 +174,7 @@ class TestPostgresType(msgspec.Struct): ltxtquery_test -- str """ - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -186,9 +216,9 @@ class TestTypeOverride(msgspec.Struct): """Model representing TestTypeOverride. Attributes: - id -- int + id_ -- int text_test -- UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_asyncpg/msgspec/classes/queries.py b/test/driver_asyncpg/msgspec/classes/queries.py index 5e865023..31f0064e 100644 --- a/test/driver_asyncpg/msgspec/classes/queries.py +++ b/test/driver_asyncpg/msgspec/classes/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -14,7 +16,6 @@ ) from collections import UserString -import datetime import msgspec import operator import typing @@ -23,33 +24,23 @@ import asyncpg import asyncpg.cursor import collections.abc + import datetime import decimal import uuid - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None - ConnectionLike: typing.TypeAlias = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] +from test.driver_asyncpg.msgspec.classes import enums from test.driver_asyncpg.msgspec.classes import models -class GetAllEmbeddedTestPostgresTypeRow(msgspec.Struct): - """Model representing GetAllEmbeddedTestPostgresTypeRow. - - Attributes: - test_postgres_type -- models.TestPostgresType - test_inner_postgres_type -- models.TestInnerPostgresType - """ - - test_postgres_type: models.TestPostgresType - test_inner_postgres_type: models.TestInnerPostgresType - - class GetEmbeddedTestPostgresTypeRow(msgspec.Struct): """Model representing GetEmbeddedTestPostgresTypeRow. Attributes: - id -- int + id_ -- int serial_test -- int serial4_test -- int bigserial_test -- int @@ -88,7 +79,7 @@ class GetEmbeddedTestPostgresTypeRow(msgspec.Struct): test_inner_postgres_type -- models.TestInnerPostgresType """ - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -127,62 +118,92 @@ class GetEmbeddedTestPostgresTypeRow(msgspec.Struct): test_inner_postgres_type: models.TestInnerPostgresType +class GetAllEmbeddedTestPostgresTypeRow(msgspec.Struct): + """Model representing GetAllEmbeddedTestPostgresTypeRow. + + Attributes: + test_postgres_type -- models.TestPostgresType + test_inner_postgres_type -- models.TestInnerPostgresType + """ + + test_postgres_type: models.TestPostgresType + test_inner_postgres_type: models.TestInnerPostgresType + + class TestCopyFromParams(msgspec.Struct): """Model representing TestCopyFromParams. Attributes: - id -- int + id_ -- int float_test -- float int_test -- int """ - id: int + id_: int float_test: float int_test: int -CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec -INSERT INTO test_inner_postgres_types (table_id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) -VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) +GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one +SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_inner_postgres_types +WHERE table_id = $1 LIMIT 1 +""" + +GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 +""" + +GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 """ CREATE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresType :exec @@ -229,6 +250,62 @@ class TestCopyFromParams(msgspec.Struct): $33, $34, $35, $36) """ +CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec +INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec +DELETE +FROM test_inner_postgres_types +WHERE test_inner_postgres_types.table_id = $1 +""" + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateResultOneTestPostgresType :execresult INSERT INTO test_postgres_types (id, serial_test, @@ -273,6 +350,18 @@ class TestCopyFromParams(msgspec.Struct): $33, $34, $35, $36) """ +UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateRowsOneTestPostgresType :execrows INSERT INTO test_postgres_types (id, serial_test, @@ -317,6 +406,18 @@ class TestCopyFromParams(msgspec.Struct): $33, $34, $35, $36) """ +UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows CREATE TABLE test_create_rows_table ( @@ -325,28 +426,32 @@ class TestCopyFromParams(msgspec.Struct): ) """ -DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom +INSERT INTO test_copy_from (id, + float_test, int_test) +VALUES ($1, $2, $3) """ -DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec +INSERT INTO test_type_override ( + id, text_test +) VALUES ($1 ,$2) """ -DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec -DELETE -FROM test_inner_postgres_types -WHERE test_inner_postgres_types.table_id = $1 +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = $1 """ -DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 """ DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec @@ -355,113 +460,37 @@ class TestCopyFromParams(msgspec.Struct): WHERE test_type_override.id = $1 """ -GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one -SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id -WHERE test_postgres_types.id = $1 +INSERT_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: InsertOneTestEnumType :exec +INSERT INTO test_enum_types (id, mood, maybe_mood) +VALUES ($1, $2, $3) """ -GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one -SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id -WHERE test_postgres_types.id = $1 +GET_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: GetOneTestEnumType :one +SELECT id, mood, maybe_mood +FROM test_enum_types +WHERE id = $1 """ -GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many -SELECT bytea_test -FROM test_postgres_types -WHERE id = $1 LIMIT 2 -""" - -GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types +GET_ONE_TEST_ENUM_VALUE: typing.Final[str] = """-- name: GetOneTestEnumValue :one +SELECT mood +FROM test_enum_types WHERE id = $1 """ -GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types -WHERE id = $1 -""" - -GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many -SELECT timestamp_test -FROM test_postgres_types -WHERE id = $1 LIMIT 2 -""" - -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one -SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_inner_postgres_types -WHERE table_id = $1 LIMIT 1 -""" - -GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one -SELECT bytea_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one -SELECT timestamp_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = $1 -""" - -INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec -INSERT INTO test_type_override ( - id, text_test -) VALUES ($1 ,$2) -""" - -TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom -INSERT INTO test_copy_from (id, - float_test, int_test) -VALUES ($1, $2, $3) -""" - -UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult -UPDATE test_postgres_types -SET serial_test = 187 -WHERE test_postgres_types.id = $1 +GET_MANY_TEST_ENUM_TYPES: typing.Final[str] = """-- name: GetManyTestEnumTypes :many +SELECT id, mood, maybe_mood +FROM test_enum_types +ORDER BY id """ -UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows -UPDATE test_postgres_types -SET serial_test = 187 -WHERE test_postgres_types.id = $1 +DELETE_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: DeleteOneTestEnumType :execrows +DELETE +FROM test_enum_types +WHERE id = $1 """ -T = typing.TypeVar("T") - - -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db.""" __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") @@ -504,9 +533,11 @@ def __await__( Returns: A sequence of decoded objects of type `T`. """ + async def _wrapper() -> collections.abc.Sequence[T]: result = await self._conn.fetch(self._sql, *self._args) return [self._decode_hook(row) for row in result] + return _wrapper().__await__() async def __anext__(self) -> T: @@ -552,182 +583,549 @@ def conn(self) -> ConnectionLike: """ return self._conn - async def create_one_test_postgres_inner_type(self, *, table_id: int, serial_test: int | None, serial4_test: int | None, bigserial_test: int | None, smallserial_test: int | None, int_test: int | None, bigint_test: int | None, smallint_test: int | None, float_test: float | None, double_precision_test: float | None, real_test: float | None, numeric_test: decimal.Decimal | None, money_test: str | None, bool_test: bool | None, json_test: str | None, jsonb_test: str | None, bytea_test: memoryview | None, date_test: datetime.date | None, time_test: datetime.time | None, timetz_test: datetime.time | None, timestamp_test: datetime.datetime | None, timestamptz_test: datetime.datetime | None, interval_test: datetime.timedelta | None, text_test: str | None, varchar_test: str | None, bpchar_test: str | None, char_test: str | None, citext_test: str | None, uuid_test: uuid.UUID | None, inet_test: str | None, cidr_test: str | None, macaddr_test: str | None, macaddr8_test: str | None, ltree_test: str | None, lquery_test: str | None, ltxtquery_test: str | None) -> None: - """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. + async def get_one_test_postgres_type(self, *, id_: int) -> models.TestPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. ```sql - INSERT INTO test_inner_postgres_types (table_id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Arguments: + id_ -- int. + + Returns: + models.TestPostgresType -- Result fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + async def get_one_inner_test_postgres_type(self, *, table_id: int) -> models.TestInnerPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + + ```sql + SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_inner_postgres_types + WHERE table_id = $1 LIMIT 1 ``` Arguments: table_id -- int. - serial_test -- int | None. - serial4_test -- int | None. - bigserial_test -- int | None. - smallserial_test -- int | None. - int_test -- int | None. - bigint_test -- int | None. - smallint_test -- int | None. - float_test -- float | None. - double_precision_test -- float | None. - real_test -- float | None. - numeric_test -- decimal.Decimal | None. - money_test -- str | None. - bool_test -- bool | None. - json_test -- str | None. - jsonb_test -- str | None. - bytea_test -- memoryview | None. - date_test -- datetime.date | None. - time_test -- datetime.time | None. - timetz_test -- datetime.time | None. - timestamp_test -- datetime.datetime | None. - timestamptz_test -- datetime.datetime | None. - interval_test -- datetime.timedelta | None. - text_test -- str | None. - varchar_test -- str | None. - bpchar_test -- str | None. - char_test -- str | None. - citext_test -- str | None. - uuid_test -- uuid.UUID | None. - inet_test -- str | None. - cidr_test -- str | None. - macaddr_test -- str | None. - macaddr8_test -- str | None. - ltree_test -- str | None. - lquery_test -- str | None. - ltxtquery_test -- str | None. + + Returns: + models.TestInnerPostgresType -- Result fetched from the db. Will be `None` if not found. """ - await self._conn.execute(CREATE_ONE_TEST_POSTGRES_INNER_TYPE, table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + row = await self._conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + if row is None: + return None + return models.TestInnerPostgresType( + table_id=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]) if row[16] is not None else None, + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]) if row[29] is not None else None, + cidr_test=str(row[30]) if row[30] is not None else None, + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) - async def create_one_test_postgres_type(self, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> None: - """Execute SQL query with `name: CreateOneTestPostgresType :exec`. + async def get_one_test_timestamp_postgres_type(self, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. ```sql - INSERT INTO test_postgres_types (id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 ``` Arguments: id_ -- int. - serial_test -- int. - serial4_test -- int. - bigserial_test -- int. - smallserial_test -- int. - int_test -- int. - bigint_test -- int. - smallint_test -- int. - float_test -- float. - double_precision_test -- float. - real_test -- float. - numeric_test -- decimal.Decimal. - money_test -- str. - bool_test -- bool. - json_test -- str. - jsonb_test -- str. - bytea_test -- memoryview. - date_test -- datetime.date. - time_test -- datetime.time. - timetz_test -- datetime.time. - timestamp_test -- datetime.datetime. - timestamptz_test -- datetime.datetime. - interval_test -- datetime.timedelta. - text_test -- str. - varchar_test -- str. - bpchar_test -- str. - char_test -- str. - citext_test -- str. - uuid_test -- uuid.UUID. - inet_test -- str. - cidr_test -- str. - macaddr_test -- str. - macaddr8_test -- str. - ltree_test -- str. - lquery_test -- str. - ltxtquery_test -- str. + + Returns: + datetime.datetime -- Result fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) + if row is None: + return None + return row[0] + + async def get_one_test_bytea_postgres_type(self, *, id_: int) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Arguments: + id_ -- int. + + Returns: + memoryview -- Result fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) + if row is None: + return None + return memoryview(row[0]) + + def get_many_test_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Arguments: + id_ -- int. + + Returns: + QueryResults[models.TestPostgresType] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(self._conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + + def get_many_test_iterator_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Arguments: + id_ -- int. + + Returns: + QueryResults[models.TestPostgresType] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(self._conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) + + def get_many_test_timestamp_postgres_type(self, *, id_: int) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. + + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Arguments: + id_ -- int. + + Returns: + QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + + def get_many_test_bytea_postgres_type(self, *, id_: int) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Arguments: + id_ -- int. + + Returns: + QueryResults[memoryview] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> memoryview: + return memoryview(row[0]) + + return QueryResults(self._conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + + async def get_embedded_test_postgres_type(self, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Arguments: + id_ -- int. + + Returns: + GetEmbeddedTestPostgresTypeRow -- Result fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetEmbeddedTestPostgresTypeRow( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + async def get_all_embedded_test_postgres_type(self, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Arguments: + id_ -- int. + + Returns: + GetAllEmbeddedTestPostgresTypeRow -- Result fetched from the db. Will be `None` if not found. """ - await self._conn.execute(CREATE_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + row = await self._conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetAllEmbeddedTestPostgresTypeRow( + test_postgres_type=models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ), + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) - async def create_result_one_test_postgres_type(self, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> str: - """Execute and return the result of SQL query with `name: CreateResultOneTestPostgresType :execresult`. + async def create_one_test_postgres_type( + self, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, + ) -> None: + """Execute SQL query with `name: CreateOneTestPostgresType :exec`. ```sql INSERT INTO test_postgres_types (id, @@ -810,14 +1208,280 @@ async def create_result_one_test_postgres_type(self, *, id_: int, serial_test: i ltree_test -- str. lquery_test -- str. ltxtquery_test -- str. + """ + await self._conn.execute( + CREATE_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) - Returns: - str -- The result returned when executing the query. + async def create_one_test_postgres_inner_type( + self, + *, + table_id: int, + serial_test: int | None, + serial4_test: int | None, + bigserial_test: int | None, + smallserial_test: int | None, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + float_test: float | None, + double_precision_test: float | None, + real_test: float | None, + numeric_test: decimal.Decimal | None, + money_test: str | None, + bool_test: bool | None, + json_test: str | None, + jsonb_test: str | None, + bytea_test: memoryview | None, + date_test: datetime.date | None, + time_test: datetime.time | None, + timetz_test: datetime.time | None, + timestamp_test: datetime.datetime | None, + timestamptz_test: datetime.datetime | None, + interval_test: datetime.timedelta | None, + text_test: str | None, + varchar_test: str | None, + bpchar_test: str | None, + char_test: str | None, + citext_test: str | None, + uuid_test: uuid.UUID | None, + inet_test: str | None, + cidr_test: str | None, + macaddr_test: str | None, + macaddr8_test: str | None, + ltree_test: str | None, + lquery_test: str | None, + ltxtquery_test: str | None, + ) -> None: + """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. + + ```sql + INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Arguments: + table_id -- int. + serial_test -- int | None. + serial4_test -- int | None. + bigserial_test -- int | None. + smallserial_test -- int | None. + int_test -- int | None. + bigint_test -- int | None. + smallint_test -- int | None. + float_test -- float | None. + double_precision_test -- float | None. + real_test -- float | None. + numeric_test -- decimal.Decimal | None. + money_test -- str | None. + bool_test -- bool | None. + json_test -- str | None. + jsonb_test -- str | None. + bytea_test -- memoryview | None. + date_test -- datetime.date | None. + time_test -- datetime.time | None. + timetz_test -- datetime.time | None. + timestamp_test -- datetime.datetime | None. + timestamptz_test -- datetime.datetime | None. + interval_test -- datetime.timedelta | None. + text_test -- str | None. + varchar_test -- str | None. + bpchar_test -- str | None. + char_test -- str | None. + citext_test -- str | None. + uuid_test -- uuid.UUID | None. + inet_test -- str | None. + cidr_test -- str | None. + macaddr_test -- str | None. + macaddr8_test -- str | None. + ltree_test -- str | None. + lquery_test -- str | None. + ltxtquery_test -- str | None. """ - return await self._conn.execute(CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + await self._conn.execute( + CREATE_ONE_TEST_POSTGRES_INNER_TYPE, + table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) - async def create_rows_one_test_postgres_type(self, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> int: - """Execute SQL query with `name: CreateRowsOneTestPostgresType :execrows` and return the number of affected rows. + async def delete_one_test_postgres_type(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + + Arguments: + id_ -- int. + """ + await self._conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) + + async def delete_one_test_postgres_inner_type(self, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. + + ```sql + DELETE + FROM test_inner_postgres_types + WHERE test_inner_postgres_types.table_id = $1 + ``` + + Arguments: + table_id -- int. + """ + await self._conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) + + async def create_result_one_test_postgres_type( + self, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, + ) -> str: + """Execute and return the result of SQL query with `name: CreateResultOneTestPostgresType :execresult`. ```sql INSERT INTO test_postgres_types (id, @@ -902,34 +1566,54 @@ async def create_rows_one_test_postgres_type(self, *, id_: int, serial_test: int ltxtquery_test -- str. Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + str -- The result returned when executing the query. """ - r = await self._conn.execute(CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - - async def create_rows_table(self) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. - - ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL + return await self._conn.execute( + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, ) - ``` - - Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - """ - r = await self._conn.execute(CREATE_ROWS_TABLE) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - async def delete_one_result_test_postgres_type(self, *, id_: int) -> str: - """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. + async def update_result_test_postgres_type(self, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. ```sql - DELETE - FROM test_postgres_types + UPDATE test_postgres_types + SET serial_test = 187 WHERE test_postgres_types.id = $1 ``` @@ -939,10 +1623,10 @@ async def delete_one_result_test_postgres_type(self, *, id_: int) -> str: Returns: str -- The result returned when executing the query. """ - return await self._conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) + return await self._conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) - async def delete_one_rows_test_postgres_type(self, *, id_: int) -> int: - """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. + async def delete_one_result_test_postgres_type(self, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. ```sql DELETE @@ -954,81 +1638,184 @@ async def delete_one_rows_test_postgres_type(self, *, id_: int) -> int: id_ -- int. Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - """ - r = await self._conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - - async def delete_one_test_postgres_inner_type(self, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. - - ```sql - DELETE - FROM test_inner_postgres_types - WHERE test_inner_postgres_types.table_id = $1 - ``` - - Arguments: - table_id -- int. - """ - await self._conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) - - async def delete_one_test_postgres_type(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. - - ```sql - DELETE - FROM test_postgres_types - WHERE test_postgres_types.id = $1 - ``` - - Arguments: - id_ -- int. - """ - await self._conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) - - async def delete_type_override(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. - - ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = $1 - ``` - - Arguments: - id_ -- int. + str -- The result returned when executing the query. """ - await self._conn.execute(DELETE_TYPE_OVERRIDE, id_) + return await self._conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) - async def get_all_embedded_test_postgres_type(self, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: - """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. + async def create_rows_one_test_postgres_type( + self, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, + ) -> int: + """Execute SQL query with `name: CreateRowsOneTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test - FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id - WHERE test_postgres_types.id = $1 + INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) ``` Arguments: id_ -- int. + serial_test -- int. + serial4_test -- int. + bigserial_test -- int. + smallserial_test -- int. + int_test -- int. + bigint_test -- int. + smallint_test -- int. + float_test -- float. + double_precision_test -- float. + real_test -- float. + numeric_test -- decimal.Decimal. + money_test -- str. + bool_test -- bool. + json_test -- str. + jsonb_test -- str. + bytea_test -- memoryview. + date_test -- datetime.date. + time_test -- datetime.time. + timetz_test -- datetime.time. + timestamp_test -- datetime.datetime. + timestamptz_test -- datetime.datetime. + interval_test -- datetime.timedelta. + text_test -- str. + varchar_test -- str. + bpchar_test -- str. + char_test -- str. + citext_test -- str. + uuid_test -- uuid.UUID. + inet_test -- str. + cidr_test -- str. + macaddr_test -- str. + macaddr8_test -- str. + ltree_test -- str. + lquery_test -- str. + ltxtquery_test -- str. Returns: - GetAllEmbeddedTestPostgresTypeRow -- Result fetched from the db. Will be `None` if not found. + int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - row = await self._conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return GetAllEmbeddedTestPostgresTypeRow(test_postgres_type=models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]), test_inner_postgres_type=models.TestInnerPostgresType(table_id=row[36], serial_test=row[37], serial4_test=row[38], bigserial_test=row[39], smallserial_test=row[40], int_test=row[41], bigint_test=row[42], smallint_test=row[43], float_test=row[44], double_precision_test=row[45], real_test=row[46], numeric_test=row[47], money_test=row[48], bool_test=row[49], json_test=row[50], jsonb_test=row[51], bytea_test=memoryview(row[52]) if row[52] is not None else None, date_test=row[53], time_test=row[54], timetz_test=row[55], timestamp_test=row[56], timestamptz_test=row[57], interval_test=row[58], text_test=row[59], varchar_test=row[60], bpchar_test=row[61], char_test=row[62], citext_test=row[63], uuid_test=row[64], inet_test=str(row[65]) if row[65] is not None else None, cidr_test=str(row[66]) if row[66] is not None else None, macaddr_test=row[67], macaddr8_test=row[68], ltree_test=row[69], lquery_test=row[70], ltxtquery_test=row[71])) + r = await self._conn.execute( + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - async def get_embedded_test_postgres_type(self, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: - """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. + async def update_rows_test_postgres_type(self, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test - FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + UPDATE test_postgres_types + SET serial_test = 187 WHERE test_postgres_types.id = $1 ``` @@ -1036,101 +1823,91 @@ async def get_embedded_test_postgres_type(self, *, id_: int) -> GetEmbeddedTestP id_ -- int. Returns: - GetEmbeddedTestPostgresTypeRow -- Result fetched from the db. Will be `None` if not found. + int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - row = await self._conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return GetEmbeddedTestPostgresTypeRow(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35], test_inner_postgres_type=models.TestInnerPostgresType(table_id=row[36], serial_test=row[37], serial4_test=row[38], bigserial_test=row[39], smallserial_test=row[40], int_test=row[41], bigint_test=row[42], smallint_test=row[43], float_test=row[44], double_precision_test=row[45], real_test=row[46], numeric_test=row[47], money_test=row[48], bool_test=row[49], json_test=row[50], jsonb_test=row[51], bytea_test=memoryview(row[52]) if row[52] is not None else None, date_test=row[53], time_test=row[54], timetz_test=row[55], timestamp_test=row[56], timestamptz_test=row[57], interval_test=row[58], text_test=row[59], varchar_test=row[60], bpchar_test=row[61], char_test=row[62], citext_test=row[63], uuid_test=row[64], inet_test=str(row[65]) if row[65] is not None else None, cidr_test=str(row[66]) if row[66] is not None else None, macaddr_test=row[67], macaddr8_test=row[68], ltree_test=row[69], lquery_test=row[70], ltxtquery_test=row[71])) + r = await self._conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - def get_many_test_bytea_postgres_type(self, *, id_: int) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. + async def delete_one_rows_test_postgres_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT bytea_test + DELETE FROM test_postgres_types - WHERE id = $1 LIMIT 2 + WHERE test_postgres_types.id = $1 ``` Arguments: id_ -- int. Returns: - QueryResults[memoryview] -- Helper class that allows both iteration and normal fetching of data from the db. + int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - def _decode_hook(row: asyncpg.Record) -> memoryview: - return memoryview(row[0]) - return QueryResults[memoryview](self._conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + r = await self._conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - def get_many_test_iterator_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: - """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. + async def create_rows_table(self) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) ``` - Arguments: - id_ -- int. - Returns: - QueryResults[models.TestPostgresType] -- Helper class that allows both iteration and normal fetching of data from the db. + int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) - return QueryResults[models.TestPostgresType](self._conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) - - def get_many_test_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: - """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. + r = await self._conn.execute(CREATE_ROWS_TABLE) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 - ``` + async def test_copy_from(self, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. Arguments: - id_ -- int. + params -- collections.abc.Sequence[TestCopyFromParams]. A list of params for rows that should be inserted. Returns: - QueryResults[models.TestPostgresType] -- Helper class that allows both iteration and normal fetching of data from the db. + int -- The number of affected rows. """ - def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) - return QueryResults[models.TestPostgresType](self._conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + records = [(param.id_, param.float_test, param.int_test) for param in params] + r = await self._conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - def get_many_test_timestamp_postgres_type(self, *, id_: int) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. + async def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: + """Execute SQL query with `name: InsertTypeOverride :exec`. ```sql - SELECT timestamp_test - FROM test_postgres_types - WHERE id = $1 LIMIT 2 + INSERT INTO test_type_override ( + id, text_test + ) VALUES ($1 ,$2) ``` Arguments: id_ -- int. - - Returns: - QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. + text_test -- UserString | None. """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + await self._conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test) if text_test is not None else None) - def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + SELECT id, text_test FROM test_type_override WHERE id = $1 ``` Arguments: id_ -- int. Returns: - QueryResults[UserString] -- Helper class that allows both iteration and normal fetching of data from the db. + models.TestTypeOverride -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[UserString](self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, operator.itemgetter(0), id_) + row = await self._conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. @@ -1145,188 +1922,150 @@ def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOve Returns: QueryResults[models.TestTypeOverride] -- Helper class that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: asyncpg.Record) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - return QueryResults[models.TestTypeOverride](self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - async def get_one_inner_test_postgres_type(self, *, table_id: int) -> models.TestInnerPostgresType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + return QueryResults(self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + async def get_one_text_type_override(self, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_inner_postgres_types - WHERE table_id = $1 LIMIT 1 + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 ``` Arguments: - table_id -- int. + id_ -- int. Returns: - models.TestInnerPostgresType -- Result fetched from the db. Will be `None` if not found. + UserString -- Result fetched from the db. Will be `None` if not found. """ - row = await self._conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + row = await self._conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) if row is None: return None - return models.TestInnerPostgresType(table_id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]) if row[16] is not None else None, date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]) if row[29] is not None else None, cidr_test=str(row[30]) if row[30] is not None else None, macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) + return UserString(row[0]) if row[0] is not None else None - async def get_one_test_bytea_postgres_type(self, *, id_: int) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. + def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. ```sql - SELECT bytea_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 ``` Arguments: id_ -- int. Returns: - memoryview -- Result fetched from the db. Will be `None` if not found. + QueryResults[UserString | None] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = await self._conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) - if row is None: - return None - return memoryview(row[0]) - async def get_one_test_postgres_type(self, *, id_: int) -> models.TestPostgresType | None: - """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. + def _decode_hook(row: asyncpg.Record) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + async def delete_type_override(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + DELETE + FROM test_type_override + WHERE test_type_override.id = $1 ``` Arguments: id_ -- int. - - Returns: - models.TestPostgresType -- Result fetched from the db. Will be `None` if not found. """ - row = await self._conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) + await self._conn.execute(DELETE_TYPE_OVERRIDE, id_) - async def get_one_test_timestamp_postgres_type(self, *, id_: int) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. + async def insert_one_test_enum_type(self, *, id_: int, mood: enums.TestMood, maybe_mood: enums.TestMood | None) -> None: + """Execute SQL query with `name: InsertOneTestEnumType :exec`. ```sql - SELECT timestamp_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + INSERT INTO test_enum_types (id, mood, maybe_mood) + VALUES ($1, $2, $3) ``` Arguments: id_ -- int. - - Returns: - datetime.datetime -- Result fetched from the db. Will be `None` if not found. + mood -- enums.TestMood. + maybe_mood -- enums.TestMood | None. """ - row = await self._conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) - if row is None: - return None - return row[0] + await self._conn.execute(INSERT_ONE_TEST_ENUM_TYPE, id_, mood, maybe_mood) - async def get_one_text_type_override(self, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + async def get_one_test_enum_type(self, *, id_: int) -> models.TestEnumType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumType :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + SELECT id, mood, maybe_mood + FROM test_enum_types + WHERE id = $1 ``` Arguments: id_ -- int. Returns: - UserString -- Result fetched from the db. Will be `None` if not found. + models.TestEnumType -- Result fetched from the db. Will be `None` if not found. """ - row = await self._conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) + row = await self._conn.fetchrow(GET_ONE_TEST_ENUM_TYPE, id_) if row is None: return None - return row[0] + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) - async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + async def get_one_test_enum_value(self, *, id_: int) -> enums.TestMood | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumValue :one`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = $1 + SELECT mood + FROM test_enum_types + WHERE id = $1 ``` Arguments: id_ -- int. Returns: - models.TestTypeOverride -- Result fetched from the db. Will be `None` if not found. + enums.TestMood -- Result fetched from the db. Will be `None` if not found. """ - row = await self._conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + row = await self._conn.fetchrow(GET_ONE_TEST_ENUM_VALUE, id_) if row is None: return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + return enums.TestMood(row[0]) - async def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: - """Execute SQL query with `name: InsertTypeOverride :exec`. + def get_many_test_enum_types(self) -> QueryResults[models.TestEnumType]: + """Fetch many from the db using the SQL query with `name: GetManyTestEnumTypes :many`. ```sql - INSERT INTO test_type_override ( - id, text_test - ) VALUES ($1 ,$2) + SELECT id, mood, maybe_mood + FROM test_enum_types + ORDER BY id ``` - Arguments: - id_ -- int. - text_test -- UserString | None. - """ - await self._conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test)) - - async def test_copy_from(self, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: - """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. - - Arguments: - params -- collections.abc.Sequence[TestCopyFromParams]. A list of params for rows that should be inserted. - Returns: - int -- The number of affected rows. + QueryResults[models.TestEnumType] -- Helper class that allows both iteration and normal fetching of data from the db. """ - records = [ - (param.id, param.float_test, param.int_test) - for param in params - ] - r = await self._conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - - async def update_result_test_postgres_type(self, *, id_: int) -> str: - """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. - - ```sql - UPDATE test_postgres_types - SET serial_test = 187 - WHERE test_postgres_types.id = $1 - ``` - Arguments: - id_ -- int. + def _decode_hook(row: asyncpg.Record) -> models.TestEnumType: + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) - Returns: - str -- The result returned when executing the query. - """ - return await self._conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) + return QueryResults(self._conn, GET_MANY_TEST_ENUM_TYPES, _decode_hook) - async def update_rows_test_postgres_type(self, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. + async def delete_one_test_enum_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneTestEnumType :execrows` and return the number of affected rows. ```sql - UPDATE test_postgres_types - SET serial_test = 187 - WHERE test_postgres_types.id = $1 + DELETE + FROM test_enum_types + WHERE id = $1 ``` Arguments: id_ -- int. Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - r = await self._conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + r = await self._conn.execute(DELETE_ONE_TEST_ENUM_TYPE, id_) return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 diff --git a/test/driver_asyncpg/msgspec/classes/queries_copy_override.py b/test/driver_asyncpg/msgspec/classes/queries_copy_override.py new file mode 100644 index 00000000..d849826c --- /dev/null +++ b/test/driver_asyncpg/msgspec/classes/queries_copy_override.py @@ -0,0 +1,109 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_copy_override.sql +"""Module containing queries from file queries_copy_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "CopyOverrideRowsParams", + "QueriesCopyOverride", +) + +import decimal +import msgspec +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import collections.abc + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + + +class CopyOverrideRowsParams(msgspec.Struct): + """Model representing CopyOverrideRowsParams. + + Attributes: + id_ -- int + amount -- float + """ + + id_: int + amount: float + + +COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CopyOverrideRows :copyfrom +INSERT INTO test_copy_override (id, amount) VALUES ($1, $2) +""" + +COUNT_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CountCopyOverrideRows :one +SELECT count(*) FROM test_copy_override +""" + +DELETE_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: DeleteCopyOverrideRows :exec +DELETE FROM test_copy_override +""" + + +class QueriesCopyOverride: + """Queries from file queries_copy_override.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: ConnectionLike) -> None: + """Initialize the instance using the connection. + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute queries. + """ + self._conn = conn + + @property + def conn(self) -> ConnectionLike: + """Connection object used to make queries. + + Returns: + ConnectionLike -- Connection object used to make queries. + """ + return self._conn + + async def copy_override_rows(self, *, params: collections.abc.Sequence[CopyOverrideRowsParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: CopyOverrideRows :copyfrom` and return the number of affected rows. + + Arguments: + params -- collections.abc.Sequence[CopyOverrideRowsParams]. A list of params for rows that should be inserted. + + Returns: + int -- The number of affected rows. + """ + records = [(param.id_, decimal.Decimal(param.amount)) for param in params] + r = await self._conn.copy_records_to_table("test_copy_override", columns=["id", "amount"], records=records) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + async def count_copy_override_rows(self) -> int | None: + """Fetch one from the db using the SQL query with `name: CountCopyOverrideRows :one`. + + ```sql + SELECT count(*) FROM test_copy_override + ``` + + Returns: + int -- Result fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(COUNT_COPY_OVERRIDE_ROWS) + if row is None: + return None + return row[0] + + async def delete_copy_override_rows(self) -> None: + """Execute SQL query with `name: DeleteCopyOverrideRows :exec`. + + ```sql + DELETE FROM test_copy_override + ``` + + """ + await self._conn.execute(DELETE_COPY_OVERRIDE_ROWS) diff --git a/test/driver_asyncpg/msgspec/classes/queries_enum_override.py b/test/driver_asyncpg/msgspec/classes/queries_enum_override.py new file mode 100644 index 00000000..e27bb2d7 --- /dev/null +++ b/test/driver_asyncpg/msgspec/classes/queries_enum_override.py @@ -0,0 +1,206 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_enum_override.sql +"""Module containing queries from file queries_enum_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "QueriesEnumOverride", + "QueryResults", +) + +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import asyncpg.cursor + import collections.abc + + type QueryResultsArgsType = int | float | str | memoryview | collections.abc.Sequence[QueryResultsArgsType] | None + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + +from test.driver_asyncpg.msgspec.classes import enums +from test.driver_asyncpg.msgspec.classes import models + + +INSERT_ENUM_OVERRIDE: typing.Final[str] = """-- name: InsertEnumOverride :exec +INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) +""" + +GET_ENUM_OVERRIDE_MOOD: typing.Final[str] = """-- name: GetEnumOverrideMood :one +SELECT mood_test FROM test_enum_override WHERE id = $1 +""" + +LIST_ENUM_OVERRIDE_BY_IDS: typing.Final[str] = """-- name: ListEnumOverrideByIds :many +SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) +""" + +COUNT_ENUM_OVERRIDE_BY_MOODS: typing.Final[str] = """-- name: CountEnumOverrideByMoods :one +SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: ConnectionLike, + sql: str, + decode_hook: collections.abc.Callable[[asyncpg.Record], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Arguments: + conn -- The connection object of type `ConnectionLike` used to execute queries. + sql -- The SQL statement that will be executed when fetching/iterating. + decode_hook -- A callback that turns an `asyncpg.Record` object into `T` that will be returned. + *args -- Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: asyncpg.cursor.CursorFactory[asyncpg.Record] | None = None + self._iterator: asyncpg.cursor.CursorIterator[asyncpg.Record] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns: + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await self._conn.fetch(self._sql, *self._args) + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an asyncpg cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopAsyncIteration -- When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor = self._conn.cursor(self._sql, *self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +class QueriesEnumOverride: + """Queries from file queries_enum_override.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: ConnectionLike) -> None: + """Initialize the instance using the connection. + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute queries. + """ + self._conn = conn + + @property + def conn(self) -> ConnectionLike: + """Connection object used to make queries. + + Returns: + ConnectionLike -- Connection object used to make queries. + """ + return self._conn + + async def insert_enum_override(self, *, id_: int, mood_test: str) -> None: + """Execute SQL query with `name: InsertEnumOverride :exec`. + + ```sql + INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) + ``` + + Arguments: + id_ -- int. + mood_test -- str. + """ + await self._conn.execute(INSERT_ENUM_OVERRIDE, id_, enums.TestMood(mood_test)) + + async def get_enum_override_mood(self, *, id_: int) -> str | None: + """Fetch one from the db using the SQL query with `name: GetEnumOverrideMood :one`. + + ```sql + SELECT mood_test FROM test_enum_override WHERE id = $1 + ``` + + Arguments: + id_ -- int. + + Returns: + str -- Result fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ENUM_OVERRIDE_MOOD, id_) + if row is None: + return None + return str(row[0]) + + def list_enum_override_by_ids(self, *, dollar_1: collections.abc.Sequence[int]) -> QueryResults[models.TestEnumOverride]: + """Fetch many from the db using the SQL query with `name: ListEnumOverrideByIds :many`. + + ```sql + SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) + ``` + + Arguments: + dollar_1 -- collections.abc.Sequence[int]. + + Returns: + QueryResults[models.TestEnumOverride] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestEnumOverride: + return models.TestEnumOverride(id_=row[0], mood_test=str(row[1])) + + return QueryResults(self._conn, LIST_ENUM_OVERRIDE_BY_IDS, _decode_hook, dollar_1) + + async def count_enum_override_by_moods(self, *, dollar_1: collections.abc.Sequence[enums.TestMood]) -> int | None: + """Fetch one from the db using the SQL query with `name: CountEnumOverrideByMoods :one`. + + ```sql + SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) + ``` + + Arguments: + dollar_1 -- collections.abc.Sequence[enums.TestMood]. + + Returns: + int -- Result fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(COUNT_ENUM_OVERRIDE_BY_MOODS, dollar_1) + if row is None: + return None + return row[0] diff --git a/test/driver_asyncpg/msgspec/functions/__init__.py b/test/driver_asyncpg/msgspec/functions/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_asyncpg/msgspec/functions/__init__.py +++ b/test/driver_asyncpg/msgspec/functions/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_asyncpg/msgspec/functions/enums.py b/test/driver_asyncpg/msgspec/functions/enums.py new file mode 100644 index 00000000..d49ac611 --- /dev/null +++ b/test/driver_asyncpg/msgspec/functions/enums.py @@ -0,0 +1,23 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing enums.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("TestMood",) + +import enum +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +class TestMood(enum.StrEnum): + """Enum representing TestMood.""" + + SAD = "sad" + OK = "ok" + HAPPY = "happy" diff --git a/test/driver_asyncpg/msgspec/functions/models.py b/test/driver_asyncpg/msgspec/functions/models.py index ec0755b3..98b55cd5 100644 --- a/test/driver_asyncpg/msgspec/functions/models.py +++ b/test/driver_asyncpg/msgspec/functions/models.py @@ -1,11 +1,14 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( + "TestEnumOverride", + "TestEnumType", "TestInnerPostgresType", "TestPostgresType", "TestTypeOverride", @@ -16,12 +19,39 @@ if typing.TYPE_CHECKING: from collections import UserString + from test.driver_asyncpg.msgspec.functions import enums import collections.abc import datetime import decimal import uuid +class TestEnumOverride(msgspec.Struct): + """Model representing TestEnumOverride. + + Attributes: + id_ -- int + mood_test -- str + """ + + id_: int + mood_test: str + + +class TestEnumType(msgspec.Struct): + """Model representing TestEnumType. + + Attributes: + id_ -- int + mood -- enums.TestMood + maybe_mood -- enums.TestMood | None + """ + + id_: int + mood: enums.TestMood + maybe_mood: enums.TestMood | None + + class TestInnerPostgresType(msgspec.Struct): """Model representing TestInnerPostgresType. @@ -106,7 +136,7 @@ class TestPostgresType(msgspec.Struct): """Model representing TestPostgresType. Attributes: - id -- int + id_ -- int serial_test -- int serial4_test -- int bigserial_test -- int @@ -144,7 +174,7 @@ class TestPostgresType(msgspec.Struct): ltxtquery_test -- str """ - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -186,9 +216,9 @@ class TestTypeOverride(msgspec.Struct): """Model representing TestTypeOverride. Attributes: - id -- int + id_ -- int text_test -- UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_asyncpg/msgspec/functions/queries.py b/test/driver_asyncpg/msgspec/functions/queries.py index 57d85bde..88e0a525 100644 --- a/test/driver_asyncpg/msgspec/functions/queries.py +++ b/test/driver_asyncpg/msgspec/functions/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -17,12 +19,14 @@ "create_rows_table", "delete_one_result_test_postgres_type", "delete_one_rows_test_postgres_type", + "delete_one_test_enum_type", "delete_one_test_postgres_inner_type", "delete_one_test_postgres_type", "delete_type_override", "get_all_embedded_test_postgres_type", "get_embedded_test_postgres_type", "get_many_test_bytea_postgres_type", + "get_many_test_enum_types", "get_many_test_iterator_postgres_type", "get_many_test_postgres_type", "get_many_test_timestamp_postgres_type", @@ -30,10 +34,13 @@ "get_many_type_override", "get_one_inner_test_postgres_type", "get_one_test_bytea_postgres_type", + "get_one_test_enum_type", + "get_one_test_enum_value", "get_one_test_postgres_type", "get_one_test_timestamp_postgres_type", "get_one_text_type_override", "get_one_type_override", + "insert_one_test_enum_type", "insert_type_override", "test_copy_from", "update_result_test_postgres_type", @@ -41,7 +48,6 @@ ) from collections import UserString -import datetime import msgspec import operator import typing @@ -50,33 +56,23 @@ import asyncpg import asyncpg.cursor import collections.abc + import datetime import decimal import uuid - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None - ConnectionLike: typing.TypeAlias = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] +from test.driver_asyncpg.msgspec.functions import enums from test.driver_asyncpg.msgspec.functions import models -class GetAllEmbeddedTestPostgresTypeRow(msgspec.Struct): - """Model representing GetAllEmbeddedTestPostgresTypeRow. - - Attributes: - test_postgres_type -- models.TestPostgresType - test_inner_postgres_type -- models.TestInnerPostgresType - """ - - test_postgres_type: models.TestPostgresType - test_inner_postgres_type: models.TestInnerPostgresType - - class GetEmbeddedTestPostgresTypeRow(msgspec.Struct): """Model representing GetEmbeddedTestPostgresTypeRow. Attributes: - id -- int + id_ -- int serial_test -- int serial4_test -- int bigserial_test -- int @@ -115,7 +111,7 @@ class GetEmbeddedTestPostgresTypeRow(msgspec.Struct): test_inner_postgres_type -- models.TestInnerPostgresType """ - id: int + id_: int serial_test: int serial4_test: int bigserial_test: int @@ -154,62 +150,92 @@ class GetEmbeddedTestPostgresTypeRow(msgspec.Struct): test_inner_postgres_type: models.TestInnerPostgresType +class GetAllEmbeddedTestPostgresTypeRow(msgspec.Struct): + """Model representing GetAllEmbeddedTestPostgresTypeRow. + + Attributes: + test_postgres_type -- models.TestPostgresType + test_inner_postgres_type -- models.TestInnerPostgresType + """ + + test_postgres_type: models.TestPostgresType + test_inner_postgres_type: models.TestInnerPostgresType + + class TestCopyFromParams(msgspec.Struct): """Model representing TestCopyFromParams. Attributes: - id -- int + id_ -- int float_test -- float int_test -- int """ - id: int + id_: int float_test: float int_test: int -CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec -INSERT INTO test_inner_postgres_types (table_id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) -VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) +GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one +SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_inner_postgres_types +WHERE table_id = $1 LIMIT 1 +""" + +GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 +""" + +GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 """ CREATE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresType :exec @@ -256,6 +282,62 @@ class TestCopyFromParams(msgspec.Struct): $33, $34, $35, $36) """ +CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec +INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec +DELETE +FROM test_inner_postgres_types +WHERE test_inner_postgres_types.table_id = $1 +""" + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateResultOneTestPostgresType :execresult INSERT INTO test_postgres_types (id, serial_test, @@ -300,6 +382,18 @@ class TestCopyFromParams(msgspec.Struct): $33, $34, $35, $36) """ +UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateRowsOneTestPostgresType :execrows INSERT INTO test_postgres_types (id, serial_test, @@ -344,6 +438,18 @@ class TestCopyFromParams(msgspec.Struct): $33, $34, $35, $36) """ +UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows CREATE TABLE test_create_rows_table ( @@ -352,28 +458,32 @@ class TestCopyFromParams(msgspec.Struct): ) """ -DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom +INSERT INTO test_copy_from (id, + float_test, int_test) +VALUES ($1, $2, $3) """ -DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec +INSERT INTO test_type_override ( + id, text_test +) VALUES ($1 ,$2) """ -DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec -DELETE -FROM test_inner_postgres_types -WHERE test_inner_postgres_types.table_id = $1 +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = $1 """ -DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec -DELETE -FROM test_postgres_types -WHERE test_postgres_types.id = $1 +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 """ DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec @@ -382,113 +492,37 @@ class TestCopyFromParams(msgspec.Struct): WHERE test_type_override.id = $1 """ -GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one -SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id -WHERE test_postgres_types.id = $1 +INSERT_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: InsertOneTestEnumType :exec +INSERT INTO test_enum_types (id, mood, maybe_mood) +VALUES ($1, $2, $3) """ -GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one -SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id -WHERE test_postgres_types.id = $1 +GET_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: GetOneTestEnumType :one +SELECT id, mood, maybe_mood +FROM test_enum_types +WHERE id = $1 """ -GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many -SELECT bytea_test -FROM test_postgres_types -WHERE id = $1 LIMIT 2 -""" - -GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types -WHERE id = $1 -""" - -GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types +GET_ONE_TEST_ENUM_VALUE: typing.Final[str] = """-- name: GetOneTestEnumValue :one +SELECT mood +FROM test_enum_types WHERE id = $1 """ -GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many -SELECT timestamp_test -FROM test_postgres_types -WHERE id = $1 LIMIT 2 -""" - -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 -""" - -GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one -SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_inner_postgres_types -WHERE table_id = $1 LIMIT 1 -""" - -GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one -SELECT bytea_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one -SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one -SELECT timestamp_test -FROM test_postgres_types -WHERE id = $1 LIMIT 1 -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 +GET_MANY_TEST_ENUM_TYPES: typing.Final[str] = """-- name: GetManyTestEnumTypes :many +SELECT id, mood, maybe_mood +FROM test_enum_types +ORDER BY id """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = $1 -""" - -INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec -INSERT INTO test_type_override ( - id, text_test -) VALUES ($1 ,$2) -""" - -TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom -INSERT INTO test_copy_from (id, - float_test, int_test) -VALUES ($1, $2, $3) -""" - -UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult -UPDATE test_postgres_types -SET serial_test = 187 -WHERE test_postgres_types.id = $1 -""" - -UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows -UPDATE test_postgres_types -SET serial_test = 187 -WHERE test_postgres_types.id = $1 +DELETE_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: DeleteOneTestEnumType :execrows +DELETE +FROM test_enum_types +WHERE id = $1 """ -T = typing.TypeVar("T") - - -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db.""" __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") @@ -531,9 +565,11 @@ def __await__( Returns: A sequence of decoded objects of type `T`. """ + async def _wrapper() -> collections.abc.Sequence[T]: result = await self._conn.fetch(self._sql, *self._args) return [self._decode_hook(row) for row in result] + return _wrapper().__await__() async def __anext__(self) -> T: @@ -557,186 +593,569 @@ async def __anext__(self) -> T: return self._decode_hook(record) -async def create_one_test_postgres_inner_type(conn: ConnectionLike, *, table_id: int, serial_test: int | None, serial4_test: int | None, bigserial_test: int | None, smallserial_test: int | None, int_test: int | None, bigint_test: int | None, smallint_test: int | None, float_test: float | None, double_precision_test: float | None, real_test: float | None, numeric_test: decimal.Decimal | None, money_test: str | None, bool_test: bool | None, json_test: str | None, jsonb_test: str | None, bytea_test: memoryview | None, date_test: datetime.date | None, time_test: datetime.time | None, timetz_test: datetime.time | None, timestamp_test: datetime.datetime | None, timestamptz_test: datetime.datetime | None, interval_test: datetime.timedelta | None, text_test: str | None, varchar_test: str | None, bpchar_test: str | None, char_test: str | None, citext_test: str | None, uuid_test: uuid.UUID | None, inet_test: str | None, cidr_test: str | None, macaddr_test: str | None, macaddr8_test: str | None, ltree_test: str | None, lquery_test: str | None, ltxtquery_test: str | None) -> None: - """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. +async def get_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> models.TestPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. ```sql - INSERT INTO test_inner_postgres_types (table_id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + id_ -- int. + + Returns: + models.TestPostgresType -- Result fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + +async def get_one_inner_test_postgres_type(conn: ConnectionLike, *, table_id: int) -> models.TestInnerPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + + ```sql + SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_inner_postgres_types + WHERE table_id = $1 LIMIT 1 ``` Arguments: conn -- Connection object of type `ConnectionLike` used to execute the query. table_id -- int. - serial_test -- int | None. - serial4_test -- int | None. - bigserial_test -- int | None. - smallserial_test -- int | None. - int_test -- int | None. - bigint_test -- int | None. - smallint_test -- int | None. - float_test -- float | None. - double_precision_test -- float | None. - real_test -- float | None. - numeric_test -- decimal.Decimal | None. - money_test -- str | None. - bool_test -- bool | None. - json_test -- str | None. - jsonb_test -- str | None. - bytea_test -- memoryview | None. - date_test -- datetime.date | None. - time_test -- datetime.time | None. - timetz_test -- datetime.time | None. - timestamp_test -- datetime.datetime | None. - timestamptz_test -- datetime.datetime | None. - interval_test -- datetime.timedelta | None. - text_test -- str | None. - varchar_test -- str | None. - bpchar_test -- str | None. - char_test -- str | None. - citext_test -- str | None. - uuid_test -- uuid.UUID | None. - inet_test -- str | None. - cidr_test -- str | None. - macaddr_test -- str | None. - macaddr8_test -- str | None. - ltree_test -- str | None. - lquery_test -- str | None. - ltxtquery_test -- str | None. + + Returns: + models.TestInnerPostgresType -- Result fetched from the db. Will be `None` if not found. """ - await conn.execute(CREATE_ONE_TEST_POSTGRES_INNER_TYPE, table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + row = await conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + if row is None: + return None + return models.TestInnerPostgresType( + table_id=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]) if row[16] is not None else None, + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]) if row[29] is not None else None, + cidr_test=str(row[30]) if row[30] is not None else None, + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) -async def create_one_test_postgres_type(conn: ConnectionLike, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> None: - """Execute SQL query with `name: CreateOneTestPostgresType :exec`. +async def get_one_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. ```sql - INSERT INTO test_postgres_types (id, - serial_test, - serial4_test, - bigserial_test, - smallserial_test, - int_test, - bigint_test, - smallint_test, - float_test, - double_precision_test, - real_test, - numeric_test, - money_test, - bool_test, - json_test, - jsonb_test, - bytea_test, - date_test, - time_test, - timetz_test, - timestamp_test, - timestamptz_test, - interval_test, - text_test, - varchar_test, - bpchar_test, - char_test, - citext_test, - uuid_test, - inet_test, - cidr_test, - macaddr_test, - macaddr8_test, - ltree_test, - lquery_test, - ltxtquery_test) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, - $9, $10, $11, $12, $13, $14, $15, $16, - $17, $18, $19, $20, $21, $22, $23, $24, - $25, $26, $27, $28, $29, $30, $31, $32, - $33, $34, $35, $36) + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 ``` Arguments: conn -- Connection object of type `ConnectionLike` used to execute the query. id_ -- int. - serial_test -- int. - serial4_test -- int. - bigserial_test -- int. - smallserial_test -- int. - int_test -- int. - bigint_test -- int. - smallint_test -- int. - float_test -- float. - double_precision_test -- float. - real_test -- float. - numeric_test -- decimal.Decimal. - money_test -- str. - bool_test -- bool. - json_test -- str. - jsonb_test -- str. - bytea_test -- memoryview. - date_test -- datetime.date. - time_test -- datetime.time. - timetz_test -- datetime.time. - timestamp_test -- datetime.datetime. - timestamptz_test -- datetime.datetime. - interval_test -- datetime.timedelta. - text_test -- str. - varchar_test -- str. - bpchar_test -- str. - char_test -- str. - citext_test -- str. - uuid_test -- uuid.UUID. - inet_test -- str. - cidr_test -- str. - macaddr_test -- str. - macaddr8_test -- str. - ltree_test -- str. - lquery_test -- str. - ltxtquery_test -- str. + + Returns: + datetime.datetime -- Result fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) + if row is None: + return None + return row[0] + + +async def get_one_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + id_ -- int. + + Returns: + memoryview -- Result fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) + if row is None: + return None + return memoryview(row[0]) + + +def get_many_test_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + id_ -- int. + + Returns: + QueryResults[models.TestPostgresType] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + + +def get_many_test_iterator_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + id_ -- int. + + Returns: + QueryResults[models.TestPostgresType] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) + + +def get_many_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. + + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + id_ -- int. + + Returns: + QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + + +def get_many_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + id_ -- int. + + Returns: + QueryResults[memoryview] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> memoryview: + return memoryview(row[0]) + + return QueryResults(conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + + +async def get_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + id_ -- int. + + Returns: + GetEmbeddedTestPostgresTypeRow -- Result fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetEmbeddedTestPostgresTypeRow( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + +async def get_all_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + id_ -- int. + + Returns: + GetAllEmbeddedTestPostgresTypeRow -- Result fetched from the db. Will be `None` if not found. """ - await conn.execute(CREATE_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + row = await conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetAllEmbeddedTestPostgresTypeRow( + test_postgres_type=models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ), + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) -async def create_result_one_test_postgres_type(conn: ConnectionLike, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> str: - """Execute and return the result of SQL query with `name: CreateResultOneTestPostgresType :execresult`. +async def create_one_test_postgres_type( + conn: ConnectionLike, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, +) -> None: + """Execute SQL query with `name: CreateOneTestPostgresType :exec`. ```sql INSERT INTO test_postgres_types (id, @@ -820,15 +1239,287 @@ async def create_result_one_test_postgres_type(conn: ConnectionLike, *, id_: int ltree_test -- str. lquery_test -- str. ltxtquery_test -- str. + """ + await conn.execute( + CREATE_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) - Returns: - str -- The result returned when executing the query. + +async def create_one_test_postgres_inner_type( + conn: ConnectionLike, + *, + table_id: int, + serial_test: int | None, + serial4_test: int | None, + bigserial_test: int | None, + smallserial_test: int | None, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + float_test: float | None, + double_precision_test: float | None, + real_test: float | None, + numeric_test: decimal.Decimal | None, + money_test: str | None, + bool_test: bool | None, + json_test: str | None, + jsonb_test: str | None, + bytea_test: memoryview | None, + date_test: datetime.date | None, + time_test: datetime.time | None, + timetz_test: datetime.time | None, + timestamp_test: datetime.datetime | None, + timestamptz_test: datetime.datetime | None, + interval_test: datetime.timedelta | None, + text_test: str | None, + varchar_test: str | None, + bpchar_test: str | None, + char_test: str | None, + citext_test: str | None, + uuid_test: uuid.UUID | None, + inet_test: str | None, + cidr_test: str | None, + macaddr_test: str | None, + macaddr8_test: str | None, + ltree_test: str | None, + lquery_test: str | None, + ltxtquery_test: str | None, +) -> None: + """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. + + ```sql + INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + table_id -- int. + serial_test -- int | None. + serial4_test -- int | None. + bigserial_test -- int | None. + smallserial_test -- int | None. + int_test -- int | None. + bigint_test -- int | None. + smallint_test -- int | None. + float_test -- float | None. + double_precision_test -- float | None. + real_test -- float | None. + numeric_test -- decimal.Decimal | None. + money_test -- str | None. + bool_test -- bool | None. + json_test -- str | None. + jsonb_test -- str | None. + bytea_test -- memoryview | None. + date_test -- datetime.date | None. + time_test -- datetime.time | None. + timetz_test -- datetime.time | None. + timestamp_test -- datetime.datetime | None. + timestamptz_test -- datetime.datetime | None. + interval_test -- datetime.timedelta | None. + text_test -- str | None. + varchar_test -- str | None. + bpchar_test -- str | None. + char_test -- str | None. + citext_test -- str | None. + uuid_test -- uuid.UUID | None. + inet_test -- str | None. + cidr_test -- str | None. + macaddr_test -- str | None. + macaddr8_test -- str | None. + ltree_test -- str | None. + lquery_test -- str | None. + ltxtquery_test -- str | None. """ - return await conn.execute(CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) + await conn.execute( + CREATE_ONE_TEST_POSTGRES_INNER_TYPE, + table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) -async def create_rows_one_test_postgres_type(conn: ConnectionLike, *, id_: int, serial_test: int, serial4_test: int, bigserial_test: int, smallserial_test: int, int_test: int, bigint_test: int, smallint_test: int, float_test: float, double_precision_test: float, real_test: float, numeric_test: decimal.Decimal, money_test: str, bool_test: bool, json_test: str, jsonb_test: str, bytea_test: memoryview, date_test: datetime.date, time_test: datetime.time, timetz_test: datetime.time, timestamp_test: datetime.datetime, timestamptz_test: datetime.datetime, interval_test: datetime.timedelta, text_test: str, varchar_test: str, bpchar_test: str, char_test: str, citext_test: str, uuid_test: uuid.UUID, inet_test: str, cidr_test: str, macaddr_test: str, macaddr8_test: str, ltree_test: str, lquery_test: str, ltxtquery_test: str) -> int: - """Execute SQL query with `name: CreateRowsOneTestPostgresType :execrows` and return the number of affected rows. +async def delete_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + id_ -- int. + """ + await conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) + + +async def delete_one_test_postgres_inner_type(conn: ConnectionLike, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. + + ```sql + DELETE + FROM test_inner_postgres_types + WHERE test_inner_postgres_types.table_id = $1 + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + table_id -- int. + """ + await conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) + + +async def create_result_one_test_postgres_type( + conn: ConnectionLike, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, +) -> str: + """Execute and return the result of SQL query with `name: CreateResultOneTestPostgresType :execresult`. ```sql INSERT INTO test_postgres_types (id, @@ -914,39 +1605,55 @@ async def create_rows_one_test_postgres_type(conn: ConnectionLike, *, id_: int, ltxtquery_test -- str. Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + str -- The result returned when executing the query. """ - r = await conn.execute(CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, id_, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - - -async def create_rows_table(conn: ConnectionLike) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. - - ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL + return await conn.execute( + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, ) - ``` - - Arguments: - conn -- Connection object of type `ConnectionLike` used to execute the query. - - Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - """ - r = await conn.execute(CREATE_ROWS_TABLE) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 -async def delete_one_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: - """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. +async def update_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. ```sql - DELETE - FROM test_postgres_types + UPDATE test_postgres_types + SET serial_test = 187 WHERE test_postgres_types.id = $1 ``` @@ -957,11 +1664,11 @@ async def delete_one_result_test_postgres_type(conn: ConnectionLike, *, id_: int Returns: str -- The result returned when executing the query. """ - return await conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) + return await conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) -async def delete_one_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: - """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. +async def delete_one_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. ```sql DELETE @@ -974,90 +1681,187 @@ async def delete_one_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) id_ -- int. Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - """ - r = await conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - - -async def delete_one_test_postgres_inner_type(conn: ConnectionLike, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. - - ```sql - DELETE - FROM test_inner_postgres_types - WHERE test_inner_postgres_types.table_id = $1 - ``` - - Arguments: - conn -- Connection object of type `ConnectionLike` used to execute the query. - table_id -- int. - """ - await conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) - - -async def delete_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. - - ```sql - DELETE - FROM test_postgres_types - WHERE test_postgres_types.id = $1 - ``` - - Arguments: - conn -- Connection object of type `ConnectionLike` used to execute the query. - id_ -- int. - """ - await conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) - - -async def delete_type_override(conn: ConnectionLike, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. - - ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = $1 - ``` - - Arguments: - conn -- Connection object of type `ConnectionLike` used to execute the query. - id_ -- int. + str -- The result returned when executing the query. """ - await conn.execute(DELETE_TYPE_OVERRIDE, id_) + return await conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) -async def get_all_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: - """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. +async def create_rows_one_test_postgres_type( + conn: ConnectionLike, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, +) -> int: + """Execute SQL query with `name: CreateRowsOneTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test - FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id - WHERE test_postgres_types.id = $1 + INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) ``` Arguments: conn -- Connection object of type `ConnectionLike` used to execute the query. id_ -- int. + serial_test -- int. + serial4_test -- int. + bigserial_test -- int. + smallserial_test -- int. + int_test -- int. + bigint_test -- int. + smallint_test -- int. + float_test -- float. + double_precision_test -- float. + real_test -- float. + numeric_test -- decimal.Decimal. + money_test -- str. + bool_test -- bool. + json_test -- str. + jsonb_test -- str. + bytea_test -- memoryview. + date_test -- datetime.date. + time_test -- datetime.time. + timetz_test -- datetime.time. + timestamp_test -- datetime.datetime. + timestamptz_test -- datetime.datetime. + interval_test -- datetime.timedelta. + text_test -- str. + varchar_test -- str. + bpchar_test -- str. + char_test -- str. + citext_test -- str. + uuid_test -- uuid.UUID. + inet_test -- str. + cidr_test -- str. + macaddr_test -- str. + macaddr8_test -- str. + ltree_test -- str. + lquery_test -- str. + ltxtquery_test -- str. Returns: - GetAllEmbeddedTestPostgresTypeRow -- Result fetched from the db. Will be `None` if not found. + int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - row = await conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return GetAllEmbeddedTestPostgresTypeRow(test_postgres_type=models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]), test_inner_postgres_type=models.TestInnerPostgresType(table_id=row[36], serial_test=row[37], serial4_test=row[38], bigserial_test=row[39], smallserial_test=row[40], int_test=row[41], bigint_test=row[42], smallint_test=row[43], float_test=row[44], double_precision_test=row[45], real_test=row[46], numeric_test=row[47], money_test=row[48], bool_test=row[49], json_test=row[50], jsonb_test=row[51], bytea_test=memoryview(row[52]) if row[52] is not None else None, date_test=row[53], time_test=row[54], timetz_test=row[55], timestamp_test=row[56], timestamptz_test=row[57], interval_test=row[58], text_test=row[59], varchar_test=row[60], bpchar_test=row[61], char_test=row[62], citext_test=row[63], uuid_test=row[64], inet_test=str(row[65]) if row[65] is not None else None, cidr_test=str(row[66]) if row[66] is not None else None, macaddr_test=row[67], macaddr8_test=row[68], ltree_test=row[69], lquery_test=row[70], ltxtquery_test=row[71])) + r = await conn.execute( + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 -async def get_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: - """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. +async def update_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test - FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + UPDATE test_postgres_types + SET serial_test = 187 WHERE test_postgres_types.id = $1 ``` @@ -1066,21 +1870,19 @@ async def get_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> id_ -- int. Returns: - GetEmbeddedTestPostgresTypeRow -- Result fetched from the db. Will be `None` if not found. + int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - row = await conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return GetEmbeddedTestPostgresTypeRow(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35], test_inner_postgres_type=models.TestInnerPostgresType(table_id=row[36], serial_test=row[37], serial4_test=row[38], bigserial_test=row[39], smallserial_test=row[40], int_test=row[41], bigint_test=row[42], smallint_test=row[43], float_test=row[44], double_precision_test=row[45], real_test=row[46], numeric_test=row[47], money_test=row[48], bool_test=row[49], json_test=row[50], jsonb_test=row[51], bytea_test=memoryview(row[52]) if row[52] is not None else None, date_test=row[53], time_test=row[54], timetz_test=row[55], timestamp_test=row[56], timestamptz_test=row[57], interval_test=row[58], text_test=row[59], varchar_test=row[60], bpchar_test=row[61], char_test=row[62], citext_test=row[63], uuid_test=row[64], inet_test=str(row[65]) if row[65] is not None else None, cidr_test=str(row[66]) if row[66] is not None else None, macaddr_test=row[67], macaddr8_test=row[68], ltree_test=row[69], lquery_test=row[70], ltxtquery_test=row[71])) + r = await conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 -def get_many_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. +async def delete_one_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. ```sql - SELECT bytea_test + DELETE FROM test_postgres_types - WHERE id = $1 LIMIT 2 + WHERE test_postgres_types.id = $1 ``` Arguments: @@ -1088,79 +1890,70 @@ def get_many_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> Quer id_ -- int. Returns: - QueryResults[memoryview] -- Helper class that allows both iteration and normal fetching of data from the db. + int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - def _decode_hook(row: asyncpg.Record) -> memoryview: - return memoryview(row[0]) - return QueryResults[memoryview](conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + r = await conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 -def get_many_test_iterator_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: - """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. +async def create_rows_table(conn: ConnectionLike) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) ``` Arguments: conn -- Connection object of type `ConnectionLike` used to execute the query. - id_ -- int. Returns: - QueryResults[models.TestPostgresType] -- Helper class that allows both iteration and normal fetching of data from the db. + int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) - return QueryResults[models.TestPostgresType](conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) - + r = await conn.execute(CREATE_ROWS_TABLE) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 -def get_many_test_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: - """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. - ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 - ``` +async def test_copy_from(conn: ConnectionLike, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. Arguments: conn -- Connection object of type `ConnectionLike` used to execute the query. - id_ -- int. + params -- collections.abc.Sequence[TestCopyFromParams]. A list of params for rows that should be inserted. Returns: - QueryResults[models.TestPostgresType] -- Helper class that allows both iteration and normal fetching of data from the db. + int -- The number of affected rows. """ - def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) - return QueryResults[models.TestPostgresType](conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + records = [(param.id_, param.float_test, param.int_test) for param in params] + r = await conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 -def get_many_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. +async def insert_type_override(conn: ConnectionLike, *, id_: int, text_test: UserString | None) -> None: + """Execute SQL query with `name: InsertTypeOverride :exec`. ```sql - SELECT timestamp_test - FROM test_postgres_types - WHERE id = $1 LIMIT 2 + INSERT INTO test_type_override ( + id, text_test + ) VALUES ($1 ,$2) ``` Arguments: conn -- Connection object of type `ConnectionLike` used to execute the query. id_ -- int. - - Returns: - QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. + text_test -- UserString | None. """ - return QueryResults[datetime.datetime](conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + await conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test) if text_test is not None else None) -def get_many_text_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. +async def get_one_type_override(conn: ConnectionLike, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + SELECT id, text_test FROM test_type_override WHERE id = $1 ``` Arguments: @@ -1168,9 +1961,12 @@ def get_many_text_type_override(conn: ConnectionLike, *, id_: int) -> QueryResul id_ -- int. Returns: - QueryResults[UserString] -- Helper class that allows both iteration and normal fetching of data from the db. + models.TestTypeOverride -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[UserString](conn, GET_MANY_TEXT_TYPE_OVERRIDE, operator.itemgetter(0), id_) + row = await conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) def get_many_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestTypeOverride]: @@ -1187,40 +1983,38 @@ def get_many_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[mo Returns: QueryResults[models.TestTypeOverride] -- Helper class that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: asyncpg.Record) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - return QueryResults[models.TestTypeOverride](conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + return QueryResults(conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) -async def get_one_inner_test_postgres_type(conn: ConnectionLike, *, table_id: int) -> models.TestInnerPostgresType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + +async def get_one_text_type_override(conn: ConnectionLike, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_inner_postgres_types - WHERE table_id = $1 LIMIT 1 + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 ``` Arguments: conn -- Connection object of type `ConnectionLike` used to execute the query. - table_id -- int. + id_ -- int. Returns: - models.TestInnerPostgresType -- Result fetched from the db. Will be `None` if not found. + UserString -- Result fetched from the db. Will be `None` if not found. """ - row = await conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + row = await conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) if row is None: return None - return models.TestInnerPostgresType(table_id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]) if row[16] is not None else None, date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]) if row[29] is not None else None, cidr_test=str(row[30]) if row[30] is not None else None, macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) + return UserString(row[0]) if row[0] is not None else None -async def get_one_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. +def get_many_text_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. ```sql - SELECT bytea_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 ``` Arguments: @@ -1228,63 +2022,55 @@ async def get_one_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> id_ -- int. Returns: - memoryview -- Result fetched from the db. Will be `None` if not found. + QueryResults[UserString | None] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = await conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) - if row is None: - return None - return memoryview(row[0]) + def _decode_hook(row: asyncpg.Record) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None -async def get_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> models.TestPostgresType | None: - """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. + return QueryResults(conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + +async def delete_type_override(conn: ConnectionLike, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. ```sql - SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + DELETE + FROM test_type_override + WHERE test_type_override.id = $1 ``` Arguments: conn -- Connection object of type `ConnectionLike` used to execute the query. id_ -- int. - - Returns: - models.TestPostgresType -- Result fetched from the db. Will be `None` if not found. """ - row = await conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) - if row is None: - return None - return models.TestPostgresType(id=row[0], serial_test=row[1], serial4_test=row[2], bigserial_test=row[3], smallserial_test=row[4], int_test=row[5], bigint_test=row[6], smallint_test=row[7], float_test=row[8], double_precision_test=row[9], real_test=row[10], numeric_test=row[11], money_test=row[12], bool_test=row[13], json_test=row[14], jsonb_test=row[15], bytea_test=memoryview(row[16]), date_test=row[17], time_test=row[18], timetz_test=row[19], timestamp_test=row[20], timestamptz_test=row[21], interval_test=row[22], text_test=row[23], varchar_test=row[24], bpchar_test=row[25], char_test=row[26], citext_test=row[27], uuid_test=row[28], inet_test=str(row[29]), cidr_test=str(row[30]), macaddr_test=row[31], macaddr8_test=row[32], ltree_test=row[33], lquery_test=row[34], ltxtquery_test=row[35]) + await conn.execute(DELETE_TYPE_OVERRIDE, id_) -async def get_one_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. +async def insert_one_test_enum_type(conn: ConnectionLike, *, id_: int, mood: enums.TestMood, maybe_mood: enums.TestMood | None) -> None: + """Execute SQL query with `name: InsertOneTestEnumType :exec`. ```sql - SELECT timestamp_test - FROM test_postgres_types - WHERE id = $1 LIMIT 1 + INSERT INTO test_enum_types (id, mood, maybe_mood) + VALUES ($1, $2, $3) ``` Arguments: conn -- Connection object of type `ConnectionLike` used to execute the query. id_ -- int. - - Returns: - datetime.datetime -- Result fetched from the db. Will be `None` if not found. + mood -- enums.TestMood. + maybe_mood -- enums.TestMood | None. """ - row = await conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) - if row is None: - return None - return row[0] + await conn.execute(INSERT_ONE_TEST_ENUM_TYPE, id_, mood, maybe_mood) -async def get_one_text_type_override(conn: ConnectionLike, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. +async def get_one_test_enum_type(conn: ConnectionLike, *, id_: int) -> models.TestEnumType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumType :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + SELECT id, mood, maybe_mood + FROM test_enum_types + WHERE id = $1 ``` Arguments: @@ -1292,19 +2078,21 @@ async def get_one_text_type_override(conn: ConnectionLike, *, id_: int) -> UserS id_ -- int. Returns: - UserString -- Result fetched from the db. Will be `None` if not found. + models.TestEnumType -- Result fetched from the db. Will be `None` if not found. """ - row = await conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) + row = await conn.fetchrow(GET_ONE_TEST_ENUM_TYPE, id_) if row is None: return None - return row[0] + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) -async def get_one_type_override(conn: ConnectionLike, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. +async def get_one_test_enum_value(conn: ConnectionLike, *, id_: int) -> enums.TestMood | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumValue :one`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = $1 + SELECT mood + FROM test_enum_types + WHERE id = $1 ``` Arguments: @@ -1312,75 +2100,43 @@ async def get_one_type_override(conn: ConnectionLike, *, id_: int) -> models.Tes id_ -- int. Returns: - models.TestTypeOverride -- Result fetched from the db. Will be `None` if not found. + enums.TestMood -- Result fetched from the db. Will be `None` if not found. """ - row = await conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + row = await conn.fetchrow(GET_ONE_TEST_ENUM_VALUE, id_) if row is None: return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + return enums.TestMood(row[0]) -async def insert_type_override(conn: ConnectionLike, *, id_: int, text_test: UserString | None) -> None: - """Execute SQL query with `name: InsertTypeOverride :exec`. +def get_many_test_enum_types(conn: ConnectionLike) -> QueryResults[models.TestEnumType]: + """Fetch many from the db using the SQL query with `name: GetManyTestEnumTypes :many`. ```sql - INSERT INTO test_type_override ( - id, text_test - ) VALUES ($1 ,$2) + SELECT id, mood, maybe_mood + FROM test_enum_types + ORDER BY id ``` Arguments: conn -- Connection object of type `ConnectionLike` used to execute the query. - id_ -- int. - text_test -- UserString | None. - """ - await conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test)) - - -async def test_copy_from(conn: ConnectionLike, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: - """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. - - Arguments: - conn -- Connection object of type `ConnectionLike` used to execute the query. - params -- collections.abc.Sequence[TestCopyFromParams]. A list of params for rows that should be inserted. Returns: - int -- The number of affected rows. + QueryResults[models.TestEnumType] -- Helper class that allows both iteration and normal fetching of data from the db. """ - records = [ - (param.id, param.float_test, param.int_test) - for param in params - ] - r = await conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) - return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 - - -async def update_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: - """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. - - ```sql - UPDATE test_postgres_types - SET serial_test = 187 - WHERE test_postgres_types.id = $1 - ``` - Arguments: - conn -- Connection object of type `ConnectionLike` used to execute the query. - id_ -- int. + def _decode_hook(row: asyncpg.Record) -> models.TestEnumType: + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) - Returns: - str -- The result returned when executing the query. - """ - return await conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) + return QueryResults(conn, GET_MANY_TEST_ENUM_TYPES, _decode_hook) -async def update_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. +async def delete_one_test_enum_type(conn: ConnectionLike, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneTestEnumType :execrows` and return the number of affected rows. ```sql - UPDATE test_postgres_types - SET serial_test = 187 - WHERE test_postgres_types.id = $1 + DELETE + FROM test_enum_types + WHERE id = $1 ``` Arguments: @@ -1388,7 +2144,7 @@ async def update_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> i id_ -- int. Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. """ - r = await conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + r = await conn.execute(DELETE_ONE_TEST_ENUM_TYPE, id_) return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 diff --git a/test/driver_asyncpg/msgspec/functions/queries_copy_override.py b/test/driver_asyncpg/msgspec/functions/queries_copy_override.py new file mode 100644 index 00000000..aa993032 --- /dev/null +++ b/test/driver_asyncpg/msgspec/functions/queries_copy_override.py @@ -0,0 +1,97 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_copy_override.sql +"""Module containing queries from file queries_copy_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "CopyOverrideRowsParams", + "copy_override_rows", + "count_copy_override_rows", + "delete_copy_override_rows", +) + +import decimal +import msgspec +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import collections.abc + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + + +class CopyOverrideRowsParams(msgspec.Struct): + """Model representing CopyOverrideRowsParams. + + Attributes: + id_ -- int + amount -- float + """ + + id_: int + amount: float + + +COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CopyOverrideRows :copyfrom +INSERT INTO test_copy_override (id, amount) VALUES ($1, $2) +""" + +COUNT_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CountCopyOverrideRows :one +SELECT count(*) FROM test_copy_override +""" + +DELETE_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: DeleteCopyOverrideRows :exec +DELETE FROM test_copy_override +""" + + +async def copy_override_rows(conn: ConnectionLike, *, params: collections.abc.Sequence[CopyOverrideRowsParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: CopyOverrideRows :copyfrom` and return the number of affected rows. + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + params -- collections.abc.Sequence[CopyOverrideRowsParams]. A list of params for rows that should be inserted. + + Returns: + int -- The number of affected rows. + """ + records = [(param.id_, decimal.Decimal(param.amount)) for param in params] + r = await conn.copy_records_to_table("test_copy_override", columns=["id", "amount"], records=records) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + +async def count_copy_override_rows(conn: ConnectionLike) -> int | None: + """Fetch one from the db using the SQL query with `name: CountCopyOverrideRows :one`. + + ```sql + SELECT count(*) FROM test_copy_override + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + + Returns: + int -- Result fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(COUNT_COPY_OVERRIDE_ROWS) + if row is None: + return None + return row[0] + + +async def delete_copy_override_rows(conn: ConnectionLike) -> None: + """Execute SQL query with `name: DeleteCopyOverrideRows :exec`. + + ```sql + DELETE FROM test_copy_override + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + """ + await conn.execute(DELETE_COPY_OVERRIDE_ROWS) diff --git a/test/driver_asyncpg/msgspec/functions/queries_enum_override.py b/test/driver_asyncpg/msgspec/functions/queries_enum_override.py new file mode 100644 index 00000000..dd89ff8b --- /dev/null +++ b/test/driver_asyncpg/msgspec/functions/queries_enum_override.py @@ -0,0 +1,194 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_enum_override.sql +"""Module containing queries from file queries_enum_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "QueryResults", + "count_enum_override_by_moods", + "get_enum_override_mood", + "insert_enum_override", + "list_enum_override_by_ids", +) + +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import asyncpg.cursor + import collections.abc + + type QueryResultsArgsType = int | float | str | memoryview | collections.abc.Sequence[QueryResultsArgsType] | None + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + +from test.driver_asyncpg.msgspec.functions import enums +from test.driver_asyncpg.msgspec.functions import models + + +INSERT_ENUM_OVERRIDE: typing.Final[str] = """-- name: InsertEnumOverride :exec +INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) +""" + +GET_ENUM_OVERRIDE_MOOD: typing.Final[str] = """-- name: GetEnumOverrideMood :one +SELECT mood_test FROM test_enum_override WHERE id = $1 +""" + +LIST_ENUM_OVERRIDE_BY_IDS: typing.Final[str] = """-- name: ListEnumOverrideByIds :many +SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) +""" + +COUNT_ENUM_OVERRIDE_BY_MOODS: typing.Final[str] = """-- name: CountEnumOverrideByMoods :one +SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: ConnectionLike, + sql: str, + decode_hook: collections.abc.Callable[[asyncpg.Record], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Arguments: + conn -- The connection object of type `ConnectionLike` used to execute queries. + sql -- The SQL statement that will be executed when fetching/iterating. + decode_hook -- A callback that turns an `asyncpg.Record` object into `T` that will be returned. + *args -- Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: asyncpg.cursor.CursorFactory[asyncpg.Record] | None = None + self._iterator: asyncpg.cursor.CursorIterator[asyncpg.Record] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns: + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await self._conn.fetch(self._sql, *self._args) + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an asyncpg cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopAsyncIteration -- When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor = self._conn.cursor(self._sql, *self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +async def insert_enum_override(conn: ConnectionLike, *, id_: int, mood_test: str) -> None: + """Execute SQL query with `name: InsertEnumOverride :exec`. + + ```sql + INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + id_ -- int. + mood_test -- str. + """ + await conn.execute(INSERT_ENUM_OVERRIDE, id_, enums.TestMood(mood_test)) + + +async def get_enum_override_mood(conn: ConnectionLike, *, id_: int) -> str | None: + """Fetch one from the db using the SQL query with `name: GetEnumOverrideMood :one`. + + ```sql + SELECT mood_test FROM test_enum_override WHERE id = $1 + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + id_ -- int. + + Returns: + str -- Result fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ENUM_OVERRIDE_MOOD, id_) + if row is None: + return None + return str(row[0]) + + +def list_enum_override_by_ids(conn: ConnectionLike, *, dollar_1: collections.abc.Sequence[int]) -> QueryResults[models.TestEnumOverride]: + """Fetch many from the db using the SQL query with `name: ListEnumOverrideByIds :many`. + + ```sql + SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + dollar_1 -- collections.abc.Sequence[int]. + + Returns: + QueryResults[models.TestEnumOverride] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestEnumOverride: + return models.TestEnumOverride(id_=row[0], mood_test=str(row[1])) + + return QueryResults(conn, LIST_ENUM_OVERRIDE_BY_IDS, _decode_hook, dollar_1) + + +async def count_enum_override_by_moods(conn: ConnectionLike, *, dollar_1: collections.abc.Sequence[enums.TestMood]) -> int | None: + """Fetch one from the db using the SQL query with `name: CountEnumOverrideByMoods :one`. + + ```sql + SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) + ``` + + Arguments: + conn -- Connection object of type `ConnectionLike` used to execute the query. + dollar_1 -- collections.abc.Sequence[enums.TestMood]. + + Returns: + int -- Result fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(COUNT_ENUM_OVERRIDE_BY_MOODS, dollar_1) + if row is None: + return None + return row[0] diff --git a/test/driver_asyncpg/msgspec/test_msgspec_classes.py b/test/driver_asyncpg/msgspec/test_msgspec_classes.py index db90a49a..0a2fe830 100644 --- a/test/driver_asyncpg/msgspec/test_msgspec_classes.py +++ b/test/driver_asyncpg/msgspec/test_msgspec_classes.py @@ -43,12 +43,12 @@ class TestMsgspecClasses: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestPostgresType: return models.TestPostgresType( - id=random.randint(1, 1000000), + id_=random.randint(1, 1000000), serial_test=1, serial4_test=2, bigserial_test=3, @@ -67,9 +67,9 @@ def model(self) -> models.TestPostgresType: bytea_test=memoryview(b"\x00\x01\x02hello"), date_test=datetime.date(2025, 1, 1), time_test=datetime.time(14, 30, 0), - timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.timezone.utc), + timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.UTC), timestamp_test=datetime.datetime(2025, 1, 1, 14, 30, 0), - timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.timezone.utc), + timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.UTC), interval_test=datetime.timedelta(days=1, hours=2, minutes=30), text_test="Lorem ipsum", varchar_test="Example varchar", @@ -89,7 +89,7 @@ def model(self) -> models.TestPostgresType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestPostgresType) -> models.TestInnerPostgresType: return models.TestInnerPostgresType( - table_id=model.id, + table_id=model.id_, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -135,7 +135,7 @@ async def queries_obj(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> @pytest.mark.dependency(name="TestMsgspecClasses::create") async def test_create(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: await queries_obj.create_one_test_postgres_type( - id_=model.id, + id_=model.id_, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -218,7 +218,7 @@ async def test_create_inner(self, queries_obj: queries.Queries, inner_model: mod @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestMsgspecClasses::create_inner"], name="TestMsgspecClasses::get_one") async def test_get_one(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_one_test_postgres_type(id_=model.id) + result = await queries_obj.get_one_test_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, models.TestPostgresType) @@ -242,9 +242,7 @@ async def test_get_one_inner(self, queries_obj: queries.Queries, inner_model: mo assert result == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestMsgspecClasses::get_one_inner"], name="TestMsgspecClasses::get_one_inner_none" - ) + @pytest.mark.dependency(depends=["TestMsgspecClasses::get_one_inner"], name="TestMsgspecClasses::get_one_inner_none") async def test_get_one_inner_none(self, queries_obj: queries.Queries) -> None: result = await queries_obj.get_one_inner_test_postgres_type(table_id=0) @@ -256,16 +254,14 @@ async def test_get_one_inner_none(self, queries_obj: queries.Queries) -> None: name="TestMsgspecClasses::get_one_timestamp", ) async def test_get_one_timestamp(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_one_test_timestamp_postgres_type(id_=model.id) + result = await queries_obj.get_one_test_timestamp_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestMsgspecClasses::get_one_timestamp"], name="TestMsgspecClasses::get_one_timestamp_none" - ) + @pytest.mark.dependency(depends=["TestMsgspecClasses::get_one_timestamp"], name="TestMsgspecClasses::get_one_timestamp_none") async def test_get_one_timestamp_none(self, queries_obj: queries.Queries) -> None: result = await queries_obj.get_one_test_timestamp_postgres_type(id_=0) @@ -277,16 +273,14 @@ async def test_get_one_timestamp_none(self, queries_obj: queries.Queries) -> Non name="TestMsgspecClasses::get_one_bytea", ) async def test_get_one_bytea(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_one_test_bytea_postgres_type(id_=model.id) + result = await queries_obj.get_one_test_bytea_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, memoryview) assert result == model.bytea_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestMsgspecClasses::get_one_bytea"], name="TestMsgspecClasses::get_one_bytea_none" - ) + @pytest.mark.dependency(depends=["TestMsgspecClasses::get_one_bytea"], name="TestMsgspecClasses::get_one_bytea_none") async def test_get_one_bytea_none(self, queries_obj: queries.Queries) -> None: result = await queries_obj.get_one_test_bytea_postgres_type(id_=0) @@ -295,7 +289,7 @@ async def test_get_one_bytea_none(self, queries_obj: queries.Queries) -> None: @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestMsgspecClasses::get_one_bytea_none"], name="TestMsgspecClasses::get_many") async def test_get_many(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_many_test_postgres_type(id_=model.id) + result = await queries_obj.get_many_test_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -307,7 +301,7 @@ async def test_get_many(self, queries_obj: queries.Queries, model: models.TestPo @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestMsgspecClasses::get_many"], name="TestMsgspecClasses::get_many_timestamp") async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_many_test_timestamp_postgres_type(id_=model.id) + result = await queries_obj.get_many_test_timestamp_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -321,7 +315,7 @@ async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: mod name="TestMsgspecClasses::get_many_bytea", ) async def test_get_many_bytea(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: - result = await queries_obj.get_many_test_bytea_postgres_type(id_=model.id) + result = await queries_obj.get_many_test_bytea_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -337,13 +331,13 @@ async def test_get_embedded( model: models.TestPostgresType, inner_model: models.TestInnerPostgresType, ) -> None: - result = await queries_obj.get_embedded_test_postgres_type(id_=model.id) + result = await queries_obj.get_embedded_test_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, queries.GetEmbeddedTestPostgresTypeRow) assert isinstance(result.test_inner_postgres_type, models.TestInnerPostgresType) - assert result.id == model.id + assert result.id_ == model.id_ assert result.serial_test == model.serial_test assert result.serial4_test == model.serial4_test assert result.bigserial_test == model.bigserial_test @@ -403,7 +397,7 @@ async def test_get_all_embedded( model: models.TestPostgresType, inner_model: models.TestInnerPostgresType, ) -> None: - result = await queries_obj.get_all_embedded_test_postgres_type(id_=model.id) + result = await queries_obj.get_all_embedded_test_postgres_type(id_=model.id_) assert result is not None assert isinstance(result, queries.GetAllEmbeddedTestPostgresTypeRow) @@ -415,9 +409,7 @@ async def test_get_all_embedded( assert result.test_inner_postgres_type == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestMsgspecClasses::get_all_embedded"], name="TestMsgspecClasses::get_all_embedded_none" - ) + @pytest.mark.dependency(depends=["TestMsgspecClasses::get_all_embedded"], name="TestMsgspecClasses::get_all_embedded_none") async def test_get_all_embedded_none( self, queries_obj: queries.Queries, @@ -436,7 +428,7 @@ async def test_get_many_iterator( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - results = queries_obj.get_many_test_iterator_postgres_type(id_=model.id) + results = queries_obj.get_many_test_iterator_postgres_type(id_=model.id_) async with queries_obj.conn.transaction(): async for result in results: assert result is not None @@ -451,7 +443,7 @@ async def test_delete( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - await queries_obj.delete_one_test_postgres_type(id_=model.id) + await queries_obj.delete_one_test_postgres_type(id_=model.id_) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestMsgspecClasses::delete"], name="TestMsgspecClasses::delete_inner") @@ -470,7 +462,7 @@ async def test_create_result( model: models.TestPostgresType, ) -> None: result = await queries_obj.create_result_one_test_postgres_type( - id_=model.id + 1, + id_=model.id_ + 1, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -517,7 +509,7 @@ async def test_update_result( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - result = await queries_obj.update_result_test_postgres_type(id_=model.id + 1) + result = await queries_obj.update_result_test_postgres_type(id_=model.id_ + 1) assert result == "UPDATE 1" @@ -528,7 +520,7 @@ async def test_delete_result( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - result = await queries_obj.delete_one_result_test_postgres_type(id_=model.id + 1) + result = await queries_obj.delete_one_result_test_postgres_type(id_=model.id_ + 1) assert result == "DELETE 1" @@ -540,7 +532,7 @@ async def test_create_rows( model: models.TestPostgresType, ) -> None: result = await queries_obj.create_rows_one_test_postgres_type( - id_=model.id + 1, + id_=model.id_ + 1, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -587,7 +579,7 @@ async def test_update_rows( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - result = await queries_obj.update_rows_test_postgres_type(id_=model.id + 1) + result = await queries_obj.update_rows_test_postgres_type(id_=model.id_ + 1) assert result == 1 @@ -598,7 +590,7 @@ async def test_delete_rows( queries_obj: queries.Queries, model: models.TestPostgresType, ) -> None: - result = await queries_obj.delete_one_rows_test_postgres_type(id_=model.id + 1) + result = await queries_obj.delete_one_rows_test_postgres_type(id_=model.id_ + 1) assert result == 1 @@ -613,7 +605,7 @@ async def test_copy_from( num = 3 rows: list[queries.TestCopyFromParams] = [ queries.TestCopyFromParams( - id=i, + id_=i, int_test=model.int_test, float_test=model.float_test, ) @@ -640,20 +632,16 @@ async def test_create_table( @pytest.mark.dependency( name="TestMsgspecClasses::insert_type_override", ) - async def test_insert_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - await queries_obj.insert_type_override(id_=override_model.id, text_test=override_model.text_test) + async def test_insert_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.insert_type_override(id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="TestMsgspecClasses::get_one_type_override", depends=["TestMsgspecClasses::insert_type_override"], ) - async def test_get_one_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_type_override(id_=override_model.id) + async def test_get_one_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_) assert result is not None assert result == override_model @@ -662,10 +650,8 @@ async def test_get_one_type_override( name="TestMsgspecClasses::get_one_type_override_none", depends=["TestMsgspecClasses::get_one_type_override"], ) - async def test_get_one_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_type_override(id_=override_model.id - 1) + async def test_get_one_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -673,10 +659,8 @@ async def test_get_one_type_override_none( name="TestMsgspecClasses::get_many_type_override", depends=["TestMsgspecClasses::get_one_type_override_none"], ) - async def test_get_many_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_many_type_override(id_=override_model.id) + async def test_get_many_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_type_override(id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model @@ -685,10 +669,8 @@ async def test_get_many_type_override( name="TestMsgspecClasses::get_one_text_type_override", depends=["TestMsgspecClasses::get_many_type_override"], ) - async def test_get_one_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_text_type_override(id_=override_model.id) + async def test_get_one_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -697,10 +679,8 @@ async def test_get_one_text_type_override( name="TestMsgspecClasses::get_one_text_type_override_none", depends=["TestMsgspecClasses::get_one_text_type_override"], ) - async def test_get_one_text_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_one_text_type_override(id_=override_model.id - 1) + async def test_get_one_text_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -708,10 +688,8 @@ async def test_get_one_text_type_override_none( name="TestMsgspecClasses::get_many_text_type_override", depends=["TestMsgspecClasses::get_one_text_type_override_none"], ) - async def test_get_many_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = await queries_obj.get_many_text_type_override(id_=override_model.id) + async def test_get_many_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_text_type_override(id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model.text_test @@ -720,7 +698,5 @@ async def test_get_many_text_type_override( name="TestMsgspecClasses::delete_type_override", depends=["TestMsgspecClasses::get_many_text_type_override"], ) - async def test_delete_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - await queries_obj.delete_type_override(id_=override_model.id) + async def test_delete_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.delete_type_override(id_=override_model.id_) diff --git a/test/driver_asyncpg/msgspec/test_msgspec_functions.py b/test/driver_asyncpg/msgspec/test_msgspec_functions.py index 5fe31b7a..a2d4935f 100644 --- a/test/driver_asyncpg/msgspec/test_msgspec_functions.py +++ b/test/driver_asyncpg/msgspec/test_msgspec_functions.py @@ -34,20 +34,23 @@ import pytest +from test.driver_asyncpg.msgspec.functions import enums from test.driver_asyncpg.msgspec.functions import models from test.driver_asyncpg.msgspec.functions import queries +from test.driver_asyncpg.msgspec.functions import queries_copy_override +from test.driver_asyncpg.msgspec.functions import queries_enum_override @pytest.mark.asyncio(loop_scope="session") class TestMsgspecFunctions: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestPostgresType: return models.TestPostgresType( - id=random.randint(1, 1000000), + id_=random.randint(1, 1000000), serial_test=1, serial4_test=2, bigserial_test=3, @@ -66,9 +69,9 @@ def model(self) -> models.TestPostgresType: bytea_test=memoryview(b"\x00\x01\x02hello"), date_test=datetime.date(2025, 1, 1), time_test=datetime.time(14, 30, 0), - timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.timezone.utc), + timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.UTC), timestamp_test=datetime.datetime(2025, 1, 1, 14, 30, 0), - timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.timezone.utc), + timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.UTC), interval_test=datetime.timedelta(days=1, hours=2, minutes=30), text_test="Lorem ipsum", varchar_test="Example varchar", @@ -88,7 +91,7 @@ def model(self) -> models.TestPostgresType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestPostgresType) -> models.TestInnerPostgresType: return models.TestInnerPostgresType( - table_id=model.id, + table_id=model.id_, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -135,7 +138,7 @@ async def test_create( ) -> None: await queries.create_one_test_postgres_type( conn=asyncpg_conn, - id_=model.id, + id_=model.id_, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -227,7 +230,7 @@ async def test_get_one( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_one_test_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_one_test_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, models.TestPostgresType) @@ -259,9 +262,7 @@ async def test_get_one_inner( assert result == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestMsgspecFunctions::get_one_inner"], name="TestMsgspecFunctions::get_one_inner_none" - ) + @pytest.mark.dependency(depends=["TestMsgspecFunctions::get_one_inner"], name="TestMsgspecFunctions::get_one_inner_none") async def test_get_one_inner_none( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], @@ -280,16 +281,14 @@ async def test_get_one_timestamp( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_one_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_one_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestMsgspecFunctions::get_one_timestamp"], name="TestMsgspecFunctions::get_one_timestamp_none" - ) + @pytest.mark.dependency(depends=["TestMsgspecFunctions::get_one_timestamp"], name="TestMsgspecFunctions::get_one_timestamp_none") async def test_get_one_timestamp_none( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], @@ -308,16 +307,14 @@ async def test_get_one_bytea( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_one_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_one_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, memoryview) assert result == model.bytea_test @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestMsgspecFunctions::get_one_bytea"], name="TestMsgspecFunctions::get_one_bytea_none" - ) + @pytest.mark.dependency(depends=["TestMsgspecFunctions::get_one_bytea"], name="TestMsgspecFunctions::get_one_bytea_none") async def test_get_one_bytea_none( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], @@ -333,7 +330,7 @@ async def test_get_many( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_many_test_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_many_test_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -352,7 +349,7 @@ async def test_get_many_timestamp( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_many_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_many_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -370,7 +367,7 @@ async def test_get_many_bytea( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.get_many_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_many_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, collections.abc.Sequence) @@ -389,13 +386,13 @@ async def test_get_embedded( model: models.TestPostgresType, inner_model: models.TestInnerPostgresType, ) -> None: - result = await queries.get_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, queries.GetEmbeddedTestPostgresTypeRow) assert isinstance(result.test_inner_postgres_type, models.TestInnerPostgresType) - assert result.id == model.id + assert result.id_ == model.id_ assert result.serial_test == model.serial_test assert result.serial4_test == model.serial4_test assert result.bigserial_test == model.bigserial_test @@ -435,9 +432,7 @@ async def test_get_embedded( assert result.test_inner_postgres_type == inner_model @pytest.mark.asyncio(loop_scope="session") - @pytest.mark.dependency( - depends=["TestMsgspecFunctions::get_embedded"], name="TestMsgspecFunctions::get_embedded_none" - ) + @pytest.mark.dependency(depends=["TestMsgspecFunctions::get_embedded"], name="TestMsgspecFunctions::get_embedded_none") async def test_get_embedded_none( self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], @@ -457,7 +452,7 @@ async def test_get_all_embedded( model: models.TestPostgresType, inner_model: models.TestInnerPostgresType, ) -> None: - result = await queries.get_all_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id) + result = await queries.get_all_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id_) assert result is not None assert isinstance(result, queries.GetAllEmbeddedTestPostgresTypeRow) @@ -490,7 +485,7 @@ async def test_get_many_iterator( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - results = queries.get_many_test_iterator_postgres_type(conn=asyncpg_conn, id_=model.id) + results = queries.get_many_test_iterator_postgres_type(conn=asyncpg_conn, id_=model.id_) async with asyncpg_conn.transaction(): async for result in results: assert result is not None @@ -505,7 +500,7 @@ async def test_delete( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - await queries.delete_one_test_postgres_type(conn=asyncpg_conn, id_=model.id) + await queries.delete_one_test_postgres_type(conn=asyncpg_conn, id_=model.id_) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency(depends=["TestMsgspecFunctions::delete"], name="TestMsgspecFunctions::delete_inner") @@ -525,7 +520,7 @@ async def test_create_result( ) -> None: result = await queries.create_result_one_test_postgres_type( conn=asyncpg_conn, - id_=model.id + 1, + id_=model.id_ + 1, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -572,7 +567,7 @@ async def test_update_result( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.update_result_test_postgres_type(conn=asyncpg_conn, id_=model.id + 1) + result = await queries.update_result_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) assert result == "UPDATE 1" @@ -583,7 +578,7 @@ async def test_delete_result( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.delete_one_result_test_postgres_type(conn=asyncpg_conn, id_=model.id + 1) + result = await queries.delete_one_result_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) assert result == "DELETE 1" @@ -596,7 +591,7 @@ async def test_create_rows( ) -> None: result = await queries.create_rows_one_test_postgres_type( conn=asyncpg_conn, - id_=model.id + 1, + id_=model.id_ + 1, serial_test=model.serial_test, serial4_test=model.serial4_test, bigserial_test=model.bigserial_test, @@ -643,7 +638,7 @@ async def test_update_rows( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.update_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id + 1) + result = await queries.update_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) assert result == 1 @@ -654,7 +649,7 @@ async def test_delete_rows( asyncpg_conn: asyncpg.Connection[asyncpg.Record], model: models.TestPostgresType, ) -> None: - result = await queries.delete_one_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id + 1) + result = await queries.delete_one_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) assert result == 1 @@ -668,7 +663,7 @@ async def test_copy_from( num = 3 rows: list[queries.TestCopyFromParams] = [ queries.TestCopyFromParams( - id=i, + id_=i, int_test=model.int_test, float_test=model.float_test, ) @@ -694,20 +689,16 @@ async def test_create_table( @pytest.mark.dependency( name="TestMsgspecFunctions::insert_type_override", ) - async def test_insert_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - await queries.insert_type_override(conn=asyncpg_conn, id_=override_model.id, text_test=override_model.text_test) + async def test_insert_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + await queries.insert_type_override(conn=asyncpg_conn, id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.asyncio(loop_scope="session") @pytest.mark.dependency( name="TestMsgspecFunctions::get_one_type_override", depends=["TestMsgspecFunctions::insert_type_override"], ) - async def test_get_one_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_get_one_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id_) assert result is not None assert result == override_model @@ -716,10 +707,8 @@ async def test_get_one_type_override( name="TestMsgspecFunctions::get_one_type_override_none", depends=["TestMsgspecFunctions::get_one_type_override"], ) - async def test_get_one_type_override_none( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id - 1) + async def test_get_one_type_override_none(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -727,10 +716,8 @@ async def test_get_one_type_override_none( name="TestMsgspecFunctions::get_many_type_override", depends=["TestMsgspecFunctions::get_one_type_override_none"], ) - async def test_get_many_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_many_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_get_many_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_type_override(conn=asyncpg_conn, id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model @@ -739,10 +726,8 @@ async def test_get_many_type_override( name="TestMsgspecFunctions::get_one_text_type_override", depends=["TestMsgspecFunctions::get_many_type_override"], ) - async def test_get_one_text_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_get_one_text_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -751,10 +736,8 @@ async def test_get_one_text_type_override( name="TestMsgspecFunctions::get_one_text_type_override_none", depends=["TestMsgspecFunctions::get_one_text_type_override"], ) - async def test_get_one_text_type_override_none( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id - 1) + async def test_get_one_text_type_override_none(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.asyncio(loop_scope="session") @@ -762,10 +745,8 @@ async def test_get_one_text_type_override_none( name="TestMsgspecFunctions::get_many_text_type_override", depends=["TestMsgspecFunctions::get_one_text_type_override_none"], ) - async def test_get_many_text_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - result = await queries.get_many_text_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_get_many_text_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_text_type_override(conn=asyncpg_conn, id_=override_model.id_) assert isinstance(result, collections.abc.Sequence) assert result[0] == override_model.text_test @@ -774,7 +755,90 @@ async def test_get_many_text_type_override( name="TestMsgspecFunctions::delete_type_override", depends=["TestMsgspecFunctions::get_many_text_type_override"], ) - async def test_delete_type_override( - self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride - ) -> None: - await queries.delete_type_override(conn=asyncpg_conn, id_=override_model.id) + async def test_delete_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + await queries.delete_type_override(conn=asyncpg_conn, id_=override_model.id_) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestMsgspecFunctions::insert_enum") + async def test_insert_enum(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> None: + await queries.insert_one_test_enum_type(conn=asyncpg_conn, id_=424242, mood=enums.TestMood.HAPPY, maybe_mood=None) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestMsgspecFunctions::get_enum", depends=["TestMsgspecFunctions::insert_enum"]) + async def test_get_enum(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> None: + result = await queries.get_one_test_enum_type(conn=asyncpg_conn, id_=424242) + assert result is not None + assert isinstance(result.mood, enums.TestMood) + assert result.mood is enums.TestMood.HAPPY + assert result.maybe_mood is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestMsgspecFunctions::get_enum_value", depends=["TestMsgspecFunctions::get_enum"]) + async def test_get_enum_value(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> None: + mood = await queries.get_one_test_enum_value(conn=asyncpg_conn, id_=424242) + assert isinstance(mood, enums.TestMood) + assert mood is enums.TestMood.HAPPY + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestMsgspecFunctions::get_many_enums", depends=["TestMsgspecFunctions::get_enum_value"]) + async def test_get_many_enums(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> None: + result = await queries.get_many_test_enum_types(conn=asyncpg_conn) + assert len(result) >= 1 + assert all(isinstance(row.mood, enums.TestMood) for row in result) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestMsgspecFunctions::get_many_enums"]) + async def test_delete_enum(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> None: + assert await queries.delete_one_test_enum_type(conn=asyncpg_conn, id_=424242) == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestMsgspecFunctions::insert_enum_override") + async def test_insert_enum_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> None: + # The overridden parameter is a plain str; the generated code converts + # it back to enums.TestMood before it reaches the driver. + await queries_enum_override.insert_enum_override(conn=asyncpg_conn, id_=434343, mood_test="happy") + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestMsgspecFunctions::insert_enum_override"]) + async def test_get_enum_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> None: + mood = await queries_enum_override.get_enum_override_mood(conn=asyncpg_conn, id_=434343) + assert mood is not None + assert isinstance(mood, str) + assert mood == "happy" + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestMsgspecFunctions::list_enum_override", depends=["TestMsgspecFunctions::insert_enum_override"]) + async def test_list_enum_override_by_ids(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> None: + # :many with an array parameter: the Sequence must pass both pyright + # (QueryResultsArgsType) and the runtime QueryResults plumbing. + rows = await queries_enum_override.list_enum_override_by_ids(conn=asyncpg_conn, dollar_1=[434343]) + assert len(rows) == 1 + assert rows[0].mood_test == "happy" + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestMsgspecFunctions::insert_enum_override"]) + async def test_count_enum_override_by_moods(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> None: + count = await queries_enum_override.count_enum_override_by_moods(conn=asyncpg_conn, dollar_1=[enums.TestMood.HAPPY, enums.TestMood.SAD]) + assert count == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestMsgspecFunctions::copy_override") + async def test_copy_override_rows(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> None: + # The overridden float values must be converted back to Decimal before + # copy_records_to_table. + params = [ + queries_copy_override.CopyOverrideRowsParams(id_=1, amount=12.5), + queries_copy_override.CopyOverrideRowsParams(id_=2, amount=0.25), + ] + inserted = await queries_copy_override.copy_override_rows(conn=asyncpg_conn, params=params) + assert inserted == len(params) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestMsgspecFunctions::copy_override"]) + async def test_count_and_delete_copy_override_rows(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> None: + copied_rows = 2 + count = await queries_copy_override.count_copy_override_rows(conn=asyncpg_conn) + assert count == copied_rows + await queries_copy_override.delete_copy_override_rows(conn=asyncpg_conn) + count = await queries_copy_override.count_copy_override_rows(conn=asyncpg_conn) + assert count == 0 diff --git a/test/driver_asyncpg/omit_tc/__init__.py b/test/driver_asyncpg/omit_tc/__init__.py new file mode 100644 index 00000000..23c84d55 --- /dev/null +++ b/test/driver_asyncpg/omit_tc/__init__.py @@ -0,0 +1,20 @@ +# Copyright (c) 2025 Rayakame + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +"""Package to allow importing for asyncpg omit_typechecking_block tests.""" diff --git a/test/driver_asyncpg/omit_tc/classes/__init__.py b/test/driver_asyncpg/omit_tc/classes/__init__.py new file mode 100644 index 00000000..5c9110dc --- /dev/null +++ b/test/driver_asyncpg/omit_tc/classes/__init__.py @@ -0,0 +1,5 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_asyncpg/omit_tc/classes/enums.py b/test/driver_asyncpg/omit_tc/classes/enums.py new file mode 100644 index 00000000..936931ea --- /dev/null +++ b/test/driver_asyncpg/omit_tc/classes/enums.py @@ -0,0 +1,20 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing enums.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("TestMood",) + +import enum +import collections.abc + + +class TestMood(enum.StrEnum): + """Enum representing TestMood.""" + + SAD = "sad" + OK = "ok" + HAPPY = "happy" diff --git a/test/driver_asyncpg/omit_tc/classes/models.py b/test/driver_asyncpg/omit_tc/classes/models.py new file mode 100644 index 00000000..1d2c050e --- /dev/null +++ b/test/driver_asyncpg/omit_tc/classes/models.py @@ -0,0 +1,25 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing models.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("TestEnumOverride",) + +import dataclasses +import collections.abc + + +@dataclasses.dataclass() +class TestEnumOverride: + """Model representing TestEnumOverride. + + Attributes: + id_: int + mood_test: str + """ + + id_: int + mood_test: str diff --git a/test/driver_asyncpg/omit_tc/classes/queries_enum_override.py b/test/driver_asyncpg/omit_tc/classes/queries_enum_override.py new file mode 100644 index 00000000..453d5ed7 --- /dev/null +++ b/test/driver_asyncpg/omit_tc/classes/queries_enum_override.py @@ -0,0 +1,210 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_enum_override.sql +"""Module containing queries from file queries_enum_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "QueriesEnumOverride", + "QueryResults", +) + +import typing +import asyncpg +import asyncpg.cursor +import collections.abc + + +from test.driver_asyncpg.omit_tc.classes import enums +from test.driver_asyncpg.omit_tc.classes import models + +type QueryResultsArgsType = int | float | str | memoryview | collections.abc.Sequence[QueryResultsArgsType] | None + +type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + + +INSERT_ENUM_OVERRIDE: typing.Final[str] = """-- name: InsertEnumOverride :exec +INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) +""" + +GET_ENUM_OVERRIDE_MOOD: typing.Final[str] = """-- name: GetEnumOverrideMood :one +SELECT mood_test FROM test_enum_override WHERE id = $1 +""" + +LIST_ENUM_OVERRIDE_BY_IDS: typing.Final[str] = """-- name: ListEnumOverrideByIds :many +SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) +""" + +COUNT_ENUM_OVERRIDE_BY_MOODS: typing.Final[str] = """-- name: CountEnumOverrideByMoods :one +SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: ConnectionLike, + sql: str, + decode_hook: collections.abc.Callable[[asyncpg.Record], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Args: + conn: + The connection object of type `ConnectionLike` used to execute queries. + sql: + The SQL statement that will be executed when fetching/iterating. + decode_hook: + A callback that turns an `asyncpg.Record` object into `T` that will be returned. + *args: + Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: asyncpg.cursor.CursorFactory[asyncpg.Record] | None = None + self._iterator: asyncpg.cursor.CursorIterator[asyncpg.Record] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns: + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await self._conn.fetch(self._sql, *self._args) + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an asyncpg cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopAsyncIteration: When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor = self._conn.cursor(self._sql, *self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +class QueriesEnumOverride: + """Queries from file queries_enum_override.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: ConnectionLike) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> ConnectionLike: + """Connection object used to make queries. + + Returns: + Connection object of type `ConnectionLike` used to make queries. + """ + return self._conn + + async def insert_enum_override(self, *, id_: int, mood_test: str) -> None: + """Execute SQL query with `name: InsertEnumOverride :exec`. + + ```sql + INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) + ``` + + Args: + id_: int. + mood_test: str. + """ + await self._conn.execute(INSERT_ENUM_OVERRIDE, id_, enums.TestMood(mood_test)) + + async def get_enum_override_mood(self, *, id_: int) -> str | None: + """Fetch one from the db using the SQL query with `name: GetEnumOverrideMood :one`. + + ```sql + SELECT mood_test FROM test_enum_override WHERE id = $1 + ``` + + Args: + id_: int. + + Returns: + Result of type `str` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ENUM_OVERRIDE_MOOD, id_) + if row is None: + return None + return str(row[0]) + + def list_enum_override_by_ids(self, *, dollar_1: collections.abc.Sequence[int]) -> QueryResults[models.TestEnumOverride]: + """Fetch many from the db using the SQL query with `name: ListEnumOverrideByIds :many`. + + ```sql + SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) + ``` + + Args: + dollar_1: collections.abc.Sequence[int]. + + Returns: + Helper class of type `QueryResults[models.TestEnumOverride]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestEnumOverride: + return models.TestEnumOverride(id_=row[0], mood_test=str(row[1])) + + return QueryResults(self._conn, LIST_ENUM_OVERRIDE_BY_IDS, _decode_hook, dollar_1) + + async def count_enum_override_by_moods(self, *, dollar_1: collections.abc.Sequence[enums.TestMood]) -> int | None: + """Fetch one from the db using the SQL query with `name: CountEnumOverrideByMoods :one`. + + ```sql + SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) + ``` + + Args: + dollar_1: collections.abc.Sequence[enums.TestMood]. + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(COUNT_ENUM_OVERRIDE_BY_MOODS, dollar_1) + if row is None: + return None + return row[0] diff --git a/test/driver_asyncpg/omit_tc/functions/__init__.py b/test/driver_asyncpg/omit_tc/functions/__init__.py new file mode 100644 index 00000000..5c9110dc --- /dev/null +++ b/test/driver_asyncpg/omit_tc/functions/__init__.py @@ -0,0 +1,5 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_asyncpg/omit_tc/functions/enums.py b/test/driver_asyncpg/omit_tc/functions/enums.py new file mode 100644 index 00000000..936931ea --- /dev/null +++ b/test/driver_asyncpg/omit_tc/functions/enums.py @@ -0,0 +1,20 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing enums.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("TestMood",) + +import enum +import collections.abc + + +class TestMood(enum.StrEnum): + """Enum representing TestMood.""" + + SAD = "sad" + OK = "ok" + HAPPY = "happy" diff --git a/test/driver_asyncpg/omit_tc/functions/models.py b/test/driver_asyncpg/omit_tc/functions/models.py new file mode 100644 index 00000000..1d2c050e --- /dev/null +++ b/test/driver_asyncpg/omit_tc/functions/models.py @@ -0,0 +1,25 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing models.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("TestEnumOverride",) + +import dataclasses +import collections.abc + + +@dataclasses.dataclass() +class TestEnumOverride: + """Model representing TestEnumOverride. + + Attributes: + id_: int + mood_test: str + """ + + id_: int + mood_test: str diff --git a/test/driver_asyncpg/omit_tc/functions/queries_enum_override.py b/test/driver_asyncpg/omit_tc/functions/queries_enum_override.py new file mode 100644 index 00000000..8858f6c7 --- /dev/null +++ b/test/driver_asyncpg/omit_tc/functions/queries_enum_override.py @@ -0,0 +1,201 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_enum_override.sql +"""Module containing queries from file queries_enum_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "QueryResults", + "count_enum_override_by_moods", + "get_enum_override_mood", + "insert_enum_override", + "list_enum_override_by_ids", +) + +import typing +import asyncpg +import asyncpg.cursor +import collections.abc + + +from test.driver_asyncpg.omit_tc.functions import enums +from test.driver_asyncpg.omit_tc.functions import models + +type QueryResultsArgsType = int | float | str | memoryview | collections.abc.Sequence[QueryResultsArgsType] | None + +type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + + +INSERT_ENUM_OVERRIDE: typing.Final[str] = """-- name: InsertEnumOverride :exec +INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) +""" + +GET_ENUM_OVERRIDE_MOOD: typing.Final[str] = """-- name: GetEnumOverrideMood :one +SELECT mood_test FROM test_enum_override WHERE id = $1 +""" + +LIST_ENUM_OVERRIDE_BY_IDS: typing.Final[str] = """-- name: ListEnumOverrideByIds :many +SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) +""" + +COUNT_ENUM_OVERRIDE_BY_MOODS: typing.Final[str] = """-- name: CountEnumOverrideByMoods :one +SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: ConnectionLike, + sql: str, + decode_hook: collections.abc.Callable[[asyncpg.Record], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Args: + conn: + The connection object of type `ConnectionLike` used to execute queries. + sql: + The SQL statement that will be executed when fetching/iterating. + decode_hook: + A callback that turns an `asyncpg.Record` object into `T` that will be returned. + *args: + Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: asyncpg.cursor.CursorFactory[asyncpg.Record] | None = None + self._iterator: asyncpg.cursor.CursorIterator[asyncpg.Record] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns: + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await self._conn.fetch(self._sql, *self._args) + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an asyncpg cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopAsyncIteration: When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor = self._conn.cursor(self._sql, *self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +async def insert_enum_override(conn: ConnectionLike, *, id_: int, mood_test: str) -> None: + """Execute SQL query with `name: InsertEnumOverride :exec`. + + ```sql + INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + mood_test: str. + """ + await conn.execute(INSERT_ENUM_OVERRIDE, id_, enums.TestMood(mood_test)) + + +async def get_enum_override_mood(conn: ConnectionLike, *, id_: int) -> str | None: + """Fetch one from the db using the SQL query with `name: GetEnumOverrideMood :one`. + + ```sql + SELECT mood_test FROM test_enum_override WHERE id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `str` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ENUM_OVERRIDE_MOOD, id_) + if row is None: + return None + return str(row[0]) + + +def list_enum_override_by_ids(conn: ConnectionLike, *, dollar_1: collections.abc.Sequence[int]) -> QueryResults[models.TestEnumOverride]: + """Fetch many from the db using the SQL query with `name: ListEnumOverrideByIds :many`. + + ```sql + SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + dollar_1: collections.abc.Sequence[int]. + + Returns: + Helper class of type `QueryResults[models.TestEnumOverride]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestEnumOverride: + return models.TestEnumOverride(id_=row[0], mood_test=str(row[1])) + + return QueryResults(conn, LIST_ENUM_OVERRIDE_BY_IDS, _decode_hook, dollar_1) + + +async def count_enum_override_by_moods(conn: ConnectionLike, *, dollar_1: collections.abc.Sequence[enums.TestMood]) -> int | None: + """Fetch one from the db using the SQL query with `name: CountEnumOverrideByMoods :one`. + + ```sql + SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + dollar_1: collections.abc.Sequence[enums.TestMood]. + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(COUNT_ENUM_OVERRIDE_BY_MOODS, dollar_1) + if row is None: + return None + return row[0] diff --git a/test/driver_asyncpg/omit_tc/ruff.toml b/test/driver_asyncpg/omit_tc/ruff.toml new file mode 100644 index 00000000..0fa548a4 --- /dev/null +++ b/test/driver_asyncpg/omit_tc/ruff.toml @@ -0,0 +1,5 @@ +extend="../../../ruff.toml" + + +[lint.pydocstyle] +convention = "google" diff --git a/test/driver_asyncpg/omit_tc/test_omit_typechecking_import.py b/test/driver_asyncpg/omit_tc/test_omit_typechecking_import.py new file mode 100644 index 00000000..dd45a032 --- /dev/null +++ b/test/driver_asyncpg/omit_tc/test_omit_typechecking_import.py @@ -0,0 +1,35 @@ +# Copyright (c) 2025 Rayakame + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +"""With omit_typechecking_block the driver hook executes at module level. + +Importing the generated modules is the whole test: stub-only generics like +``asyncpg.Connection[...]`` must never be evaluated eagerly, which the lazy +PEP 695 alias form guarantees. +""" + +from __future__ import annotations + +from test.driver_asyncpg.omit_tc.classes import queries_enum_override as classes_module +from test.driver_asyncpg.omit_tc.functions import queries_enum_override as functions_module + + +def test_omit_typechecking_modules_import_at_runtime() -> None: + assert classes_module.INSERT_ENUM_OVERRIDE + assert functions_module.INSERT_ENUM_OVERRIDE diff --git a/test/driver_asyncpg/pydantic/__init__.py b/test/driver_asyncpg/pydantic/__init__.py new file mode 100644 index 00000000..b4b6b22c --- /dev/null +++ b/test/driver_asyncpg/pydantic/__init__.py @@ -0,0 +1,20 @@ +# Copyright (c) 2025 Rayakame + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +"""Package to allow importing for asyncpg tests.""" diff --git a/test/driver_asyncpg/pydantic/classes/__init__.py b/test/driver_asyncpg/pydantic/classes/__init__.py new file mode 100644 index 00000000..5c9110dc --- /dev/null +++ b/test/driver_asyncpg/pydantic/classes/__init__.py @@ -0,0 +1,5 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_asyncpg/pydantic/classes/enums.py b/test/driver_asyncpg/pydantic/classes/enums.py new file mode 100644 index 00000000..d49ac611 --- /dev/null +++ b/test/driver_asyncpg/pydantic/classes/enums.py @@ -0,0 +1,23 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing enums.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("TestMood",) + +import enum +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +class TestMood(enum.StrEnum): + """Enum representing TestMood.""" + + SAD = "sad" + OK = "ok" + HAPPY = "happy" diff --git a/test/driver_asyncpg/pydantic/classes/models.py b/test/driver_asyncpg/pydantic/classes/models.py new file mode 100644 index 00000000..2a610044 --- /dev/null +++ b/test/driver_asyncpg/pydantic/classes/models.py @@ -0,0 +1,235 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing models.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "TestEnumOverride", + "TestEnumType", + "TestInnerPostgresType", + "TestPostgresType", + "TestTypeOverride", +) + +from collections import UserString +import datetime +import decimal +import pydantic +import typing +import uuid + +if typing.TYPE_CHECKING: + import collections.abc + +from test.driver_asyncpg.pydantic.classes import enums + + +class TestEnumOverride(pydantic.BaseModel): + """Model representing TestEnumOverride. + + Attributes: + id_: int + mood_test: str + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + mood_test: str + + +class TestEnumType(pydantic.BaseModel): + """Model representing TestEnumType. + + Attributes: + id_: int + mood: enums.TestMood + maybe_mood: enums.TestMood | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + mood: enums.TestMood + maybe_mood: enums.TestMood | None + + +class TestInnerPostgresType(pydantic.BaseModel): + """Model representing TestInnerPostgresType. + + Attributes: + table_id: int + serial_test: int | None + serial4_test: int | None + bigserial_test: int | None + smallserial_test: int | None + int_test: int | None + bigint_test: int | None + smallint_test: int | None + float_test: float | None + double_precision_test: float | None + real_test: float | None + numeric_test: decimal.Decimal | None + money_test: str | None + bool_test: bool | None + json_test: str | None + jsonb_test: str | None + bytea_test: memoryview | None + date_test: datetime.date | None + time_test: datetime.time | None + timetz_test: datetime.time | None + timestamp_test: datetime.datetime | None + timestamptz_test: datetime.datetime | None + interval_test: datetime.timedelta | None + text_test: str | None + varchar_test: str | None + bpchar_test: str | None + char_test: str | None + citext_test: str | None + uuid_test: uuid.UUID | None + inet_test: str | None + cidr_test: str | None + macaddr_test: str | None + macaddr8_test: str | None + ltree_test: str | None + lquery_test: str | None + ltxtquery_test: str | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + table_id: int + serial_test: int | None + serial4_test: int | None + bigserial_test: int | None + smallserial_test: int | None + int_test: int | None + bigint_test: int | None + smallint_test: int | None + float_test: float | None + double_precision_test: float | None + real_test: float | None + numeric_test: decimal.Decimal | None + money_test: str | None + bool_test: bool | None + json_test: str | None + jsonb_test: str | None + bytea_test: memoryview | None + date_test: datetime.date | None + time_test: datetime.time | None + timetz_test: datetime.time | None + timestamp_test: datetime.datetime | None + timestamptz_test: datetime.datetime | None + interval_test: datetime.timedelta | None + text_test: str | None + varchar_test: str | None + bpchar_test: str | None + char_test: str | None + citext_test: str | None + uuid_test: uuid.UUID | None + inet_test: str | None + cidr_test: str | None + macaddr_test: str | None + macaddr8_test: str | None + ltree_test: str | None + lquery_test: str | None + ltxtquery_test: str | None + + +class TestPostgresType(pydantic.BaseModel): + """Model representing TestPostgresType. + + Attributes: + id_: int + serial_test: int + serial4_test: int + bigserial_test: int + smallserial_test: int + int_test: int + bigint_test: int + smallint_test: int + float_test: float + double_precision_test: float + real_test: float + numeric_test: decimal.Decimal + money_test: str + bool_test: bool + json_test: str + jsonb_test: str + bytea_test: memoryview + date_test: datetime.date + time_test: datetime.time + timetz_test: datetime.time + timestamp_test: datetime.datetime + timestamptz_test: datetime.datetime + interval_test: datetime.timedelta + text_test: str + varchar_test: str + bpchar_test: str + char_test: str + citext_test: str + uuid_test: uuid.UUID + inet_test: str + cidr_test: str + macaddr_test: str + macaddr8_test: str + ltree_test: str + lquery_test: str + ltxtquery_test: str + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + serial_test: int + serial4_test: int + bigserial_test: int + smallserial_test: int + int_test: int + bigint_test: int + smallint_test: int + float_test: float + double_precision_test: float + real_test: float + numeric_test: decimal.Decimal + money_test: str + bool_test: bool + json_test: str + jsonb_test: str + bytea_test: memoryview + date_test: datetime.date + time_test: datetime.time + timetz_test: datetime.time + timestamp_test: datetime.datetime + timestamptz_test: datetime.datetime + interval_test: datetime.timedelta + text_test: str + varchar_test: str + bpchar_test: str + char_test: str + citext_test: str + uuid_test: uuid.UUID + inet_test: str + cidr_test: str + macaddr_test: str + macaddr8_test: str + ltree_test: str + lquery_test: str + ltxtquery_test: str + + +class TestTypeOverride(pydantic.BaseModel): + """Model representing TestTypeOverride. + + Attributes: + id_: int + text_test: UserString | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + text_test: UserString | None diff --git a/test/driver_asyncpg/pydantic/classes/queries.py b/test/driver_asyncpg/pydantic/classes/queries.py new file mode 100644 index 00000000..372c56f5 --- /dev/null +++ b/test/driver_asyncpg/pydantic/classes/queries.py @@ -0,0 +1,2083 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql +"""Module containing queries from file queries.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "GetAllEmbeddedTestPostgresTypeRow", + "GetEmbeddedTestPostgresTypeRow", + "Queries", + "QueryResults", + "TestCopyFromParams", +) + +from collections import UserString +import datetime +import decimal +import operator +import pydantic +import typing +import uuid + +if typing.TYPE_CHECKING: + import asyncpg + import asyncpg.cursor + import collections.abc + + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + +from test.driver_asyncpg.pydantic.classes import enums +from test.driver_asyncpg.pydantic.classes import models + + +class GetEmbeddedTestPostgresTypeRow(pydantic.BaseModel): + """Model representing GetEmbeddedTestPostgresTypeRow. + + Attributes: + id_: int + serial_test: int + serial4_test: int + bigserial_test: int + smallserial_test: int + int_test: int + bigint_test: int + smallint_test: int + float_test: float + double_precision_test: float + real_test: float + numeric_test: decimal.Decimal + money_test: str + bool_test: bool + json_test: str + jsonb_test: str + bytea_test: memoryview + date_test: datetime.date + time_test: datetime.time + timetz_test: datetime.time + timestamp_test: datetime.datetime + timestamptz_test: datetime.datetime + interval_test: datetime.timedelta + text_test: str + varchar_test: str + bpchar_test: str + char_test: str + citext_test: str + uuid_test: uuid.UUID + inet_test: str + cidr_test: str + macaddr_test: str + macaddr8_test: str + ltree_test: str + lquery_test: str + ltxtquery_test: str + test_inner_postgres_type: models.TestInnerPostgresType + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + serial_test: int + serial4_test: int + bigserial_test: int + smallserial_test: int + int_test: int + bigint_test: int + smallint_test: int + float_test: float + double_precision_test: float + real_test: float + numeric_test: decimal.Decimal + money_test: str + bool_test: bool + json_test: str + jsonb_test: str + bytea_test: memoryview + date_test: datetime.date + time_test: datetime.time + timetz_test: datetime.time + timestamp_test: datetime.datetime + timestamptz_test: datetime.datetime + interval_test: datetime.timedelta + text_test: str + varchar_test: str + bpchar_test: str + char_test: str + citext_test: str + uuid_test: uuid.UUID + inet_test: str + cidr_test: str + macaddr_test: str + macaddr8_test: str + ltree_test: str + lquery_test: str + ltxtquery_test: str + test_inner_postgres_type: models.TestInnerPostgresType + + +class GetAllEmbeddedTestPostgresTypeRow(pydantic.BaseModel): + """Model representing GetAllEmbeddedTestPostgresTypeRow. + + Attributes: + test_postgres_type: models.TestPostgresType + test_inner_postgres_type: models.TestInnerPostgresType + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + test_postgres_type: models.TestPostgresType + test_inner_postgres_type: models.TestInnerPostgresType + + +class TestCopyFromParams(pydantic.BaseModel): + """Model representing TestCopyFromParams. + + Attributes: + id_: int + float_test: float + int_test: int + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + float_test: float + int_test: int + + +GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one +SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_inner_postgres_types +WHERE table_id = $1 LIMIT 1 +""" + +GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 +""" + +GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 +""" + +CREATE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresType :exec +INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec +INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec +DELETE +FROM test_inner_postgres_types +WHERE test_inner_postgres_types.table_id = $1 +""" + +CREATE_RESULT_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateResultOneTestPostgresType :execresult +INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + +CREATE_ROWS_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateRowsOneTestPostgresType :execrows +INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom +INSERT INTO test_copy_from (id, + float_test, int_test) +VALUES ($1, $2, $3) +""" + +INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec +INSERT INTO test_type_override ( + id, text_test +) VALUES ($1 ,$2) +""" + +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = $1 +""" + +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = $1 +""" + +INSERT_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: InsertOneTestEnumType :exec +INSERT INTO test_enum_types (id, mood, maybe_mood) +VALUES ($1, $2, $3) +""" + +GET_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: GetOneTestEnumType :one +SELECT id, mood, maybe_mood +FROM test_enum_types +WHERE id = $1 +""" + +GET_ONE_TEST_ENUM_VALUE: typing.Final[str] = """-- name: GetOneTestEnumValue :one +SELECT mood +FROM test_enum_types +WHERE id = $1 +""" + +GET_MANY_TEST_ENUM_TYPES: typing.Final[str] = """-- name: GetManyTestEnumTypes :many +SELECT id, mood, maybe_mood +FROM test_enum_types +ORDER BY id +""" + +DELETE_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: DeleteOneTestEnumType :execrows +DELETE +FROM test_enum_types +WHERE id = $1 +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: ConnectionLike, + sql: str, + decode_hook: collections.abc.Callable[[asyncpg.Record], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Args: + conn: + The connection object of type `ConnectionLike` used to execute queries. + sql: + The SQL statement that will be executed when fetching/iterating. + decode_hook: + A callback that turns an `asyncpg.Record` object into `T` that will be returned. + *args: + Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: asyncpg.cursor.CursorFactory[asyncpg.Record] | None = None + self._iterator: asyncpg.cursor.CursorIterator[asyncpg.Record] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns: + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await self._conn.fetch(self._sql, *self._args) + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an asyncpg cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopAsyncIteration: When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor = self._conn.cursor(self._sql, *self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +class Queries: + """Queries from file queries.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: ConnectionLike) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> ConnectionLike: + """Connection object used to make queries. + + Returns: + Connection object of type `ConnectionLike` used to make queries. + """ + return self._conn + + async def get_one_test_postgres_type(self, *, id_: int) -> models.TestPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Args: + id_: int. + + Returns: + Result of type `models.TestPostgresType` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + async def get_one_inner_test_postgres_type(self, *, table_id: int) -> models.TestInnerPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + + ```sql + SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_inner_postgres_types + WHERE table_id = $1 LIMIT 1 + ``` + + Args: + table_id: int. + + Returns: + Result of type `models.TestInnerPostgresType` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + if row is None: + return None + return models.TestInnerPostgresType( + table_id=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]) if row[16] is not None else None, + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]) if row[29] is not None else None, + cidr_test=str(row[30]) if row[30] is not None else None, + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + async def get_one_test_timestamp_postgres_type(self, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. + + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Args: + id_: int. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) + if row is None: + return None + return row[0] + + async def get_one_test_bytea_postgres_type(self, *, id_: int) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Args: + id_: int. + + Returns: + Result of type `memoryview` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) + if row is None: + return None + return memoryview(row[0]) + + def get_many_test_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestPostgresType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(self._conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + + def get_many_test_iterator_postgres_type(self, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestPostgresType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(self._conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) + + def get_many_test_timestamp_postgres_type(self, *, id_: int) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. + + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + + def get_many_test_bytea_postgres_type(self, *, id_: int) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> memoryview: + return memoryview(row[0]) + + return QueryResults(self._conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + + async def get_embedded_test_postgres_type(self, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Args: + id_: int. + + Returns: + Result of type `GetEmbeddedTestPostgresTypeRow` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetEmbeddedTestPostgresTypeRow( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + async def get_all_embedded_test_postgres_type(self, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Args: + id_: int. + + Returns: + Result of type `GetAllEmbeddedTestPostgresTypeRow` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetAllEmbeddedTestPostgresTypeRow( + test_postgres_type=models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ), + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + async def create_one_test_postgres_type( + self, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, + ) -> None: + """Execute SQL query with `name: CreateOneTestPostgresType :exec`. + + ```sql + INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Args: + id_: int. + serial_test: int. + serial4_test: int. + bigserial_test: int. + smallserial_test: int. + int_test: int. + bigint_test: int. + smallint_test: int. + float_test: float. + double_precision_test: float. + real_test: float. + numeric_test: decimal.Decimal. + money_test: str. + bool_test: bool. + json_test: str. + jsonb_test: str. + bytea_test: memoryview. + date_test: datetime.date. + time_test: datetime.time. + timetz_test: datetime.time. + timestamp_test: datetime.datetime. + timestamptz_test: datetime.datetime. + interval_test: datetime.timedelta. + text_test: str. + varchar_test: str. + bpchar_test: str. + char_test: str. + citext_test: str. + uuid_test: uuid.UUID. + inet_test: str. + cidr_test: str. + macaddr_test: str. + macaddr8_test: str. + ltree_test: str. + lquery_test: str. + ltxtquery_test: str. + """ + await self._conn.execute( + CREATE_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + async def create_one_test_postgres_inner_type( + self, + *, + table_id: int, + serial_test: int | None, + serial4_test: int | None, + bigserial_test: int | None, + smallserial_test: int | None, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + float_test: float | None, + double_precision_test: float | None, + real_test: float | None, + numeric_test: decimal.Decimal | None, + money_test: str | None, + bool_test: bool | None, + json_test: str | None, + jsonb_test: str | None, + bytea_test: memoryview | None, + date_test: datetime.date | None, + time_test: datetime.time | None, + timetz_test: datetime.time | None, + timestamp_test: datetime.datetime | None, + timestamptz_test: datetime.datetime | None, + interval_test: datetime.timedelta | None, + text_test: str | None, + varchar_test: str | None, + bpchar_test: str | None, + char_test: str | None, + citext_test: str | None, + uuid_test: uuid.UUID | None, + inet_test: str | None, + cidr_test: str | None, + macaddr_test: str | None, + macaddr8_test: str | None, + ltree_test: str | None, + lquery_test: str | None, + ltxtquery_test: str | None, + ) -> None: + """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. + + ```sql + INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Args: + table_id: int. + serial_test: int | None. + serial4_test: int | None. + bigserial_test: int | None. + smallserial_test: int | None. + int_test: int | None. + bigint_test: int | None. + smallint_test: int | None. + float_test: float | None. + double_precision_test: float | None. + real_test: float | None. + numeric_test: decimal.Decimal | None. + money_test: str | None. + bool_test: bool | None. + json_test: str | None. + jsonb_test: str | None. + bytea_test: memoryview | None. + date_test: datetime.date | None. + time_test: datetime.time | None. + timetz_test: datetime.time | None. + timestamp_test: datetime.datetime | None. + timestamptz_test: datetime.datetime | None. + interval_test: datetime.timedelta | None. + text_test: str | None. + varchar_test: str | None. + bpchar_test: str | None. + char_test: str | None. + citext_test: str | None. + uuid_test: uuid.UUID | None. + inet_test: str | None. + cidr_test: str | None. + macaddr_test: str | None. + macaddr8_test: str | None. + ltree_test: str | None. + lquery_test: str | None. + ltxtquery_test: str | None. + """ + await self._conn.execute( + CREATE_ONE_TEST_POSTGRES_INNER_TYPE, + table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + async def delete_one_test_postgres_type(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + + Args: + id_: int. + """ + await self._conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) + + async def delete_one_test_postgres_inner_type(self, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. + + ```sql + DELETE + FROM test_inner_postgres_types + WHERE test_inner_postgres_types.table_id = $1 + ``` + + Args: + table_id: int. + """ + await self._conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) + + async def create_result_one_test_postgres_type( + self, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, + ) -> str: + """Execute and return the result of SQL query with `name: CreateResultOneTestPostgresType :execresult`. + + ```sql + INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Args: + id_: int. + serial_test: int. + serial4_test: int. + bigserial_test: int. + smallserial_test: int. + int_test: int. + bigint_test: int. + smallint_test: int. + float_test: float. + double_precision_test: float. + real_test: float. + numeric_test: decimal.Decimal. + money_test: str. + bool_test: bool. + json_test: str. + jsonb_test: str. + bytea_test: memoryview. + date_test: datetime.date. + time_test: datetime.time. + timetz_test: datetime.time. + timestamp_test: datetime.datetime. + timestamptz_test: datetime.datetime. + interval_test: datetime.timedelta. + text_test: str. + varchar_test: str. + bpchar_test: str. + char_test: str. + citext_test: str. + uuid_test: uuid.UUID. + inet_test: str. + cidr_test: str. + macaddr_test: str. + macaddr8_test: str. + ltree_test: str. + lquery_test: str. + ltxtquery_test: str. + + Returns: + The result of type `str` returned when executing the query. + """ + return await self._conn.execute( + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + async def update_result_test_postgres_type(self, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. + + ```sql + UPDATE test_postgres_types + SET serial_test = 187 + WHERE test_postgres_types.id = $1 + ``` + + Args: + id_: int. + + Returns: + The result of type `str` returned when executing the query. + """ + return await self._conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) + + async def delete_one_result_test_postgres_type(self, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + + Args: + id_: int. + + Returns: + The result of type `str` returned when executing the query. + """ + return await self._conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) + + async def create_rows_one_test_postgres_type( + self, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, + ) -> int: + """Execute SQL query with `name: CreateRowsOneTestPostgresType :execrows` and return the number of affected rows. + + ```sql + INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Args: + id_: int. + serial_test: int. + serial4_test: int. + bigserial_test: int. + smallserial_test: int. + int_test: int. + bigint_test: int. + smallint_test: int. + float_test: float. + double_precision_test: float. + real_test: float. + numeric_test: decimal.Decimal. + money_test: str. + bool_test: bool. + json_test: str. + jsonb_test: str. + bytea_test: memoryview. + date_test: datetime.date. + time_test: datetime.time. + timetz_test: datetime.time. + timestamp_test: datetime.datetime. + timestamptz_test: datetime.datetime. + interval_test: datetime.timedelta. + text_test: str. + varchar_test: str. + bpchar_test: str. + char_test: str. + citext_test: str. + uuid_test: uuid.UUID. + inet_test: str. + cidr_test: str. + macaddr_test: str. + macaddr8_test: str. + ltree_test: str. + lquery_test: str. + ltxtquery_test: str. + + Returns: + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + """ + r = await self._conn.execute( + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + async def update_rows_test_postgres_type(self, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_postgres_types + SET serial_test = 187 + WHERE test_postgres_types.id = $1 + ``` + + Args: + id_: int. + + Returns: + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + """ + r = await self._conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + async def delete_one_rows_test_postgres_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + + Args: + id_: int. + + Returns: + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + """ + r = await self._conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + async def create_rows_table(self) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Returns: + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + """ + r = await self._conn.execute(CREATE_ROWS_TABLE) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + async def test_copy_from(self, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. + + Args: + params: collections.abc.Sequence[TestCopyFromParams]. + A list of params for rows that should be inserted. + + Returns: + The number (`int`) of affected rows. + """ + records = [(param.id_, param.float_test, param.int_test) for param in params] + r = await self._conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + async def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: + """Execute SQL query with `name: InsertTypeOverride :exec`. + + ```sql + INSERT INTO test_type_override ( + id, text_test + ) VALUES ($1 ,$2) + ``` + + Args: + id_: int. + text_test: UserString | None. + """ + await self._conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test) if text_test is not None else None) + + async def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + + ```sql + SELECT id, text_test FROM test_type_override WHERE id = $1 + ``` + + Args: + id_: int. + + Returns: + Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. + + ```sql + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + async def get_one_text_type_override(self, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + ``` + + Args: + id_: int. + + Returns: + Result of type `UserString` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[UserString | None]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + async def delete_type_override(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = $1 + ``` + + Args: + id_: int. + """ + await self._conn.execute(DELETE_TYPE_OVERRIDE, id_) + + async def insert_one_test_enum_type(self, *, id_: int, mood: enums.TestMood, maybe_mood: enums.TestMood | None) -> None: + """Execute SQL query with `name: InsertOneTestEnumType :exec`. + + ```sql + INSERT INTO test_enum_types (id, mood, maybe_mood) + VALUES ($1, $2, $3) + ``` + + Args: + id_: int. + mood: enums.TestMood. + maybe_mood: enums.TestMood | None. + """ + await self._conn.execute(INSERT_ONE_TEST_ENUM_TYPE, id_, mood, maybe_mood) + + async def get_one_test_enum_type(self, *, id_: int) -> models.TestEnumType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumType :one`. + + ```sql + SELECT id, mood, maybe_mood + FROM test_enum_types + WHERE id = $1 + ``` + + Args: + id_: int. + + Returns: + Result of type `models.TestEnumType` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TEST_ENUM_TYPE, id_) + if row is None: + return None + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) + + async def get_one_test_enum_value(self, *, id_: int) -> enums.TestMood | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumValue :one`. + + ```sql + SELECT mood + FROM test_enum_types + WHERE id = $1 + ``` + + Args: + id_: int. + + Returns: + Result of type `enums.TestMood` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ONE_TEST_ENUM_VALUE, id_) + if row is None: + return None + return enums.TestMood(row[0]) + + def get_many_test_enum_types(self) -> QueryResults[models.TestEnumType]: + """Fetch many from the db using the SQL query with `name: GetManyTestEnumTypes :many`. + + ```sql + SELECT id, mood, maybe_mood + FROM test_enum_types + ORDER BY id + ``` + + Returns: + Helper class of type `QueryResults[models.TestEnumType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestEnumType: + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) + + return QueryResults(self._conn, GET_MANY_TEST_ENUM_TYPES, _decode_hook) + + async def delete_one_test_enum_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneTestEnumType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_enum_types + WHERE id = $1 + ``` + + Args: + id_: int. + + Returns: + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + """ + r = await self._conn.execute(DELETE_ONE_TEST_ENUM_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 diff --git a/test/driver_asyncpg/pydantic/classes/queries_copy_override.py b/test/driver_asyncpg/pydantic/classes/queries_copy_override.py new file mode 100644 index 00000000..ec2e41f8 --- /dev/null +++ b/test/driver_asyncpg/pydantic/classes/queries_copy_override.py @@ -0,0 +1,113 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_copy_override.sql +"""Module containing queries from file queries_copy_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "CopyOverrideRowsParams", + "QueriesCopyOverride", +) + +import decimal +import pydantic +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import collections.abc + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + + +class CopyOverrideRowsParams(pydantic.BaseModel): + """Model representing CopyOverrideRowsParams. + + Attributes: + id_: int + amount: float + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + amount: float + + +COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CopyOverrideRows :copyfrom +INSERT INTO test_copy_override (id, amount) VALUES ($1, $2) +""" + +COUNT_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CountCopyOverrideRows :one +SELECT count(*) FROM test_copy_override +""" + +DELETE_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: DeleteCopyOverrideRows :exec +DELETE FROM test_copy_override +""" + + +class QueriesCopyOverride: + """Queries from file queries_copy_override.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: ConnectionLike) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> ConnectionLike: + """Connection object used to make queries. + + Returns: + Connection object of type `ConnectionLike` used to make queries. + """ + return self._conn + + async def copy_override_rows(self, *, params: collections.abc.Sequence[CopyOverrideRowsParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: CopyOverrideRows :copyfrom` and return the number of affected rows. + + Args: + params: collections.abc.Sequence[CopyOverrideRowsParams]. + A list of params for rows that should be inserted. + + Returns: + The number (`int`) of affected rows. + """ + records = [(param.id_, decimal.Decimal(param.amount)) for param in params] + r = await self._conn.copy_records_to_table("test_copy_override", columns=["id", "amount"], records=records) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + async def count_copy_override_rows(self) -> int | None: + """Fetch one from the db using the SQL query with `name: CountCopyOverrideRows :one`. + + ```sql + SELECT count(*) FROM test_copy_override + ``` + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(COUNT_COPY_OVERRIDE_ROWS) + if row is None: + return None + return row[0] + + async def delete_copy_override_rows(self) -> None: + """Execute SQL query with `name: DeleteCopyOverrideRows :exec`. + + ```sql + DELETE FROM test_copy_override + ``` + + """ + await self._conn.execute(DELETE_COPY_OVERRIDE_ROWS) diff --git a/test/driver_asyncpg/pydantic/classes/queries_enum_override.py b/test/driver_asyncpg/pydantic/classes/queries_enum_override.py new file mode 100644 index 00000000..53923de5 --- /dev/null +++ b/test/driver_asyncpg/pydantic/classes/queries_enum_override.py @@ -0,0 +1,211 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_enum_override.sql +"""Module containing queries from file queries_enum_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "QueriesEnumOverride", + "QueryResults", +) + +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import asyncpg.cursor + import collections.abc + + type QueryResultsArgsType = int | float | str | memoryview | collections.abc.Sequence[QueryResultsArgsType] | None + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + +from test.driver_asyncpg.pydantic.classes import enums +from test.driver_asyncpg.pydantic.classes import models + + +INSERT_ENUM_OVERRIDE: typing.Final[str] = """-- name: InsertEnumOverride :exec +INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) +""" + +GET_ENUM_OVERRIDE_MOOD: typing.Final[str] = """-- name: GetEnumOverrideMood :one +SELECT mood_test FROM test_enum_override WHERE id = $1 +""" + +LIST_ENUM_OVERRIDE_BY_IDS: typing.Final[str] = """-- name: ListEnumOverrideByIds :many +SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) +""" + +COUNT_ENUM_OVERRIDE_BY_MOODS: typing.Final[str] = """-- name: CountEnumOverrideByMoods :one +SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: ConnectionLike, + sql: str, + decode_hook: collections.abc.Callable[[asyncpg.Record], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Args: + conn: + The connection object of type `ConnectionLike` used to execute queries. + sql: + The SQL statement that will be executed when fetching/iterating. + decode_hook: + A callback that turns an `asyncpg.Record` object into `T` that will be returned. + *args: + Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: asyncpg.cursor.CursorFactory[asyncpg.Record] | None = None + self._iterator: asyncpg.cursor.CursorIterator[asyncpg.Record] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns: + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await self._conn.fetch(self._sql, *self._args) + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an asyncpg cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopAsyncIteration: When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor = self._conn.cursor(self._sql, *self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +class QueriesEnumOverride: + """Queries from file queries_enum_override.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: ConnectionLike) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> ConnectionLike: + """Connection object used to make queries. + + Returns: + Connection object of type `ConnectionLike` used to make queries. + """ + return self._conn + + async def insert_enum_override(self, *, id_: int, mood_test: str) -> None: + """Execute SQL query with `name: InsertEnumOverride :exec`. + + ```sql + INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) + ``` + + Args: + id_: int. + mood_test: str. + """ + await self._conn.execute(INSERT_ENUM_OVERRIDE, id_, enums.TestMood(mood_test)) + + async def get_enum_override_mood(self, *, id_: int) -> str | None: + """Fetch one from the db using the SQL query with `name: GetEnumOverrideMood :one`. + + ```sql + SELECT mood_test FROM test_enum_override WHERE id = $1 + ``` + + Args: + id_: int. + + Returns: + Result of type `str` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(GET_ENUM_OVERRIDE_MOOD, id_) + if row is None: + return None + return str(row[0]) + + def list_enum_override_by_ids(self, *, dollar_1: collections.abc.Sequence[int]) -> QueryResults[models.TestEnumOverride]: + """Fetch many from the db using the SQL query with `name: ListEnumOverrideByIds :many`. + + ```sql + SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) + ``` + + Args: + dollar_1: collections.abc.Sequence[int]. + + Returns: + Helper class of type `QueryResults[models.TestEnumOverride]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestEnumOverride: + return models.TestEnumOverride(id_=row[0], mood_test=str(row[1])) + + return QueryResults(self._conn, LIST_ENUM_OVERRIDE_BY_IDS, _decode_hook, dollar_1) + + async def count_enum_override_by_moods(self, *, dollar_1: collections.abc.Sequence[enums.TestMood]) -> int | None: + """Fetch one from the db using the SQL query with `name: CountEnumOverrideByMoods :one`. + + ```sql + SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) + ``` + + Args: + dollar_1: collections.abc.Sequence[enums.TestMood]. + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = await self._conn.fetchrow(COUNT_ENUM_OVERRIDE_BY_MOODS, dollar_1) + if row is None: + return None + return row[0] diff --git a/test/driver_asyncpg/pydantic/functions/__init__.py b/test/driver_asyncpg/pydantic/functions/__init__.py new file mode 100644 index 00000000..5c9110dc --- /dev/null +++ b/test/driver_asyncpg/pydantic/functions/__init__.py @@ -0,0 +1,5 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_asyncpg/pydantic/functions/enums.py b/test/driver_asyncpg/pydantic/functions/enums.py new file mode 100644 index 00000000..d49ac611 --- /dev/null +++ b/test/driver_asyncpg/pydantic/functions/enums.py @@ -0,0 +1,23 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing enums.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("TestMood",) + +import enum +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +class TestMood(enum.StrEnum): + """Enum representing TestMood.""" + + SAD = "sad" + OK = "ok" + HAPPY = "happy" diff --git a/test/driver_asyncpg/pydantic/functions/models.py b/test/driver_asyncpg/pydantic/functions/models.py new file mode 100644 index 00000000..687206d7 --- /dev/null +++ b/test/driver_asyncpg/pydantic/functions/models.py @@ -0,0 +1,235 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing models.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "TestEnumOverride", + "TestEnumType", + "TestInnerPostgresType", + "TestPostgresType", + "TestTypeOverride", +) + +from collections import UserString +import datetime +import decimal +import pydantic +import typing +import uuid + +if typing.TYPE_CHECKING: + import collections.abc + +from test.driver_asyncpg.pydantic.functions import enums + + +class TestEnumOverride(pydantic.BaseModel): + """Model representing TestEnumOverride. + + Attributes: + id_: int + mood_test: str + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + mood_test: str + + +class TestEnumType(pydantic.BaseModel): + """Model representing TestEnumType. + + Attributes: + id_: int + mood: enums.TestMood + maybe_mood: enums.TestMood | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + mood: enums.TestMood + maybe_mood: enums.TestMood | None + + +class TestInnerPostgresType(pydantic.BaseModel): + """Model representing TestInnerPostgresType. + + Attributes: + table_id: int + serial_test: int | None + serial4_test: int | None + bigserial_test: int | None + smallserial_test: int | None + int_test: int | None + bigint_test: int | None + smallint_test: int | None + float_test: float | None + double_precision_test: float | None + real_test: float | None + numeric_test: decimal.Decimal | None + money_test: str | None + bool_test: bool | None + json_test: str | None + jsonb_test: str | None + bytea_test: memoryview | None + date_test: datetime.date | None + time_test: datetime.time | None + timetz_test: datetime.time | None + timestamp_test: datetime.datetime | None + timestamptz_test: datetime.datetime | None + interval_test: datetime.timedelta | None + text_test: str | None + varchar_test: str | None + bpchar_test: str | None + char_test: str | None + citext_test: str | None + uuid_test: uuid.UUID | None + inet_test: str | None + cidr_test: str | None + macaddr_test: str | None + macaddr8_test: str | None + ltree_test: str | None + lquery_test: str | None + ltxtquery_test: str | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + table_id: int + serial_test: int | None + serial4_test: int | None + bigserial_test: int | None + smallserial_test: int | None + int_test: int | None + bigint_test: int | None + smallint_test: int | None + float_test: float | None + double_precision_test: float | None + real_test: float | None + numeric_test: decimal.Decimal | None + money_test: str | None + bool_test: bool | None + json_test: str | None + jsonb_test: str | None + bytea_test: memoryview | None + date_test: datetime.date | None + time_test: datetime.time | None + timetz_test: datetime.time | None + timestamp_test: datetime.datetime | None + timestamptz_test: datetime.datetime | None + interval_test: datetime.timedelta | None + text_test: str | None + varchar_test: str | None + bpchar_test: str | None + char_test: str | None + citext_test: str | None + uuid_test: uuid.UUID | None + inet_test: str | None + cidr_test: str | None + macaddr_test: str | None + macaddr8_test: str | None + ltree_test: str | None + lquery_test: str | None + ltxtquery_test: str | None + + +class TestPostgresType(pydantic.BaseModel): + """Model representing TestPostgresType. + + Attributes: + id_: int + serial_test: int + serial4_test: int + bigserial_test: int + smallserial_test: int + int_test: int + bigint_test: int + smallint_test: int + float_test: float + double_precision_test: float + real_test: float + numeric_test: decimal.Decimal + money_test: str + bool_test: bool + json_test: str + jsonb_test: str + bytea_test: memoryview + date_test: datetime.date + time_test: datetime.time + timetz_test: datetime.time + timestamp_test: datetime.datetime + timestamptz_test: datetime.datetime + interval_test: datetime.timedelta + text_test: str + varchar_test: str + bpchar_test: str + char_test: str + citext_test: str + uuid_test: uuid.UUID + inet_test: str + cidr_test: str + macaddr_test: str + macaddr8_test: str + ltree_test: str + lquery_test: str + ltxtquery_test: str + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + serial_test: int + serial4_test: int + bigserial_test: int + smallserial_test: int + int_test: int + bigint_test: int + smallint_test: int + float_test: float + double_precision_test: float + real_test: float + numeric_test: decimal.Decimal + money_test: str + bool_test: bool + json_test: str + jsonb_test: str + bytea_test: memoryview + date_test: datetime.date + time_test: datetime.time + timetz_test: datetime.time + timestamp_test: datetime.datetime + timestamptz_test: datetime.datetime + interval_test: datetime.timedelta + text_test: str + varchar_test: str + bpchar_test: str + char_test: str + citext_test: str + uuid_test: uuid.UUID + inet_test: str + cidr_test: str + macaddr_test: str + macaddr8_test: str + ltree_test: str + lquery_test: str + ltxtquery_test: str + + +class TestTypeOverride(pydantic.BaseModel): + """Model representing TestTypeOverride. + + Attributes: + id_: int + text_test: UserString | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + text_test: UserString | None diff --git a/test/driver_asyncpg/pydantic/functions/queries.py b/test/driver_asyncpg/pydantic/functions/queries.py new file mode 100644 index 00000000..48a813bb --- /dev/null +++ b/test/driver_asyncpg/pydantic/functions/queries.py @@ -0,0 +1,2194 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql +"""Module containing queries from file queries.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "GetAllEmbeddedTestPostgresTypeRow", + "GetEmbeddedTestPostgresTypeRow", + "QueryResults", + "TestCopyFromParams", + "create_one_test_postgres_inner_type", + "create_one_test_postgres_type", + "create_result_one_test_postgres_type", + "create_rows_one_test_postgres_type", + "create_rows_table", + "delete_one_result_test_postgres_type", + "delete_one_rows_test_postgres_type", + "delete_one_test_enum_type", + "delete_one_test_postgres_inner_type", + "delete_one_test_postgres_type", + "delete_type_override", + "get_all_embedded_test_postgres_type", + "get_embedded_test_postgres_type", + "get_many_test_bytea_postgres_type", + "get_many_test_enum_types", + "get_many_test_iterator_postgres_type", + "get_many_test_postgres_type", + "get_many_test_timestamp_postgres_type", + "get_many_text_type_override", + "get_many_type_override", + "get_one_inner_test_postgres_type", + "get_one_test_bytea_postgres_type", + "get_one_test_enum_type", + "get_one_test_enum_value", + "get_one_test_postgres_type", + "get_one_test_timestamp_postgres_type", + "get_one_text_type_override", + "get_one_type_override", + "insert_one_test_enum_type", + "insert_type_override", + "test_copy_from", + "update_result_test_postgres_type", + "update_rows_test_postgres_type", +) + +from collections import UserString +import datetime +import decimal +import operator +import pydantic +import typing +import uuid + +if typing.TYPE_CHECKING: + import asyncpg + import asyncpg.cursor + import collections.abc + + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | uuid.UUID | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + +from test.driver_asyncpg.pydantic.functions import enums +from test.driver_asyncpg.pydantic.functions import models + + +class GetEmbeddedTestPostgresTypeRow(pydantic.BaseModel): + """Model representing GetEmbeddedTestPostgresTypeRow. + + Attributes: + id_: int + serial_test: int + serial4_test: int + bigserial_test: int + smallserial_test: int + int_test: int + bigint_test: int + smallint_test: int + float_test: float + double_precision_test: float + real_test: float + numeric_test: decimal.Decimal + money_test: str + bool_test: bool + json_test: str + jsonb_test: str + bytea_test: memoryview + date_test: datetime.date + time_test: datetime.time + timetz_test: datetime.time + timestamp_test: datetime.datetime + timestamptz_test: datetime.datetime + interval_test: datetime.timedelta + text_test: str + varchar_test: str + bpchar_test: str + char_test: str + citext_test: str + uuid_test: uuid.UUID + inet_test: str + cidr_test: str + macaddr_test: str + macaddr8_test: str + ltree_test: str + lquery_test: str + ltxtquery_test: str + test_inner_postgres_type: models.TestInnerPostgresType + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + serial_test: int + serial4_test: int + bigserial_test: int + smallserial_test: int + int_test: int + bigint_test: int + smallint_test: int + float_test: float + double_precision_test: float + real_test: float + numeric_test: decimal.Decimal + money_test: str + bool_test: bool + json_test: str + jsonb_test: str + bytea_test: memoryview + date_test: datetime.date + time_test: datetime.time + timetz_test: datetime.time + timestamp_test: datetime.datetime + timestamptz_test: datetime.datetime + interval_test: datetime.timedelta + text_test: str + varchar_test: str + bpchar_test: str + char_test: str + citext_test: str + uuid_test: uuid.UUID + inet_test: str + cidr_test: str + macaddr_test: str + macaddr8_test: str + ltree_test: str + lquery_test: str + ltxtquery_test: str + test_inner_postgres_type: models.TestInnerPostgresType + + +class GetAllEmbeddedTestPostgresTypeRow(pydantic.BaseModel): + """Model representing GetAllEmbeddedTestPostgresTypeRow. + + Attributes: + test_postgres_type: models.TestPostgresType + test_inner_postgres_type: models.TestInnerPostgresType + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + test_postgres_type: models.TestPostgresType + test_inner_postgres_type: models.TestInnerPostgresType + + +class TestCopyFromParams(pydantic.BaseModel): + """Model representing TestCopyFromParams. + + Attributes: + id_: int + float_test: float + int_test: int + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + float_test: float + int_test: int + + +GET_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestPostgresType :one +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_INNER_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneInnerTestPostgresType :one +SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_inner_postgres_types +WHERE table_id = $1 LIMIT 1 +""" + +GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestTimestampPostgresType :one +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_ONE_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetOneTestByteaPostgresType :one +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 1 +""" + +GET_MANY_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_ITERATOR_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestIteratorPostgresType :many +SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test +FROM test_postgres_types +WHERE id = $1 +""" + +GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestTimestampPostgresType :many +SELECT timestamp_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_MANY_TEST_BYTEA_POSTGRES_TYPE: typing.Final[str] = """-- name: GetManyTestByteaPostgresType :many +SELECT bytea_test +FROM test_postgres_types +WHERE id = $1 LIMIT 2 +""" + +GET_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 +""" + +GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: GetAllEmbeddedTestPostgresType :one +SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test +FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id +WHERE test_postgres_types.id = $1 +""" + +CREATE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresType :exec +INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +CREATE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: CreateOneTestPostgresInnerType :exec +INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +DELETE_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresType :exec +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_TEST_POSTGRES_INNER_TYPE: typing.Final[str] = """-- name: DeleteOneTestPostgresInnerType :exec +DELETE +FROM test_inner_postgres_types +WHERE test_inner_postgres_types.table_id = $1 +""" + +CREATE_RESULT_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateResultOneTestPostgresType :execresult +INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +UPDATE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateResultTestPostgresType :execresult +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_RESULT_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneResultTestPostgresType :execresult +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + +CREATE_ROWS_ONE_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: CreateRowsOneTestPostgresType :execrows +INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) +""" + +UPDATE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: UpdateRowsTestPostgresType :execrows +UPDATE test_postgres_types +SET serial_test = 187 +WHERE test_postgres_types.id = $1 +""" + +DELETE_ONE_ROWS_TEST_POSTGRES_TYPE: typing.Final[str] = """-- name: DeleteOneRowsTestPostgresType :execrows +DELETE +FROM test_postgres_types +WHERE test_postgres_types.id = $1 +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +TEST_COPY_FROM: typing.Final[str] = """-- name: TestCopyFrom :copyfrom +INSERT INTO test_copy_from (id, + float_test, int_test) +VALUES ($1, $2, $3) +""" + +INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec +INSERT INTO test_type_override ( + id, text_test +) VALUES ($1 ,$2) +""" + +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = $1 +""" + +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 +""" + +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = $1 +""" + +INSERT_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: InsertOneTestEnumType :exec +INSERT INTO test_enum_types (id, mood, maybe_mood) +VALUES ($1, $2, $3) +""" + +GET_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: GetOneTestEnumType :one +SELECT id, mood, maybe_mood +FROM test_enum_types +WHERE id = $1 +""" + +GET_ONE_TEST_ENUM_VALUE: typing.Final[str] = """-- name: GetOneTestEnumValue :one +SELECT mood +FROM test_enum_types +WHERE id = $1 +""" + +GET_MANY_TEST_ENUM_TYPES: typing.Final[str] = """-- name: GetManyTestEnumTypes :many +SELECT id, mood, maybe_mood +FROM test_enum_types +ORDER BY id +""" + +DELETE_ONE_TEST_ENUM_TYPE: typing.Final[str] = """-- name: DeleteOneTestEnumType :execrows +DELETE +FROM test_enum_types +WHERE id = $1 +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: ConnectionLike, + sql: str, + decode_hook: collections.abc.Callable[[asyncpg.Record], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Args: + conn: + The connection object of type `ConnectionLike` used to execute queries. + sql: + The SQL statement that will be executed when fetching/iterating. + decode_hook: + A callback that turns an `asyncpg.Record` object into `T` that will be returned. + *args: + Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: asyncpg.cursor.CursorFactory[asyncpg.Record] | None = None + self._iterator: asyncpg.cursor.CursorIterator[asyncpg.Record] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns: + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await self._conn.fetch(self._sql, *self._args) + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an asyncpg cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopAsyncIteration: When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor = self._conn.cursor(self._sql, *self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +async def get_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> models.TestPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestPostgresType :one`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `models.TestPostgresType` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + +async def get_one_inner_test_postgres_type(conn: ConnectionLike, *, table_id: int) -> models.TestInnerPostgresType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerTestPostgresType :one`. + + ```sql + SELECT table_id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_inner_postgres_types + WHERE table_id = $1 LIMIT 1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + table_id: int. + + Returns: + Result of type `models.TestInnerPostgresType` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_INNER_TEST_POSTGRES_TYPE, table_id) + if row is None: + return None + return models.TestInnerPostgresType( + table_id=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]) if row[16] is not None else None, + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]) if row[29] is not None else None, + cidr_test=str(row[30]) if row[30] is not None else None, + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + +async def get_one_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTestTimestampPostgresType :one`. + + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TEST_TIMESTAMP_POSTGRES_TYPE, id_) + if row is None: + return None + return row[0] + + +async def get_one_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneTestByteaPostgresType :one`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `memoryview` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TEST_BYTEA_POSTGRES_TYPE, id_) + if row is None: + return None + return memoryview(row[0]) + + +def get_many_test_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestPostgresType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(conn, GET_MANY_TEST_POSTGRES_TYPE, _decode_hook, id_) + + +def get_many_test_iterator_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestPostgresType]: + """Fetch many from the db using the SQL query with `name: GetManyTestIteratorPostgresType :many`. + + ```sql + SELECT id, serial_test, serial4_test, bigserial_test, smallserial_test, int_test, bigint_test, smallint_test, float_test, double_precision_test, real_test, numeric_test, money_test, bool_test, json_test, jsonb_test, bytea_test, date_test, time_test, timetz_test, timestamp_test, timestamptz_test, interval_test, text_test, varchar_test, bpchar_test, char_test, citext_test, uuid_test, inet_test, cidr_test, macaddr_test, macaddr8_test, ltree_test, lquery_test, ltxtquery_test + FROM test_postgres_types + WHERE id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestPostgresType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestPostgresType: + return models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ) + + return QueryResults(conn, GET_MANY_TEST_ITERATOR_POSTGRES_TYPE, _decode_hook, id_) + + +def get_many_test_timestamp_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTestTimestampPostgresType :many`. + + ```sql + SELECT timestamp_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_TEST_TIMESTAMP_POSTGRES_TYPE, operator.itemgetter(0), id_) + + +def get_many_test_bytea_postgres_type(conn: ConnectionLike, *, id_: int) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyTestByteaPostgresType :many`. + + ```sql + SELECT bytea_test + FROM test_postgres_types + WHERE id = $1 LIMIT 2 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> memoryview: + return memoryview(row[0]) + + return QueryResults(conn, GET_MANY_TEST_BYTEA_POSTGRES_TYPE, _decode_hook, id_) + + +async def get_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `GetEmbeddedTestPostgresTypeRow` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetEmbeddedTestPostgresTypeRow( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + +async def get_all_embedded_test_postgres_type(conn: ConnectionLike, *, id_: int) -> GetAllEmbeddedTestPostgresTypeRow | None: + """Fetch one from the db using the SQL query with `name: GetAllEmbeddedTestPostgresType :one`. + + ```sql + SELECT test_postgres_types.id, test_postgres_types.serial_test, test_postgres_types.serial4_test, test_postgres_types.bigserial_test, test_postgres_types.smallserial_test, test_postgres_types.int_test, test_postgres_types.bigint_test, test_postgres_types.smallint_test, test_postgres_types.float_test, test_postgres_types.double_precision_test, test_postgres_types.real_test, test_postgres_types.numeric_test, test_postgres_types.money_test, test_postgres_types.bool_test, test_postgres_types.json_test, test_postgres_types.jsonb_test, test_postgres_types.bytea_test, test_postgres_types.date_test, test_postgres_types.time_test, test_postgres_types.timetz_test, test_postgres_types.timestamp_test, test_postgres_types.timestamptz_test, test_postgres_types.interval_test, test_postgres_types.text_test, test_postgres_types.varchar_test, test_postgres_types.bpchar_test, test_postgres_types.char_test, test_postgres_types.citext_test, test_postgres_types.uuid_test, test_postgres_types.inet_test, test_postgres_types.cidr_test, test_postgres_types.macaddr_test, test_postgres_types.macaddr8_test, test_postgres_types.ltree_test, test_postgres_types.lquery_test, test_postgres_types.ltxtquery_test, test_inner_postgres_types.table_id, test_inner_postgres_types.serial_test, test_inner_postgres_types.serial4_test, test_inner_postgres_types.bigserial_test, test_inner_postgres_types.smallserial_test, test_inner_postgres_types.int_test, test_inner_postgres_types.bigint_test, test_inner_postgres_types.smallint_test, test_inner_postgres_types.float_test, test_inner_postgres_types.double_precision_test, test_inner_postgres_types.real_test, test_inner_postgres_types.numeric_test, test_inner_postgres_types.money_test, test_inner_postgres_types.bool_test, test_inner_postgres_types.json_test, test_inner_postgres_types.jsonb_test, test_inner_postgres_types.bytea_test, test_inner_postgres_types.date_test, test_inner_postgres_types.time_test, test_inner_postgres_types.timetz_test, test_inner_postgres_types.timestamp_test, test_inner_postgres_types.timestamptz_test, test_inner_postgres_types.interval_test, test_inner_postgres_types.text_test, test_inner_postgres_types.varchar_test, test_inner_postgres_types.bpchar_test, test_inner_postgres_types.char_test, test_inner_postgres_types.citext_test, test_inner_postgres_types.uuid_test, test_inner_postgres_types.inet_test, test_inner_postgres_types.cidr_test, test_inner_postgres_types.macaddr_test, test_inner_postgres_types.macaddr8_test, test_inner_postgres_types.ltree_test, test_inner_postgres_types.lquery_test, test_inner_postgres_types.ltxtquery_test + FROM test_postgres_types + JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id + WHERE test_postgres_types.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `GetAllEmbeddedTestPostgresTypeRow` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ALL_EMBEDDED_TEST_POSTGRES_TYPE, id_) + if row is None: + return None + return GetAllEmbeddedTestPostgresTypeRow( + test_postgres_type=models.TestPostgresType( + id_=row[0], + serial_test=row[1], + serial4_test=row[2], + bigserial_test=row[3], + smallserial_test=row[4], + int_test=row[5], + bigint_test=row[6], + smallint_test=row[7], + float_test=row[8], + double_precision_test=row[9], + real_test=row[10], + numeric_test=row[11], + money_test=row[12], + bool_test=row[13], + json_test=row[14], + jsonb_test=row[15], + bytea_test=memoryview(row[16]), + date_test=row[17], + time_test=row[18], + timetz_test=row[19], + timestamp_test=row[20], + timestamptz_test=row[21], + interval_test=row[22], + text_test=row[23], + varchar_test=row[24], + bpchar_test=row[25], + char_test=row[26], + citext_test=row[27], + uuid_test=row[28], + inet_test=str(row[29]), + cidr_test=str(row[30]), + macaddr_test=row[31], + macaddr8_test=row[32], + ltree_test=row[33], + lquery_test=row[34], + ltxtquery_test=row[35], + ), + test_inner_postgres_type=models.TestInnerPostgresType( + table_id=row[36], + serial_test=row[37], + serial4_test=row[38], + bigserial_test=row[39], + smallserial_test=row[40], + int_test=row[41], + bigint_test=row[42], + smallint_test=row[43], + float_test=row[44], + double_precision_test=row[45], + real_test=row[46], + numeric_test=row[47], + money_test=row[48], + bool_test=row[49], + json_test=row[50], + jsonb_test=row[51], + bytea_test=memoryview(row[52]) if row[52] is not None else None, + date_test=row[53], + time_test=row[54], + timetz_test=row[55], + timestamp_test=row[56], + timestamptz_test=row[57], + interval_test=row[58], + text_test=row[59], + varchar_test=row[60], + bpchar_test=row[61], + char_test=row[62], + citext_test=row[63], + uuid_test=row[64], + inet_test=str(row[65]) if row[65] is not None else None, + cidr_test=str(row[66]) if row[66] is not None else None, + macaddr_test=row[67], + macaddr8_test=row[68], + ltree_test=row[69], + lquery_test=row[70], + ltxtquery_test=row[71], + ), + ) + + +async def create_one_test_postgres_type( + conn: ConnectionLike, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, +) -> None: + """Execute SQL query with `name: CreateOneTestPostgresType :exec`. + + ```sql + INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + serial_test: int. + serial4_test: int. + bigserial_test: int. + smallserial_test: int. + int_test: int. + bigint_test: int. + smallint_test: int. + float_test: float. + double_precision_test: float. + real_test: float. + numeric_test: decimal.Decimal. + money_test: str. + bool_test: bool. + json_test: str. + jsonb_test: str. + bytea_test: memoryview. + date_test: datetime.date. + time_test: datetime.time. + timetz_test: datetime.time. + timestamp_test: datetime.datetime. + timestamptz_test: datetime.datetime. + interval_test: datetime.timedelta. + text_test: str. + varchar_test: str. + bpchar_test: str. + char_test: str. + citext_test: str. + uuid_test: uuid.UUID. + inet_test: str. + cidr_test: str. + macaddr_test: str. + macaddr8_test: str. + ltree_test: str. + lquery_test: str. + ltxtquery_test: str. + """ + await conn.execute( + CREATE_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + +async def create_one_test_postgres_inner_type( + conn: ConnectionLike, + *, + table_id: int, + serial_test: int | None, + serial4_test: int | None, + bigserial_test: int | None, + smallserial_test: int | None, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + float_test: float | None, + double_precision_test: float | None, + real_test: float | None, + numeric_test: decimal.Decimal | None, + money_test: str | None, + bool_test: bool | None, + json_test: str | None, + jsonb_test: str | None, + bytea_test: memoryview | None, + date_test: datetime.date | None, + time_test: datetime.time | None, + timetz_test: datetime.time | None, + timestamp_test: datetime.datetime | None, + timestamptz_test: datetime.datetime | None, + interval_test: datetime.timedelta | None, + text_test: str | None, + varchar_test: str | None, + bpchar_test: str | None, + char_test: str | None, + citext_test: str | None, + uuid_test: uuid.UUID | None, + inet_test: str | None, + cidr_test: str | None, + macaddr_test: str | None, + macaddr8_test: str | None, + ltree_test: str | None, + lquery_test: str | None, + ltxtquery_test: str | None, +) -> None: + """Execute SQL query with `name: CreateOneTestPostgresInnerType :exec`. + + ```sql + INSERT INTO test_inner_postgres_types (table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + table_id: int. + serial_test: int | None. + serial4_test: int | None. + bigserial_test: int | None. + smallserial_test: int | None. + int_test: int | None. + bigint_test: int | None. + smallint_test: int | None. + float_test: float | None. + double_precision_test: float | None. + real_test: float | None. + numeric_test: decimal.Decimal | None. + money_test: str | None. + bool_test: bool | None. + json_test: str | None. + jsonb_test: str | None. + bytea_test: memoryview | None. + date_test: datetime.date | None. + time_test: datetime.time | None. + timetz_test: datetime.time | None. + timestamp_test: datetime.datetime | None. + timestamptz_test: datetime.datetime | None. + interval_test: datetime.timedelta | None. + text_test: str | None. + varchar_test: str | None. + bpchar_test: str | None. + char_test: str | None. + citext_test: str | None. + uuid_test: uuid.UUID | None. + inet_test: str | None. + cidr_test: str | None. + macaddr_test: str | None. + macaddr8_test: str | None. + ltree_test: str | None. + lquery_test: str | None. + ltxtquery_test: str | None. + """ + await conn.execute( + CREATE_ONE_TEST_POSTGRES_INNER_TYPE, + table_id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + +async def delete_one_test_postgres_type(conn: ConnectionLike, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresType :exec`. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + """ + await conn.execute(DELETE_ONE_TEST_POSTGRES_TYPE, id_) + + +async def delete_one_test_postgres_inner_type(conn: ConnectionLike, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestPostgresInnerType :exec`. + + ```sql + DELETE + FROM test_inner_postgres_types + WHERE test_inner_postgres_types.table_id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + table_id: int. + """ + await conn.execute(DELETE_ONE_TEST_POSTGRES_INNER_TYPE, table_id) + + +async def create_result_one_test_postgres_type( + conn: ConnectionLike, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, +) -> str: + """Execute and return the result of SQL query with `name: CreateResultOneTestPostgresType :execresult`. + + ```sql + INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + serial_test: int. + serial4_test: int. + bigserial_test: int. + smallserial_test: int. + int_test: int. + bigint_test: int. + smallint_test: int. + float_test: float. + double_precision_test: float. + real_test: float. + numeric_test: decimal.Decimal. + money_test: str. + bool_test: bool. + json_test: str. + jsonb_test: str. + bytea_test: memoryview. + date_test: datetime.date. + time_test: datetime.time. + timetz_test: datetime.time. + timestamp_test: datetime.datetime. + timestamptz_test: datetime.datetime. + interval_test: datetime.timedelta. + text_test: str. + varchar_test: str. + bpchar_test: str. + char_test: str. + citext_test: str. + uuid_test: uuid.UUID. + inet_test: str. + cidr_test: str. + macaddr_test: str. + macaddr8_test: str. + ltree_test: str. + lquery_test: str. + ltxtquery_test: str. + + Returns: + The result of type `str` returned when executing the query. + """ + return await conn.execute( + CREATE_RESULT_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + + +async def update_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: UpdateResultTestPostgresType :execresult`. + + ```sql + UPDATE test_postgres_types + SET serial_test = 187 + WHERE test_postgres_types.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + The result of type `str` returned when executing the query. + """ + return await conn.execute(UPDATE_RESULT_TEST_POSTGRES_TYPE, id_) + + +async def delete_one_result_test_postgres_type(conn: ConnectionLike, *, id_: int) -> str: + """Execute and return the result of SQL query with `name: DeleteOneResultTestPostgresType :execresult`. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + The result of type `str` returned when executing the query. + """ + return await conn.execute(DELETE_ONE_RESULT_TEST_POSTGRES_TYPE, id_) + + +async def create_rows_one_test_postgres_type( + conn: ConnectionLike, + *, + id_: int, + serial_test: int, + serial4_test: int, + bigserial_test: int, + smallserial_test: int, + int_test: int, + bigint_test: int, + smallint_test: int, + float_test: float, + double_precision_test: float, + real_test: float, + numeric_test: decimal.Decimal, + money_test: str, + bool_test: bool, + json_test: str, + jsonb_test: str, + bytea_test: memoryview, + date_test: datetime.date, + time_test: datetime.time, + timetz_test: datetime.time, + timestamp_test: datetime.datetime, + timestamptz_test: datetime.datetime, + interval_test: datetime.timedelta, + text_test: str, + varchar_test: str, + bpchar_test: str, + char_test: str, + citext_test: str, + uuid_test: uuid.UUID, + inet_test: str, + cidr_test: str, + macaddr_test: str, + macaddr8_test: str, + ltree_test: str, + lquery_test: str, + ltxtquery_test: str, +) -> int: + """Execute SQL query with `name: CreateRowsOneTestPostgresType :execrows` and return the number of affected rows. + + ```sql + INSERT INTO test_postgres_types (id, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, + $9, $10, $11, $12, $13, $14, $15, $16, + $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27, $28, $29, $30, $31, $32, + $33, $34, $35, $36) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + serial_test: int. + serial4_test: int. + bigserial_test: int. + smallserial_test: int. + int_test: int. + bigint_test: int. + smallint_test: int. + float_test: float. + double_precision_test: float. + real_test: float. + numeric_test: decimal.Decimal. + money_test: str. + bool_test: bool. + json_test: str. + jsonb_test: str. + bytea_test: memoryview. + date_test: datetime.date. + time_test: datetime.time. + timetz_test: datetime.time. + timestamp_test: datetime.datetime. + timestamptz_test: datetime.datetime. + interval_test: datetime.timedelta. + text_test: str. + varchar_test: str. + bpchar_test: str. + char_test: str. + citext_test: str. + uuid_test: uuid.UUID. + inet_test: str. + cidr_test: str. + macaddr_test: str. + macaddr8_test: str. + ltree_test: str. + lquery_test: str. + ltxtquery_test: str. + + Returns: + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + """ + r = await conn.execute( + CREATE_ROWS_ONE_TEST_POSTGRES_TYPE, + id_, + serial_test, + serial4_test, + bigserial_test, + smallserial_test, + int_test, + bigint_test, + smallint_test, + float_test, + double_precision_test, + real_test, + numeric_test, + money_test, + bool_test, + json_test, + jsonb_test, + bytea_test, + date_test, + time_test, + timetz_test, + timestamp_test, + timestamptz_test, + interval_test, + text_test, + varchar_test, + bpchar_test, + char_test, + citext_test, + uuid_test, + inet_test, + cidr_test, + macaddr_test, + macaddr8_test, + ltree_test, + lquery_test, + ltxtquery_test, + ) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + +async def update_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsTestPostgresType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_postgres_types + SET serial_test = 187 + WHERE test_postgres_types.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + """ + r = await conn.execute(UPDATE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + +async def delete_one_rows_test_postgres_type(conn: ConnectionLike, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneRowsTestPostgresType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_postgres_types + WHERE test_postgres_types.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + """ + r = await conn.execute(DELETE_ONE_ROWS_TEST_POSTGRES_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + +async def create_rows_table(conn: ConnectionLike) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + + Returns: + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + """ + r = await conn.execute(CREATE_ROWS_TABLE) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + +async def test_copy_from(conn: ConnectionLike, *, params: collections.abc.Sequence[TestCopyFromParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: TestCopyFrom :copyfrom` and return the number of affected rows. + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + params: collections.abc.Sequence[TestCopyFromParams]. + A list of params for rows that should be inserted. + + Returns: + The number (`int`) of affected rows. + """ + records = [(param.id_, param.float_test, param.int_test) for param in params] + r = await conn.copy_records_to_table("test_copy_from", columns=["id", "float_test", "int_test"], records=records) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + +async def insert_type_override(conn: ConnectionLike, *, id_: int, text_test: UserString | None) -> None: + """Execute SQL query with `name: InsertTypeOverride :exec`. + + ```sql + INSERT INTO test_type_override ( + id, text_test + ) VALUES ($1 ,$2) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + text_test: UserString | None. + """ + await conn.execute(INSERT_TYPE_OVERRIDE, id_, str(text_test) if text_test is not None else None) + + +async def get_one_type_override(conn: ConnectionLike, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + + ```sql + SELECT id, text_test FROM test_type_override WHERE id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TYPE_OVERRIDE, id_) + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + +def get_many_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. + + ```sql + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + +async def get_one_text_type_override(conn: ConnectionLike, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `UserString` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TEXT_TYPE_OVERRIDE, id_) + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + +def get_many_text_type_override(conn: ConnectionLike, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[UserString | None]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + +async def delete_type_override(conn: ConnectionLike, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + """ + await conn.execute(DELETE_TYPE_OVERRIDE, id_) + + +async def insert_one_test_enum_type(conn: ConnectionLike, *, id_: int, mood: enums.TestMood, maybe_mood: enums.TestMood | None) -> None: + """Execute SQL query with `name: InsertOneTestEnumType :exec`. + + ```sql + INSERT INTO test_enum_types (id, mood, maybe_mood) + VALUES ($1, $2, $3) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + mood: enums.TestMood. + maybe_mood: enums.TestMood | None. + """ + await conn.execute(INSERT_ONE_TEST_ENUM_TYPE, id_, mood, maybe_mood) + + +async def get_one_test_enum_type(conn: ConnectionLike, *, id_: int) -> models.TestEnumType | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumType :one`. + + ```sql + SELECT id, mood, maybe_mood + FROM test_enum_types + WHERE id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `models.TestEnumType` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TEST_ENUM_TYPE, id_) + if row is None: + return None + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) + + +async def get_one_test_enum_value(conn: ConnectionLike, *, id_: int) -> enums.TestMood | None: + """Fetch one from the db using the SQL query with `name: GetOneTestEnumValue :one`. + + ```sql + SELECT mood + FROM test_enum_types + WHERE id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `enums.TestMood` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ONE_TEST_ENUM_VALUE, id_) + if row is None: + return None + return enums.TestMood(row[0]) + + +def get_many_test_enum_types(conn: ConnectionLike) -> QueryResults[models.TestEnumType]: + """Fetch many from the db using the SQL query with `name: GetManyTestEnumTypes :many`. + + ```sql + SELECT id, mood, maybe_mood + FROM test_enum_types + ORDER BY id + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + + Returns: + Helper class of type `QueryResults[models.TestEnumType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestEnumType: + return models.TestEnumType(id_=row[0], mood=enums.TestMood(row[1]), maybe_mood=enums.TestMood(row[2]) if row[2] is not None else None) + + return QueryResults(conn, GET_MANY_TEST_ENUM_TYPES, _decode_hook) + + +async def delete_one_test_enum_type(conn: ConnectionLike, *, id_: int) -> int: + """Execute SQL query with `name: DeleteOneTestEnumType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_enum_types + WHERE id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + """ + r = await conn.execute(DELETE_ONE_TEST_ENUM_TYPE, id_) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 diff --git a/test/driver_asyncpg/pydantic/functions/queries_copy_override.py b/test/driver_asyncpg/pydantic/functions/queries_copy_override.py new file mode 100644 index 00000000..23ae65f0 --- /dev/null +++ b/test/driver_asyncpg/pydantic/functions/queries_copy_override.py @@ -0,0 +1,103 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_copy_override.sql +"""Module containing queries from file queries_copy_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "CopyOverrideRowsParams", + "copy_override_rows", + "count_copy_override_rows", + "delete_copy_override_rows", +) + +import decimal +import pydantic +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import collections.abc + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + + +class CopyOverrideRowsParams(pydantic.BaseModel): + """Model representing CopyOverrideRowsParams. + + Attributes: + id_: int + amount: float + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + amount: float + + +COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CopyOverrideRows :copyfrom +INSERT INTO test_copy_override (id, amount) VALUES ($1, $2) +""" + +COUNT_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: CountCopyOverrideRows :one +SELECT count(*) FROM test_copy_override +""" + +DELETE_COPY_OVERRIDE_ROWS: typing.Final[str] = """-- name: DeleteCopyOverrideRows :exec +DELETE FROM test_copy_override +""" + + +async def copy_override_rows(conn: ConnectionLike, *, params: collections.abc.Sequence[CopyOverrideRowsParams]) -> int: + """Execute COPY FROM query to insert rows into a table with `name: CopyOverrideRows :copyfrom` and return the number of affected rows. + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + params: collections.abc.Sequence[CopyOverrideRowsParams]. + A list of params for rows that should be inserted. + + Returns: + The number (`int`) of affected rows. + """ + records = [(param.id_, decimal.Decimal(param.amount)) for param in params] + r = await conn.copy_records_to_table("test_copy_override", columns=["id", "amount"], records=records) + return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0 + + +async def count_copy_override_rows(conn: ConnectionLike) -> int | None: + """Fetch one from the db using the SQL query with `name: CountCopyOverrideRows :one`. + + ```sql + SELECT count(*) FROM test_copy_override + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(COUNT_COPY_OVERRIDE_ROWS) + if row is None: + return None + return row[0] + + +async def delete_copy_override_rows(conn: ConnectionLike) -> None: + """Execute SQL query with `name: DeleteCopyOverrideRows :exec`. + + ```sql + DELETE FROM test_copy_override + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + """ + await conn.execute(DELETE_COPY_OVERRIDE_ROWS) diff --git a/test/driver_asyncpg/pydantic/functions/queries_enum_override.py b/test/driver_asyncpg/pydantic/functions/queries_enum_override.py new file mode 100644 index 00000000..b2c241b0 --- /dev/null +++ b/test/driver_asyncpg/pydantic/functions/queries_enum_override.py @@ -0,0 +1,202 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_enum_override.sql +"""Module containing queries from file queries_enum_override.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "QueryResults", + "count_enum_override_by_moods", + "get_enum_override_mood", + "insert_enum_override", + "list_enum_override_by_ids", +) + +import typing + +if typing.TYPE_CHECKING: + import asyncpg + import asyncpg.cursor + import collections.abc + + type QueryResultsArgsType = int | float | str | memoryview | collections.abc.Sequence[QueryResultsArgsType] | None + + type ConnectionLike = asyncpg.Connection[asyncpg.Record] | asyncpg.pool.PoolConnectionProxy[asyncpg.Record] + +from test.driver_asyncpg.pydantic.functions import enums +from test.driver_asyncpg.pydantic.functions import models + + +INSERT_ENUM_OVERRIDE: typing.Final[str] = """-- name: InsertEnumOverride :exec +INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) +""" + +GET_ENUM_OVERRIDE_MOOD: typing.Final[str] = """-- name: GetEnumOverrideMood :one +SELECT mood_test FROM test_enum_override WHERE id = $1 +""" + +LIST_ENUM_OVERRIDE_BY_IDS: typing.Final[str] = """-- name: ListEnumOverrideByIds :many +SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) +""" + +COUNT_ENUM_OVERRIDE_BY_MOODS: typing.Final[str] = """-- name: CountEnumOverrideByMoods :one +SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: ConnectionLike, + sql: str, + decode_hook: collections.abc.Callable[[asyncpg.Record], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Args: + conn: + The connection object of type `ConnectionLike` used to execute queries. + sql: + The SQL statement that will be executed when fetching/iterating. + decode_hook: + A callback that turns an `asyncpg.Record` object into `T` that will be returned. + *args: + Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: asyncpg.cursor.CursorFactory[asyncpg.Record] | None = None + self._iterator: asyncpg.cursor.CursorIterator[asyncpg.Record] | None = None + + def __aiter__(self) -> QueryResults[T]: + """Initialize iteration support for `async for`. + + Returns: + Self as an asynchronous iterator. + """ + return self + + def __await__( + self, + ) -> collections.abc.Generator[None, None, collections.abc.Sequence[T]]: + """Allow `await` on the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + + async def _wrapper() -> collections.abc.Sequence[T]: + result = await self._conn.fetch(self._sql, *self._args) + return [self._decode_hook(row) for row in result] + + return _wrapper().__await__() + + async def __anext__(self) -> T: + """Yield the next item in the query result using an asyncpg cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopAsyncIteration: When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor = self._conn.cursor(self._sql, *self._args) + self._iterator = self._cursor.__aiter__() + try: + record = await self._iterator.__anext__() + except StopAsyncIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +async def insert_enum_override(conn: ConnectionLike, *, id_: int, mood_test: str) -> None: + """Execute SQL query with `name: InsertEnumOverride :exec`. + + ```sql + INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + mood_test: str. + """ + await conn.execute(INSERT_ENUM_OVERRIDE, id_, enums.TestMood(mood_test)) + + +async def get_enum_override_mood(conn: ConnectionLike, *, id_: int) -> str | None: + """Fetch one from the db using the SQL query with `name: GetEnumOverrideMood :one`. + + ```sql + SELECT mood_test FROM test_enum_override WHERE id = $1 + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + id_: int. + + Returns: + Result of type `str` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(GET_ENUM_OVERRIDE_MOOD, id_) + if row is None: + return None + return str(row[0]) + + +def list_enum_override_by_ids(conn: ConnectionLike, *, dollar_1: collections.abc.Sequence[int]) -> QueryResults[models.TestEnumOverride]: + """Fetch many from the db using the SQL query with `name: ListEnumOverrideByIds :many`. + + ```sql + SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + dollar_1: collections.abc.Sequence[int]. + + Returns: + Helper class of type `QueryResults[models.TestEnumOverride]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: asyncpg.Record) -> models.TestEnumOverride: + return models.TestEnumOverride(id_=row[0], mood_test=str(row[1])) + + return QueryResults(conn, LIST_ENUM_OVERRIDE_BY_IDS, _decode_hook, dollar_1) + + +async def count_enum_override_by_moods(conn: ConnectionLike, *, dollar_1: collections.abc.Sequence[enums.TestMood]) -> int | None: + """Fetch one from the db using the SQL query with `name: CountEnumOverrideByMoods :one`. + + ```sql + SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]) + ``` + + Args: + conn: + Connection object of type `ConnectionLike` used to execute the query. + dollar_1: collections.abc.Sequence[enums.TestMood]. + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = await conn.fetchrow(COUNT_ENUM_OVERRIDE_BY_MOODS, dollar_1) + if row is None: + return None + return row[0] diff --git a/test/driver_asyncpg/pydantic/ruff.toml b/test/driver_asyncpg/pydantic/ruff.toml new file mode 100644 index 00000000..ded540a0 --- /dev/null +++ b/test/driver_asyncpg/pydantic/ruff.toml @@ -0,0 +1,9 @@ +extend="../../../ruff.toml" + + +[lint.flake8-type-checking] +runtime-evaluated-base-classes = ["pydantic.BaseModel"] + + +[lint.pydocstyle] +convention = "google" \ No newline at end of file diff --git a/test/driver_asyncpg/pydantic/test_pydantic_classes.py b/test/driver_asyncpg/pydantic/test_pydantic_classes.py new file mode 100644 index 00000000..60794c7d --- /dev/null +++ b/test/driver_asyncpg/pydantic/test_pydantic_classes.py @@ -0,0 +1,702 @@ +# Copyright (c) 2025 Rayakame + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +from __future__ import annotations + +import collections.abc +import datetime +import decimal +import random +import typing +import uuid +from collections import UserString + +if typing.TYPE_CHECKING: + import asyncpg + +import math + +import pytest +import pytest_asyncio + +from test.driver_asyncpg.pydantic.classes import models +from test.driver_asyncpg.pydantic.classes import queries + + +@pytest.mark.asyncio(loop_scope="session") +class TestPydanticClasses: + @pytest.fixture(scope="session") + def override_model(self) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) + + @pytest.fixture(scope="session") + def model(self) -> models.TestPostgresType: + return models.TestPostgresType( + id_=random.randint(1, 1000000), + serial_test=1, + serial4_test=2, + bigserial_test=3, + smallserial_test=4, + int_test=123, + bigint_test=123_456_789_012_345, + smallint_test=12, + float_test=math.pi, + double_precision_test=math.e, + real_test=3.25, + numeric_test=decimal.Decimal("12345.6789"), + money_test="$99.99", + bool_test=True, + json_test='{"foo": "bar"}', + jsonb_test='{"foo": "bar", "active": true}', + bytea_test=memoryview(b"\x00\x01\x02hello"), + date_test=datetime.date(2025, 1, 1), + time_test=datetime.time(14, 30, 0), + timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.UTC), + timestamp_test=datetime.datetime(2025, 1, 1, 14, 30, 0), + timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.UTC), + interval_test=datetime.timedelta(days=1, hours=2, minutes=30), + text_test="Lorem ipsum", + varchar_test="Example varchar", + bpchar_test="ABCDEFGHIJ", + char_test="X", + citext_test="CaseInsensitive", + uuid_test=uuid.UUID("12345678-1234-5678-1234-567812345678"), + inet_test="192.168.1.1", + cidr_test="192.168.100.0/24", + macaddr_test="08:00:2b:01:02:03", + macaddr8_test="08:00:2b:ff:fe:01:02:03", + ltree_test="Top.Science.Astronomy", + lquery_test="*.Astronomy.*", + ltxtquery_test="Astro* & Stars", + ) + + @pytest.fixture(scope="session") + def inner_model(self, model: models.TestPostgresType) -> models.TestInnerPostgresType: + return models.TestInnerPostgresType( + table_id=model.id_, + serial_test=model.serial_test, + serial4_test=model.serial4_test, + bigserial_test=model.bigserial_test, + smallserial_test=model.smallserial_test, + int_test=None, + bigint_test=None, + smallint_test=None, + float_test=None, + double_precision_test=None, + real_test=None, + numeric_test=None, + money_test=None, + bool_test=None, + json_test=None, + jsonb_test=None, + bytea_test=None, + date_test=None, + time_test=None, + timetz_test=None, + timestamp_test=None, + timestamptz_test=None, + interval_test=None, + text_test=None, + varchar_test=None, + bpchar_test=None, + char_test=None, + citext_test=None, + uuid_test=None, + inet_test=None, + cidr_test=None, + macaddr_test=None, + macaddr8_test=None, + ltree_test=None, + lquery_test=None, + ltxtquery_test=None, + ) + + @pytest_asyncio.fixture(scope="session", loop_scope="session") + async def queries_obj(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record]) -> queries.Queries: + return queries.Queries(conn=asyncpg_conn) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestPydanticClasses::create") + async def test_create(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: + await queries_obj.create_one_test_postgres_type( + id_=model.id_, + serial_test=model.serial_test, + serial4_test=model.serial4_test, + bigserial_test=model.bigserial_test, + smallserial_test=model.smallserial_test, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + float_test=model.float_test, + double_precision_test=model.double_precision_test, + real_test=model.real_test, + numeric_test=model.numeric_test, + money_test=model.money_test, + bool_test=model.bool_test, + json_test=model.json_test, + jsonb_test=model.jsonb_test, + bytea_test=model.bytea_test, + date_test=model.date_test, + time_test=model.time_test, + timetz_test=model.timetz_test, + timestamp_test=model.timestamp_test, + timestamptz_test=model.timestamptz_test, + interval_test=model.interval_test, + text_test=model.text_test, + varchar_test=model.varchar_test, + bpchar_test=model.bpchar_test, + char_test=model.char_test, + citext_test=model.citext_test, + uuid_test=model.uuid_test, + inet_test=model.inet_test, + cidr_test=model.cidr_test, + macaddr_test=model.macaddr_test, + macaddr8_test=model.macaddr8_test, + ltree_test=model.ltree_test, + lquery_test=model.lquery_test, + ltxtquery_test=model.ltxtquery_test, + ) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestPydanticClasses::create_inner", depends=["TestPydanticClasses::create"]) + async def test_create_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerPostgresType) -> None: + await queries_obj.create_one_test_postgres_inner_type( + table_id=inner_model.table_id, + serial_test=inner_model.serial_test, + serial4_test=inner_model.serial4_test, + bigserial_test=inner_model.bigserial_test, + smallserial_test=inner_model.smallserial_test, + int_test=inner_model.int_test, + bigint_test=inner_model.bigint_test, + smallint_test=inner_model.smallint_test, + float_test=inner_model.float_test, + double_precision_test=inner_model.double_precision_test, + real_test=inner_model.real_test, + numeric_test=inner_model.numeric_test, + money_test=inner_model.money_test, + bool_test=inner_model.bool_test, + json_test=inner_model.json_test, + jsonb_test=inner_model.jsonb_test, + bytea_test=inner_model.bytea_test, + date_test=inner_model.date_test, + time_test=inner_model.time_test, + timetz_test=inner_model.timetz_test, + timestamp_test=inner_model.timestamp_test, + timestamptz_test=inner_model.timestamptz_test, + interval_test=inner_model.interval_test, + text_test=inner_model.text_test, + varchar_test=inner_model.varchar_test, + bpchar_test=inner_model.bpchar_test, + char_test=inner_model.char_test, + citext_test=inner_model.citext_test, + uuid_test=inner_model.uuid_test, + inet_test=inner_model.inet_test, + cidr_test=inner_model.cidr_test, + macaddr_test=inner_model.macaddr_test, + macaddr8_test=inner_model.macaddr8_test, + ltree_test=inner_model.ltree_test, + lquery_test=inner_model.lquery_test, + ltxtquery_test=inner_model.ltxtquery_test, + ) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::create_inner"], name="TestPydanticClasses::get_one") + async def test_get_one(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: + result = await queries_obj.get_one_test_postgres_type(id_=model.id_) + + assert result is not None + assert isinstance(result, models.TestPostgresType) + + assert result == model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::get_one"], name="TestPydanticClasses::get_one_none") + async def test_get_one_none(self, queries_obj: queries.Queries) -> None: + result = await queries_obj.get_one_test_postgres_type(id_=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::get_one_none"], name="TestPydanticClasses::get_one_inner") + async def test_get_one_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerPostgresType) -> None: + result = await queries_obj.get_one_inner_test_postgres_type(table_id=inner_model.table_id) + + assert result is not None + assert isinstance(result, models.TestInnerPostgresType) + + assert result == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::get_one_inner"], name="TestPydanticClasses::get_one_inner_none") + async def test_get_one_inner_none(self, queries_obj: queries.Queries) -> None: + result = await queries_obj.get_one_inner_test_postgres_type(table_id=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticClasses::get_one_inner_none"], + name="TestPydanticClasses::get_one_timestamp", + ) + async def test_get_one_timestamp(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: + result = await queries_obj.get_one_test_timestamp_postgres_type(id_=model.id_) + + assert result is not None + assert isinstance(result, datetime.datetime) + assert result == model.timestamp_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::get_one_timestamp"], name="TestPydanticClasses::get_one_timestamp_none") + async def test_get_one_timestamp_none(self, queries_obj: queries.Queries) -> None: + result = await queries_obj.get_one_test_timestamp_postgres_type(id_=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticClasses::get_one_timestamp_none"], + name="TestPydanticClasses::get_one_bytea", + ) + async def test_get_one_bytea(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: + result = await queries_obj.get_one_test_bytea_postgres_type(id_=model.id_) + + assert result is not None + assert isinstance(result, memoryview) + assert result == model.bytea_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::get_one_bytea"], name="TestPydanticClasses::get_one_bytea_none") + async def test_get_one_bytea_none(self, queries_obj: queries.Queries) -> None: + result = await queries_obj.get_one_test_bytea_postgres_type(id_=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::get_one_bytea_none"], name="TestPydanticClasses::get_many") + async def test_get_many(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: + result = await queries_obj.get_many_test_postgres_type(id_=model.id_) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], models.TestPostgresType) + + first_result = result[0] + assert first_result == model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::get_many"], name="TestPydanticClasses::get_many_timestamp") + async def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: + result = await queries_obj.get_many_test_timestamp_postgres_type(id_=model.id_) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], datetime.datetime) + + assert result[0] == model.timestamp_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticClasses::get_many_timestamp"], + name="TestPydanticClasses::get_many_bytea", + ) + async def test_get_many_bytea(self, queries_obj: queries.Queries, model: models.TestPostgresType) -> None: + result = await queries_obj.get_many_test_bytea_postgres_type(id_=model.id_) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], memoryview) + + assert result[0] == model.bytea_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::get_many_bytea"], name="TestPydanticClasses::get_embedded") + async def test_get_embedded( + self, + queries_obj: queries.Queries, + model: models.TestPostgresType, + inner_model: models.TestInnerPostgresType, + ) -> None: + result = await queries_obj.get_embedded_test_postgres_type(id_=model.id_) + + assert result is not None + assert isinstance(result, queries.GetEmbeddedTestPostgresTypeRow) + assert isinstance(result.test_inner_postgres_type, models.TestInnerPostgresType) + + assert result.id_ == model.id_ + assert result.serial_test == model.serial_test + assert result.serial4_test == model.serial4_test + assert result.bigserial_test == model.bigserial_test + assert result.smallserial_test == model.smallserial_test + assert result.int_test == model.int_test + assert result.bigint_test == model.bigint_test + assert result.smallint_test == model.smallint_test + assert result.float_test == model.float_test + assert result.double_precision_test == model.double_precision_test + assert result.real_test == model.real_test + assert result.numeric_test == model.numeric_test + assert result.money_test == model.money_test + assert result.bool_test == model.bool_test + assert result.json_test == model.json_test + assert result.jsonb_test == model.jsonb_test + assert result.bytea_test == model.bytea_test + assert result.date_test == model.date_test + assert result.time_test == model.time_test + assert result.timetz_test == model.timetz_test + assert result.timestamp_test == model.timestamp_test + assert result.timestamptz_test == model.timestamptz_test + assert result.interval_test == model.interval_test + assert result.text_test == model.text_test + assert result.varchar_test == model.varchar_test + assert result.bpchar_test == model.bpchar_test + assert result.char_test == model.char_test + assert result.citext_test == model.citext_test + assert result.uuid_test == model.uuid_test + assert result.inet_test == model.inet_test + assert result.cidr_test == model.cidr_test + assert result.macaddr_test == model.macaddr_test + assert result.macaddr8_test == model.macaddr8_test + assert result.ltree_test == model.ltree_test + assert result.lquery_test == model.lquery_test + assert result.ltxtquery_test == model.ltxtquery_test + + assert result.test_inner_postgres_type == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::get_embedded"], name="TestPydanticClasses::get_embedded_none") + async def test_get_embedded_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = await queries_obj.get_embedded_test_postgres_type(id_=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticClasses::get_embedded_none"], + name="TestPydanticClasses::get_all_embedded", + ) + async def test_get_all_embedded( + self, + queries_obj: queries.Queries, + model: models.TestPostgresType, + inner_model: models.TestInnerPostgresType, + ) -> None: + result = await queries_obj.get_all_embedded_test_postgres_type(id_=model.id_) + + assert result is not None + assert isinstance(result, queries.GetAllEmbeddedTestPostgresTypeRow) + assert isinstance(result.test_postgres_type, models.TestPostgresType) + assert isinstance(result.test_inner_postgres_type, models.TestInnerPostgresType) + + assert result.test_postgres_type == model + assert result.test_inner_postgres_type == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::get_all_embedded"], name="TestPydanticClasses::get_all_embedded_none") + async def test_get_all_embedded_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = await queries_obj.get_all_embedded_test_postgres_type(id_=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticClasses::get_all_embedded_none"], + name="TestPydanticClasses::get_many_iterator", + ) + async def test_get_many_iterator( + self, + queries_obj: queries.Queries, + model: models.TestPostgresType, + ) -> None: + results = queries_obj.get_many_test_iterator_postgres_type(id_=model.id_) + async with queries_obj.conn.transaction(): + async for result in results: + assert result is not None + assert isinstance(result, models.TestPostgresType) + + assert result == model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::get_many_iterator"], name="TestPydanticClasses::delete") + async def test_delete( + self, + queries_obj: queries.Queries, + model: models.TestPostgresType, + ) -> None: + await queries_obj.delete_one_test_postgres_type(id_=model.id_) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::delete"], name="TestPydanticClasses::delete_inner") + async def test_delete_inner( + self, + queries_obj: queries.Queries, + inner_model: models.TestInnerPostgresType, + ) -> None: + await queries_obj.delete_one_test_postgres_inner_type(table_id=inner_model.table_id) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestPydanticClasses::create_result") + async def test_create_result( + self, + queries_obj: queries.Queries, + model: models.TestPostgresType, + ) -> None: + result = await queries_obj.create_result_one_test_postgres_type( + id_=model.id_ + 1, + serial_test=model.serial_test, + serial4_test=model.serial4_test, + bigserial_test=model.bigserial_test, + smallserial_test=model.smallserial_test, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + float_test=model.float_test, + double_precision_test=model.double_precision_test, + real_test=model.real_test, + numeric_test=model.numeric_test, + money_test=model.money_test, + bool_test=model.bool_test, + json_test=model.json_test, + jsonb_test=model.jsonb_test, + bytea_test=model.bytea_test, + date_test=model.date_test, + time_test=model.time_test, + timetz_test=model.timetz_test, + timestamp_test=model.timestamp_test, + timestamptz_test=model.timestamptz_test, + interval_test=model.interval_test, + text_test=model.text_test, + varchar_test=model.varchar_test, + bpchar_test=model.bpchar_test, + char_test=model.char_test, + citext_test=model.citext_test, + uuid_test=model.uuid_test, + inet_test=model.inet_test, + cidr_test=model.cidr_test, + macaddr_test=model.macaddr_test, + macaddr8_test=model.macaddr8_test, + ltree_test=model.ltree_test, + lquery_test=model.lquery_test, + ltxtquery_test=model.ltxtquery_test, + ) + + assert result == "INSERT 0 1" + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::create_result"], name="TestPydanticClasses::update_result") + async def test_update_result( + self, + queries_obj: queries.Queries, + model: models.TestPostgresType, + ) -> None: + result = await queries_obj.update_result_test_postgres_type(id_=model.id_ + 1) + + assert result == "UPDATE 1" + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::update_result"], name="TestPydanticClasses::delete_result") + async def test_delete_result( + self, + queries_obj: queries.Queries, + model: models.TestPostgresType, + ) -> None: + result = await queries_obj.delete_one_result_test_postgres_type(id_=model.id_ + 1) + + assert result == "DELETE 1" + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestPydanticClasses::create_rows") + async def test_create_rows( + self, + queries_obj: queries.Queries, + model: models.TestPostgresType, + ) -> None: + result = await queries_obj.create_rows_one_test_postgres_type( + id_=model.id_ + 1, + serial_test=model.serial_test, + serial4_test=model.serial4_test, + bigserial_test=model.bigserial_test, + smallserial_test=model.smallserial_test, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + float_test=model.float_test, + double_precision_test=model.double_precision_test, + real_test=model.real_test, + numeric_test=model.numeric_test, + money_test=model.money_test, + bool_test=model.bool_test, + json_test=model.json_test, + jsonb_test=model.jsonb_test, + bytea_test=model.bytea_test, + date_test=model.date_test, + time_test=model.time_test, + timetz_test=model.timetz_test, + timestamp_test=model.timestamp_test, + timestamptz_test=model.timestamptz_test, + interval_test=model.interval_test, + text_test=model.text_test, + varchar_test=model.varchar_test, + bpchar_test=model.bpchar_test, + char_test=model.char_test, + citext_test=model.citext_test, + uuid_test=model.uuid_test, + inet_test=model.inet_test, + cidr_test=model.cidr_test, + macaddr_test=model.macaddr_test, + macaddr8_test=model.macaddr8_test, + ltree_test=model.ltree_test, + lquery_test=model.lquery_test, + ltxtquery_test=model.ltxtquery_test, + ) + + assert result == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::create_rows"], name="TestPydanticClasses::update_rows") + async def test_update_rows( + self, + queries_obj: queries.Queries, + model: models.TestPostgresType, + ) -> None: + result = await queries_obj.update_rows_test_postgres_type(id_=model.id_ + 1) + + assert result == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::update_rows"], name="TestPydanticClasses::delete_rows") + async def test_delete_rows( + self, + queries_obj: queries.Queries, + model: models.TestPostgresType, + ) -> None: + result = await queries_obj.delete_one_rows_test_postgres_type(id_=model.id_ + 1) + + assert result == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticClasses::delete_rows"], name="TestPydanticClasses::copy_from") + async def test_copy_from( + self, + queries_obj: queries.Queries, + model: models.TestPostgresType, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + ) -> None: + num = 3 + rows: list[queries.TestCopyFromParams] = [ + queries.TestCopyFromParams( + id_=i, + int_test=model.int_test, + float_test=model.float_test, + ) + for i in range(num) + ] + + result = await queries_obj.test_copy_from(params=rows) + assert result == num + await asyncpg_conn.execute("""DELETE FROM test_copy_from;""") + + @pytest.mark.asyncio(loop_scope="session") + async def test_create_table( + self, + queries_obj: queries.Queries, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + ) -> None: + result = await queries_obj.create_rows_table() + + assert result == 0 + + await asyncpg_conn.execute("""DROP TABLE test_create_rows_table;""") + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticClasses::insert_type_override", + ) + async def test_insert_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.insert_type_override(id_=override_model.id_, text_test=override_model.text_test) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticClasses::get_one_type_override", + depends=["TestPydanticClasses::insert_type_override"], + ) + async def test_get_one_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_) + assert result is not None + assert result == override_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticClasses::get_one_type_override_none", + depends=["TestPydanticClasses::get_one_type_override"], + ) + async def test_get_one_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_type_override(id_=override_model.id_ - 1) + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticClasses::get_many_type_override", + depends=["TestPydanticClasses::get_one_type_override_none"], + ) + async def test_get_many_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_type_override(id_=override_model.id_) + assert isinstance(result, collections.abc.Sequence) + assert result[0] == override_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticClasses::get_one_text_type_override", + depends=["TestPydanticClasses::get_many_type_override"], + ) + async def test_get_one_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_) + assert result is not None + assert result == override_model.text_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticClasses::get_one_text_type_override_none", + depends=["TestPydanticClasses::get_one_text_type_override"], + ) + async def test_get_one_text_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_one_text_type_override(id_=override_model.id_ - 1) + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticClasses::get_many_text_type_override", + depends=["TestPydanticClasses::get_one_text_type_override_none"], + ) + async def test_get_many_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = await queries_obj.get_many_text_type_override(id_=override_model.id_) + assert isinstance(result, collections.abc.Sequence) + assert result[0] == override_model.text_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticClasses::delete_type_override", + depends=["TestPydanticClasses::get_many_text_type_override"], + ) + async def test_delete_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + await queries_obj.delete_type_override(id_=override_model.id_) diff --git a/test/driver_asyncpg/pydantic/test_pydantic_functions.py b/test/driver_asyncpg/pydantic/test_pydantic_functions.py new file mode 100644 index 00000000..bd1fe404 --- /dev/null +++ b/test/driver_asyncpg/pydantic/test_pydantic_functions.py @@ -0,0 +1,774 @@ +# Copyright (c) 2025 Rayakame + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +from __future__ import annotations + +import collections.abc +import datetime +import decimal +import random +import typing +import uuid +from collections import UserString + +if typing.TYPE_CHECKING: + import asyncpg + +import math + +import pytest + +from test.driver_asyncpg.pydantic.functions import models +from test.driver_asyncpg.pydantic.functions import queries + + +@pytest.mark.asyncio(loop_scope="session") +class TestPydanticFunctions: + @pytest.fixture(scope="session") + def override_model(self) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) + + @pytest.fixture(scope="session") + def model(self) -> models.TestPostgresType: + return models.TestPostgresType( + id_=random.randint(1, 1000000), + serial_test=1, + serial4_test=2, + bigserial_test=3, + smallserial_test=4, + int_test=123, + bigint_test=123_456_789_012_345, + smallint_test=12, + float_test=math.pi, + double_precision_test=math.e, + real_test=3.25, + numeric_test=decimal.Decimal("12345.6789"), + money_test="$99.99", + bool_test=True, + json_test='{"foo": "bar"}', + jsonb_test='{"foo": "bar", "active": true}', + bytea_test=memoryview(b"\x00\x01\x02hello"), + date_test=datetime.date(2025, 1, 1), + time_test=datetime.time(14, 30, 0), + timetz_test=datetime.time(14, 30, 0, tzinfo=datetime.UTC), + timestamp_test=datetime.datetime(2025, 1, 1, 14, 30, 0), + timestamptz_test=datetime.datetime(2025, 1, 1, 14, 30, 0, tzinfo=datetime.UTC), + interval_test=datetime.timedelta(days=1, hours=2, minutes=30), + text_test="Lorem ipsum", + varchar_test="Example varchar", + bpchar_test="ABCDEFGHIJ", + char_test="X", + citext_test="CaseInsensitive", + uuid_test=uuid.UUID("12345678-1234-5678-1234-567812345678"), + inet_test="192.168.1.1", + cidr_test="192.168.100.0/24", + macaddr_test="08:00:2b:01:02:03", + macaddr8_test="08:00:2b:ff:fe:01:02:03", + ltree_test="Top.Science.Astronomy", + lquery_test="*.Astronomy.*", + ltxtquery_test="Astro* & Stars", + ) + + @pytest.fixture(scope="session") + def inner_model(self, model: models.TestPostgresType) -> models.TestInnerPostgresType: + return models.TestInnerPostgresType( + table_id=model.id_, + serial_test=model.serial_test, + serial4_test=model.serial4_test, + bigserial_test=model.bigserial_test, + smallserial_test=model.smallserial_test, + int_test=None, + bigint_test=None, + smallint_test=None, + float_test=None, + double_precision_test=None, + real_test=None, + numeric_test=None, + money_test=None, + bool_test=None, + json_test=None, + jsonb_test=None, + bytea_test=None, + date_test=None, + time_test=None, + timetz_test=None, + timestamp_test=None, + timestamptz_test=None, + interval_test=None, + text_test=None, + varchar_test=None, + bpchar_test=None, + char_test=None, + citext_test=None, + uuid_test=None, + inet_test=None, + cidr_test=None, + macaddr_test=None, + macaddr8_test=None, + ltree_test=None, + lquery_test=None, + ltxtquery_test=None, + ) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestPydanticFunctions::create") + async def test_create( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + await queries.create_one_test_postgres_type( + conn=asyncpg_conn, + id_=model.id_, + serial_test=model.serial_test, + serial4_test=model.serial4_test, + bigserial_test=model.bigserial_test, + smallserial_test=model.smallserial_test, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + float_test=model.float_test, + double_precision_test=model.double_precision_test, + real_test=model.real_test, + numeric_test=model.numeric_test, + money_test=model.money_test, + bool_test=model.bool_test, + json_test=model.json_test, + jsonb_test=model.jsonb_test, + bytea_test=model.bytea_test, + date_test=model.date_test, + time_test=model.time_test, + timetz_test=model.timetz_test, + timestamp_test=model.timestamp_test, + timestamptz_test=model.timestamptz_test, + interval_test=model.interval_test, + text_test=model.text_test, + varchar_test=model.varchar_test, + bpchar_test=model.bpchar_test, + char_test=model.char_test, + citext_test=model.citext_test, + uuid_test=model.uuid_test, + inet_test=model.inet_test, + cidr_test=model.cidr_test, + macaddr_test=model.macaddr_test, + macaddr8_test=model.macaddr8_test, + ltree_test=model.ltree_test, + lquery_test=model.lquery_test, + ltxtquery_test=model.ltxtquery_test, + ) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestPydanticFunctions::create2", depends=["TestPydanticFunctions::create"]) + async def test_create_inner( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + inner_model: models.TestInnerPostgresType, + ) -> None: + await queries.create_one_test_postgres_inner_type( + conn=asyncpg_conn, + table_id=inner_model.table_id, + serial_test=inner_model.serial_test, + serial4_test=inner_model.serial4_test, + bigserial_test=inner_model.bigserial_test, + smallserial_test=inner_model.smallserial_test, + int_test=inner_model.int_test, + bigint_test=inner_model.bigint_test, + smallint_test=inner_model.smallint_test, + float_test=inner_model.float_test, + double_precision_test=inner_model.double_precision_test, + real_test=inner_model.real_test, + numeric_test=inner_model.numeric_test, + money_test=inner_model.money_test, + bool_test=inner_model.bool_test, + json_test=inner_model.json_test, + jsonb_test=inner_model.jsonb_test, + bytea_test=inner_model.bytea_test, + date_test=inner_model.date_test, + time_test=inner_model.time_test, + timetz_test=inner_model.timetz_test, + timestamp_test=inner_model.timestamp_test, + timestamptz_test=inner_model.timestamptz_test, + interval_test=inner_model.interval_test, + text_test=inner_model.text_test, + varchar_test=inner_model.varchar_test, + bpchar_test=inner_model.bpchar_test, + char_test=inner_model.char_test, + citext_test=inner_model.citext_test, + uuid_test=inner_model.uuid_test, + inet_test=inner_model.inet_test, + cidr_test=inner_model.cidr_test, + macaddr_test=inner_model.macaddr_test, + macaddr8_test=inner_model.macaddr8_test, + ltree_test=inner_model.ltree_test, + lquery_test=inner_model.lquery_test, + ltxtquery_test=inner_model.ltxtquery_test, + ) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticFunctions::create2"], name="TestPydanticFunctions::get_one") + async def test_get_one( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + result = await queries.get_one_test_postgres_type(conn=asyncpg_conn, id_=model.id_) + + assert result is not None + assert isinstance(result, models.TestPostgresType) + + assert result == model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticFunctions::get_one"], name="TestPydanticFunctions::get_one_none") + async def test_get_one_none( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + ) -> None: + result = await queries.get_one_test_postgres_type(conn=asyncpg_conn, id_=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticFunctions::get_one_none"], name="TestPydanticFunctions::get_one_inner") + async def test_get_one_inner( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + inner_model: models.TestInnerPostgresType, + ) -> None: + result = await queries.get_one_inner_test_postgres_type(conn=asyncpg_conn, table_id=inner_model.table_id) + + assert result is not None + assert isinstance(result, models.TestInnerPostgresType) + + assert result == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticFunctions::get_one_inner"], name="TestPydanticFunctions::get_one_inner_none") + async def test_get_one_inner_none( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + ) -> None: + result = await queries.get_one_inner_test_postgres_type(conn=asyncpg_conn, table_id=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::get_one_inner_none"], + name="TestPydanticFunctions::get_one_timestamp", + ) + async def test_get_one_timestamp( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + result = await queries.get_one_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id_) + + assert result is not None + assert isinstance(result, datetime.datetime) + assert result == model.timestamp_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::get_one_timestamp"], + name="TestPydanticFunctions::get_one_timestamp_none", + ) + async def test_get_one_timestamp_none( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + ) -> None: + result = await queries.get_one_test_timestamp_postgres_type(conn=asyncpg_conn, id_=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::get_one_timestamp_none"], + name="TestPydanticFunctions::get_one_bytea", + ) + async def test_get_one_bytea( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + result = await queries.get_one_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id_) + + assert result is not None + assert isinstance(result, memoryview) + assert result == model.bytea_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::get_one_bytea"], + name="TestPydanticFunctions::get_one_bytea_none", + ) + async def test_get_one_bytea_none( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + ) -> None: + result = await queries.get_one_test_bytea_postgres_type(conn=asyncpg_conn, id_=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticFunctions::get_one_bytea_none"], name="TestPydanticFunctions::get_many") + async def test_get_many( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + result = await queries.get_many_test_postgres_type(conn=asyncpg_conn, id_=model.id_) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], models.TestPostgresType) + + first_result = result[0] + assert first_result == model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::get_many"], + name="TestPydanticFunctions::get_many_timestamp", + ) + async def test_get_many_timestamp( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + result = await queries.get_many_test_timestamp_postgres_type(conn=asyncpg_conn, id_=model.id_) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], datetime.datetime) + + assert result[0] == model.timestamp_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::get_many_timestamp"], + name="TestPydanticFunctions::get_many_bytea", + ) + async def test_get_many_bytea( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + result = await queries.get_many_test_bytea_postgres_type(conn=asyncpg_conn, id_=model.id_) + + assert result is not None + assert isinstance(result, collections.abc.Sequence) + assert isinstance(result[0], memoryview) + + assert result[0] == model.bytea_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::get_many_bytea"], + name="TestPydanticFunctions::get_embedded", + ) + async def test_get_embedded( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + inner_model: models.TestInnerPostgresType, + ) -> None: + result = await queries.get_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id_) + + assert result is not None + assert isinstance(result, queries.GetEmbeddedTestPostgresTypeRow) + assert isinstance(result.test_inner_postgres_type, models.TestInnerPostgresType) + + assert result.id_ == model.id_ + assert result.serial_test == model.serial_test + assert result.serial4_test == model.serial4_test + assert result.bigserial_test == model.bigserial_test + assert result.smallserial_test == model.smallserial_test + assert result.int_test == model.int_test + assert result.bigint_test == model.bigint_test + assert result.smallint_test == model.smallint_test + assert result.float_test == model.float_test + assert result.double_precision_test == model.double_precision_test + assert result.real_test == model.real_test + assert result.numeric_test == model.numeric_test + assert result.money_test == model.money_test + assert result.bool_test == model.bool_test + assert result.json_test == model.json_test + assert result.jsonb_test == model.jsonb_test + assert result.bytea_test == model.bytea_test + assert result.date_test == model.date_test + assert result.time_test == model.time_test + assert result.timetz_test == model.timetz_test + assert result.timestamp_test == model.timestamp_test + assert result.timestamptz_test == model.timestamptz_test + assert result.interval_test == model.interval_test + assert result.text_test == model.text_test + assert result.varchar_test == model.varchar_test + assert result.bpchar_test == model.bpchar_test + assert result.char_test == model.char_test + assert result.citext_test == model.citext_test + assert result.uuid_test == model.uuid_test + assert result.inet_test == model.inet_test + assert result.cidr_test == model.cidr_test + assert result.macaddr_test == model.macaddr_test + assert result.macaddr8_test == model.macaddr8_test + assert result.ltree_test == model.ltree_test + assert result.lquery_test == model.lquery_test + assert result.ltxtquery_test == model.ltxtquery_test + + assert result.test_inner_postgres_type == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::get_embedded"], + name="TestPydanticFunctions::get_embedded_none", + ) + async def test_get_embedded_none( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + ) -> None: + result = await queries.get_embedded_test_postgres_type(conn=asyncpg_conn, id_=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::get_embedded_none"], + name="TestPydanticFunctions::get_all_embedded", + ) + async def test_get_all_embedded( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + inner_model: models.TestInnerPostgresType, + ) -> None: + result = await queries.get_all_embedded_test_postgres_type(conn=asyncpg_conn, id_=model.id_) + + assert result is not None + assert isinstance(result, queries.GetAllEmbeddedTestPostgresTypeRow) + assert isinstance(result.test_postgres_type, models.TestPostgresType) + assert isinstance(result.test_inner_postgres_type, models.TestInnerPostgresType) + + assert result.test_postgres_type == model + assert result.test_inner_postgres_type == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::get_all_embedded"], + name="TestPydanticFunctions::get_all_embedded_none", + ) + async def test_get_all_embedded_none( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + ) -> None: + result = await queries.get_all_embedded_test_postgres_type(conn=asyncpg_conn, id_=0) + + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::get_all_embedded_none"], + name="TestPydanticFunctions::get_many_iterator", + ) + async def test_get_many_iterator( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + results = queries.get_many_test_iterator_postgres_type(conn=asyncpg_conn, id_=model.id_) + async with asyncpg_conn.transaction(): + async for result in results: + assert result is not None + assert isinstance(result, models.TestPostgresType) + + assert result == model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::get_many_iterator"], + name="TestPydanticFunctions::delete", + ) + async def test_delete( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + await queries.delete_one_test_postgres_type(conn=asyncpg_conn, id_=model.id_) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticFunctions::delete"], name="TestPydanticFunctions::delete_inner") + async def test_delete_inner( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + inner_model: models.TestInnerPostgresType, + ) -> None: + await queries.delete_one_test_postgres_inner_type(conn=asyncpg_conn, table_id=inner_model.table_id) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestPydanticFunctions::create_result") + async def test_create_result( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + result = await queries.create_result_one_test_postgres_type( + conn=asyncpg_conn, + id_=model.id_ + 1, + serial_test=model.serial_test, + serial4_test=model.serial4_test, + bigserial_test=model.bigserial_test, + smallserial_test=model.smallserial_test, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + float_test=model.float_test, + double_precision_test=model.double_precision_test, + real_test=model.real_test, + numeric_test=model.numeric_test, + money_test=model.money_test, + bool_test=model.bool_test, + json_test=model.json_test, + jsonb_test=model.jsonb_test, + bytea_test=model.bytea_test, + date_test=model.date_test, + time_test=model.time_test, + timetz_test=model.timetz_test, + timestamp_test=model.timestamp_test, + timestamptz_test=model.timestamptz_test, + interval_test=model.interval_test, + text_test=model.text_test, + varchar_test=model.varchar_test, + bpchar_test=model.bpchar_test, + char_test=model.char_test, + citext_test=model.citext_test, + uuid_test=model.uuid_test, + inet_test=model.inet_test, + cidr_test=model.cidr_test, + macaddr_test=model.macaddr_test, + macaddr8_test=model.macaddr8_test, + ltree_test=model.ltree_test, + lquery_test=model.lquery_test, + ltxtquery_test=model.ltxtquery_test, + ) + + assert result == "INSERT 0 1" + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::create_result"], + name="TestPydanticFunctions::update_result", + ) + async def test_update_result( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + result = await queries.update_result_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) + + assert result == "UPDATE 1" + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + depends=["TestPydanticFunctions::update_result"], + name="TestPydanticFunctions::delete_result", + ) + async def test_delete_result( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + result = await queries.delete_one_result_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) + + assert result == "DELETE 1" + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(name="TestPydanticFunctions::create_rows") + async def test_create_rows( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + result = await queries.create_rows_one_test_postgres_type( + conn=asyncpg_conn, + id_=model.id_ + 1, + serial_test=model.serial_test, + serial4_test=model.serial4_test, + bigserial_test=model.bigserial_test, + smallserial_test=model.smallserial_test, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + float_test=model.float_test, + double_precision_test=model.double_precision_test, + real_test=model.real_test, + numeric_test=model.numeric_test, + money_test=model.money_test, + bool_test=model.bool_test, + json_test=model.json_test, + jsonb_test=model.jsonb_test, + bytea_test=model.bytea_test, + date_test=model.date_test, + time_test=model.time_test, + timetz_test=model.timetz_test, + timestamp_test=model.timestamp_test, + timestamptz_test=model.timestamptz_test, + interval_test=model.interval_test, + text_test=model.text_test, + varchar_test=model.varchar_test, + bpchar_test=model.bpchar_test, + char_test=model.char_test, + citext_test=model.citext_test, + uuid_test=model.uuid_test, + inet_test=model.inet_test, + cidr_test=model.cidr_test, + macaddr_test=model.macaddr_test, + macaddr8_test=model.macaddr8_test, + ltree_test=model.ltree_test, + lquery_test=model.lquery_test, + ltxtquery_test=model.ltxtquery_test, + ) + + assert result == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticFunctions::create_rows"], name="TestPydanticFunctions::update_rows") + async def test_update_rows( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + result = await queries.update_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) + + assert result == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticFunctions::update_rows"], name="TestPydanticFunctions::delete_rows") + async def test_delete_rows( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + result = await queries.delete_one_rows_test_postgres_type(conn=asyncpg_conn, id_=model.id_ + 1) + + assert result == 1 + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency(depends=["TestPydanticFunctions::delete_rows"], name="TestPydanticFunctions::copy_from") + async def test_copy_from( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + model: models.TestPostgresType, + ) -> None: + num = 3 + rows: list[queries.TestCopyFromParams] = [ + queries.TestCopyFromParams( + id_=i, + int_test=model.int_test, + float_test=model.float_test, + ) + for i in range(num) + ] + + result = await queries.test_copy_from(conn=asyncpg_conn, params=rows) + assert result == num + await asyncpg_conn.execute("""DELETE FROM test_copy_from;""") + + @pytest.mark.asyncio(loop_scope="session") + async def test_create_table( + self, + asyncpg_conn: asyncpg.Connection[asyncpg.Record], + ) -> None: + result = await queries.create_rows_table(conn=asyncpg_conn) + + assert result == 0 + + await asyncpg_conn.execute("""DROP TABLE test_create_rows_table;""") + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticFunctions::insert_type_override", + ) + async def test_insert_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + await queries.insert_type_override(conn=asyncpg_conn, id_=override_model.id_, text_test=override_model.text_test) + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticFunctions::get_one_type_override", + depends=["TestPydanticFunctions::insert_type_override"], + ) + async def test_get_one_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id_) + assert result is not None + assert result == override_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticFunctions::get_one_type_override_none", + depends=["TestPydanticFunctions::get_one_type_override"], + ) + async def test_get_one_type_override_none(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_type_override(conn=asyncpg_conn, id_=override_model.id_ - 1) + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticFunctions::get_many_type_override", + depends=["TestPydanticFunctions::get_one_type_override_none"], + ) + async def test_get_many_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_type_override(conn=asyncpg_conn, id_=override_model.id_) + assert isinstance(result, collections.abc.Sequence) + assert result[0] == override_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticFunctions::get_one_text_type_override", + depends=["TestPydanticFunctions::get_many_type_override"], + ) + async def test_get_one_text_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id_) + assert result is not None + assert result == override_model.text_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticFunctions::get_one_text_type_override_none", + depends=["TestPydanticFunctions::get_one_text_type_override"], + ) + async def test_get_one_text_type_override_none(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_one_text_type_override(conn=asyncpg_conn, id_=override_model.id_ - 1) + assert result is None + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticFunctions::get_many_text_type_override", + depends=["TestPydanticFunctions::get_one_text_type_override_none"], + ) + async def test_get_many_text_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + result = await queries.get_many_text_type_override(conn=asyncpg_conn, id_=override_model.id_) + assert isinstance(result, collections.abc.Sequence) + assert result[0] == override_model.text_test + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="TestPydanticFunctions::delete_type_override", + depends=["TestPydanticFunctions::get_many_text_type_override"], + ) + async def test_delete_type_override(self, asyncpg_conn: asyncpg.Connection[asyncpg.Record], override_model: models.TestTypeOverride) -> None: + await queries.delete_type_override(conn=asyncpg_conn, id_=override_model.id_) diff --git a/test/driver_asyncpg/queries.sql b/test/driver_asyncpg/queries.sql index c90a8da2..2c3ea10a 100644 --- a/test/driver_asyncpg/queries.sql +++ b/test/driver_asyncpg/queries.sql @@ -288,3 +288,27 @@ SELECT text_test FROM test_type_override WHERE test_type_override.id = $1; DELETE FROM test_type_override WHERE test_type_override.id = $1; + +-- name: InsertOneTestEnumType :exec +INSERT INTO test_enum_types (id, mood, maybe_mood) +VALUES ($1, $2, $3); + +-- name: GetOneTestEnumType :one +SELECT * +FROM test_enum_types +WHERE id = $1; + +-- name: GetOneTestEnumValue :one +SELECT mood +FROM test_enum_types +WHERE id = $1; + +-- name: GetManyTestEnumTypes :many +SELECT * +FROM test_enum_types +ORDER BY id; + +-- name: DeleteOneTestEnumType :execrows +DELETE +FROM test_enum_types +WHERE id = $1; diff --git a/test/driver_asyncpg/queries_copy_override.sql b/test/driver_asyncpg/queries_copy_override.sql new file mode 100644 index 00000000..3519790c --- /dev/null +++ b/test/driver_asyncpg/queries_copy_override.sql @@ -0,0 +1,8 @@ +-- name: CopyOverrideRows :copyfrom +INSERT INTO test_copy_override (id, amount) VALUES ($1, $2); + +-- name: CountCopyOverrideRows :one +SELECT count(*) FROM test_copy_override; + +-- name: DeleteCopyOverrideRows :exec +DELETE FROM test_copy_override; diff --git a/test/driver_asyncpg/queries_enum_override.sql b/test/driver_asyncpg/queries_enum_override.sql new file mode 100644 index 00000000..e91b74c4 --- /dev/null +++ b/test/driver_asyncpg/queries_enum_override.sql @@ -0,0 +1,11 @@ +-- name: InsertEnumOverride :exec +INSERT INTO test_enum_override (id, mood_test) VALUES ($1, $2); + +-- name: GetEnumOverrideMood :one +SELECT mood_test FROM test_enum_override WHERE id = $1; + +-- name: ListEnumOverrideByIds :many +SELECT id, mood_test FROM test_enum_override WHERE id = ANY($1::int[]); + +-- name: CountEnumOverrideByMoods :one +SELECT count(*) FROM test_enum_override WHERE mood_test = ANY($1::test_mood[]); diff --git a/test/driver_asyncpg/schema.sql b/test/driver_asyncpg/schema.sql index a25d9997..6070fd4c 100644 --- a/test/driver_asyncpg/schema.sql +++ b/test/driver_asyncpg/schema.sql @@ -3,7 +3,7 @@ CREATE EXTENSION IF NOT EXISTS ltree; -- ltree / lquery / ltxtquery CREATE TABLE IF NOT EXISTS test_postgres_types ( - /* ───────────── Integer family ───────────── */ + /* ------------- Integer family ------------- */ id int PRIMARY KEY NOT NULL, serial_test serial NOT NULL, serial4_test serial4 NOT NULL, @@ -13,26 +13,26 @@ CREATE TABLE IF NOT EXISTS test_postgres_types bigint_test bigint NOT NULL, smallint_test smallint NOT NULL, - /* ───────────── Floating‑point ───────────── */ + /* ------------- Floating-point ------------- */ float_test float NOT NULL, double_precision_test double precision NOT NULL, real_test real NOT NULL, - /* ───────────── Exact numeric ───────────── */ + /* ------------- Exact numeric ------------- */ numeric_test numeric(12, 4) NOT NULL, money_test money NOT NULL, - /* ───────────── Boolean ───────────── */ + /* ------------- Boolean ------------- */ bool_test boolean NOT NULL, - /* ───────────── JSON / JSONB ───────────── */ + /* ------------- JSON / JSONB ------------- */ json_test json NOT NULL, jsonb_test jsonb NOT NULL, - /* ───────────── Binary ───────────── */ + /* ------------- Binary ------------- */ bytea_test bytea NOT NULL, - /* ───────────── Date & time ───────────── */ + /* ------------- Date & time ------------- */ date_test date NOT NULL, time_test time NOT NULL, timetz_test timetz NOT NULL, @@ -40,23 +40,23 @@ CREATE TABLE IF NOT EXISTS test_postgres_types timestamptz_test timestamptz NOT NULL, interval_test interval NOT NULL, - /* ───────────── Character / text ───────────── */ + /* ------------- Character / text ------------- */ text_test text NOT NULL, varchar_test varchar(255) NOT NULL, bpchar_test bpchar(10) NOT NULL, char_test char(1) NOT NULL, citext_test citext NOT NULL, - /* ───────────── UUID ───────────── */ + /* ------------- UUID ------------- */ uuid_test uuid NOT NULL, - /* ───────────── Network types ───────────── */ + /* ------------- Network types ------------- */ inet_test inet NOT NULL, cidr_test cidr NOT NULL, macaddr_test macaddr NOT NULL, macaddr8_test macaddr8 NOT NULL, - /* ───────────── LTree family ───────────── */ + /* ------------- LTree family ------------- */ ltree_test ltree NOT NULL, lquery_test lquery NOT NULL, ltxtquery_test ltxtquery NOT NULL @@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS test_postgres_types CREATE TABLE IF NOT EXISTS test_inner_postgres_types ( - /* ───────────── Integer family ───────────── */ + /* ------------- Integer family ------------- */ table_id int NOT NULL, serial_test serial , serial4_test serial4 , @@ -74,26 +74,26 @@ CREATE TABLE IF NOT EXISTS test_inner_postgres_types bigint_test bigint , smallint_test smallint , - /* ───────────── Floating‑point ───────────── */ + /* ------------- Floating-point ------------- */ float_test float , double_precision_test double precision , real_test real , - /* ───────────── Exact numeric ───────────── */ + /* ------------- Exact numeric ------------- */ numeric_test numeric(12, 4) , money_test money , - /* ───────────── Boolean ───────────── */ + /* ------------- Boolean ------------- */ bool_test boolean , - /* ───────────── JSON / JSONB ───────────── */ + /* ------------- JSON / JSONB ------------- */ json_test json , jsonb_test jsonb , - /* ───────────── Binary ───────────── */ + /* ------------- Binary ------------- */ bytea_test bytea , - /* ───────────── Date & time ───────────── */ + /* ------------- Date & time ------------- */ date_test date , time_test time , timetz_test timetz , @@ -101,23 +101,23 @@ CREATE TABLE IF NOT EXISTS test_inner_postgres_types timestamptz_test timestamptz , interval_test interval , - /* ───────────── Character / text ───────────── */ + /* ------------- Character / text ------------- */ text_test text , varchar_test varchar(255) , bpchar_test bpchar(10) , char_test char(1) , citext_test citext , - /* ───────────── UUID ───────────── */ + /* ------------- UUID ------------- */ uuid_test uuid , - /* ───────────── Network types ───────────── */ + /* ------------- Network types ------------- */ inet_test inet , cidr_test cidr , macaddr_test macaddr , macaddr8_test macaddr8 , - /* ───────────── LTree family ───────────── */ + /* ------------- LTree family ------------- */ ltree_test ltree , lquery_test lquery , ltxtquery_test ltxtquery @@ -136,4 +136,29 @@ CREATE TABLE IF NOT EXISTS test_type_override ( id integer PRIMARY KEY NOT NULL, text_test text -); \ No newline at end of file +); +DROP TABLE IF EXISTS test_enum_types; +DROP TABLE IF EXISTS test_enum_override; +DROP TYPE IF EXISTS test_mood; +CREATE TYPE test_mood AS ENUM ('sad', 'ok', 'happy'); + +CREATE TABLE test_enum_types +( + id int PRIMARY KEY NOT NULL, + mood test_mood NOT NULL, + maybe_mood test_mood +); + +CREATE TABLE test_enum_override +( + id int PRIMARY KEY NOT NULL, + mood_test test_mood NOT NULL +); + +-- :copyfrom into a table with an overridden column: the records must be +-- converted back to the driver type before copy_records_to_table. +CREATE TABLE IF NOT EXISTS test_copy_override +( + id bigint NOT NULL, + amount numeric NOT NULL +); diff --git a/test/driver_asyncpg/sqlc-gen-better-python.wasm b/test/driver_asyncpg/sqlc-gen-better-python.wasm index 56caaa4b..a0a8faab 100644 Binary files a/test/driver_asyncpg/sqlc-gen-better-python.wasm and b/test/driver_asyncpg/sqlc-gen-better-python.wasm differ diff --git a/test/driver_asyncpg/sqlc.yaml b/test/driver_asyncpg/sqlc.yaml index 90e1aee6..f38ec5e8 100644 --- a/test/driver_asyncpg/sqlc.yaml +++ b/test/driver_asyncpg/sqlc.yaml @@ -3,10 +3,13 @@ plugins: - name: python wasm: url: file://sqlc-gen-better-python.wasm - sha256: ee7bd0c07b784b80ea8c5853d9a6a04c51a7abbfd2663f470e9a5d2f623b967e + sha256: 0d564b87865b4733c9a41bd318277973c130fc02c32b5bfdb2a0b662f36148da sql: - schema: schema.sql - queries: queries.sql + queries: + - queries.sql + - queries_enum_override.sql + - queries_copy_override.sql engine: postgresql codegen: - out: /attrs/classes @@ -26,8 +29,17 @@ sql: import: collections package: UserString type: UserString + - column: test_enum_override.mood_test + py_type: + type: str + - column: test_copy_override.amount + py_type: + type: float - schema: schema.sql - queries: queries.sql + queries: + - queries.sql + - queries_enum_override.sql + - queries_copy_override.sql engine: postgresql codegen: - out: /attrs/functions @@ -47,8 +59,17 @@ sql: import: collections package: UserString type: UserString + - column: test_enum_override.mood_test + py_type: + type: str + - column: test_copy_override.amount + py_type: + type: float - schema: schema.sql - queries: queries.sql + queries: + - queries.sql + - queries_enum_override.sql + - queries_copy_override.sql engine: postgresql codegen: - out: /dataclass/classes @@ -67,8 +88,17 @@ sql: import: collections package: UserString type: UserString + - column: test_enum_override.mood_test + py_type: + type: str + - column: test_copy_override.amount + py_type: + type: float - schema: schema.sql - queries: queries.sql + queries: + - queries.sql + - queries_enum_override.sql + - queries_copy_override.sql engine: postgresql codegen: - out: /dataclass/functions @@ -87,8 +117,17 @@ sql: import: collections package: UserString type: UserString + - column: test_enum_override.mood_test + py_type: + type: str + - column: test_copy_override.amount + py_type: + type: float - schema: schema.sql - queries: queries.sql + queries: + - queries.sql + - queries_enum_override.sql + - queries_copy_override.sql engine: postgresql codegen: - out: /msgspec/classes @@ -107,8 +146,17 @@ sql: import: collections package: UserString type: UserString + - column: test_enum_override.mood_test + py_type: + type: str + - column: test_copy_override.amount + py_type: + type: float - schema: schema.sql - queries: queries.sql + queries: + - queries.sql + - queries_enum_override.sql + - queries_copy_override.sql engine: postgresql codegen: - out: /msgspec/functions @@ -127,4 +175,110 @@ sql: import: collections package: UserString type: UserString + - column: test_enum_override.mood_test + py_type: + type: str + - column: test_copy_override.amount + py_type: + type: float + + - schema: schema.sql + queries: + - queries.sql + - queries_enum_override.sql + - queries_copy_override.sql + engine: postgresql + codegen: + - out: /pydantic/classes + plugin: python + options: + package: test.driver_asyncpg.pydantic.classes + sql_driver: asyncpg + model_type: pydantic + emit_classes: true + omit_unused_models: true + emit_init_file: true + docstrings: google + overrides: + - column: test_type_override.text_test + py_type: + import: collections + package: UserString + type: UserString + - column: test_enum_override.mood_test + py_type: + type: str + - column: test_copy_override.amount + py_type: + type: float + - schema: schema.sql + queries: + - queries.sql + - queries_enum_override.sql + - queries_copy_override.sql + engine: postgresql + codegen: + - out: /pydantic/functions + plugin: python + options: + package: test.driver_asyncpg.pydantic.functions + sql_driver: asyncpg + model_type: pydantic + emit_classes: false + omit_unused_models: true + emit_init_file: true + docstrings: google + overrides: + - column: test_type_override.text_test + py_type: + import: collections + package: UserString + type: UserString + - column: test_enum_override.mood_test + py_type: + type: str + - column: test_copy_override.amount + py_type: + type: float + # omit_typechecking_block coverage: the driver hook and QueryResultsArgsType + # must stay runtime-safe when emitted at module level (PEP 695 aliases are + # lazy). Both modules are import-tested at runtime. + - schema: schema.sql + queries: queries_enum_override.sql + engine: postgresql + codegen: + - out: /omit_tc/classes + plugin: python + options: + package: test.driver_asyncpg.omit_tc.classes + sql_driver: asyncpg + model_type: dataclass + emit_classes: true + omit_unused_models: true + emit_init_file: true + omit_typechecking_block: true + docstrings: google + overrides: + - column: test_enum_override.mood_test + py_type: + type: str + - schema: schema.sql + queries: queries_enum_override.sql + engine: postgresql + codegen: + - out: /omit_tc/functions + plugin: python + options: + package: test.driver_asyncpg.omit_tc.functions + sql_driver: asyncpg + model_type: dataclass + emit_classes: false + omit_unused_models: true + emit_init_file: true + omit_typechecking_block: true + docstrings: google + overrides: + - column: test_enum_override.mood_test + py_type: + type: str diff --git a/test/driver_sqlite3/attrs/classes/__init__.py b/test/driver_sqlite3/attrs/classes/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_sqlite3/attrs/classes/__init__.py +++ b/test/driver_sqlite3/attrs/classes/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_sqlite3/attrs/classes/models.py b/test/driver_sqlite3/attrs/classes/models.py index 36327a67..ecb7ece5 100644 --- a/test/driver_sqlite3/attrs/classes/models.py +++ b/test/driver_sqlite3/attrs/classes/models.py @@ -1,12 +1,16 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( + "TestCaseSensitivity", "TestInnerSqliteType", + "TestOverrideConversion", + "TestReservedArg", "TestSqliteType", "TestTypeOverride", ) @@ -21,6 +25,23 @@ import decimal +@attrs.define() +class TestCaseSensitivity: + """Model representing TestCaseSensitivity. + + Attributes + ---------- + id_ : int + upper_dt : datetime.datetime + prec_dec : decimal.Decimal + + """ + + id_: int + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + + @attrs.define() class TestInnerSqliteType: """Model representing TestInnerSqliteType. @@ -90,13 +111,45 @@ class TestInnerSqliteType: json_test: str | None +@attrs.define() +class TestOverrideConversion: + """Model representing TestOverrideConversion. + + Attributes + ---------- + id_ : int + price : float + happened_at : datetime.datetime + + """ + + id_: int + price: float + happened_at: datetime.datetime + + +@attrs.define() +class TestReservedArg: + """Model representing TestReservedArg. + + Attributes + ---------- + id_ : int + conn : str + + """ + + id_: int + conn: str + + @attrs.define() class TestSqliteType: """Model representing TestSqliteType. Attributes ---------- - id : int + id_ : int int_test : int bigint_test : int smallint_test : int @@ -128,7 +181,7 @@ class TestSqliteType: """ - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -165,10 +218,10 @@ class TestTypeOverride: Attributes ---------- - id : int + id_ : int text_test : UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_sqlite3/attrs/classes/queries.py b/test/driver_sqlite3/attrs/classes/queries.py index d2f624c1..b1628d95 100644 --- a/test/driver_sqlite3/attrs/classes/queries.py +++ b/test/driver_sqlite3/attrs/classes/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -21,7 +23,7 @@ if typing.TYPE_CHECKING: import collections.abc - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None from test.driver_sqlite3.attrs.classes import models @@ -81,71 +83,74 @@ def _convert_memoryview(val: bytes) -> memoryview: sqlite3.register_converter("blob", _convert_memoryview) -CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows -CREATE TABLE test_create_rows_table -( - id int PRIMARY KEY NOT NULL, - test int NOT NULL -) -""" - -DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec -DELETE FROM test_inner_sqlite_types -WHERE test_inner_sqlite_types.table_id = ? +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ -DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? """ -DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec -DELETE -FROM test_type_override -WHERE test_type_override.id = ? +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ -GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many -SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many @@ -156,67 +161,46 @@ def _convert_memoryview(val: bytes) -> memoryview: SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? """ -GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? -""" - -GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? -""" - -GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? -""" - -GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? -""" - -GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one -SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? -""" - -GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one -SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = ? +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? """ -INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -231,37 +215,19 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec -INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? """ -INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec -INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -276,7 +242,27 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -291,35 +277,48 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec INSERT INTO test_type_override ( id, text_test ) VALUES (? ,?) """ -UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? """ -UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? """ -UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? """ +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" -T = typing.TypeVar("T") +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db. Parameters @@ -427,300 +426,240 @@ def conn(self) -> sqlite3.Connection: """ return self._conn - def create_rows_table(self) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + def insert_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Returns - ------- - int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - - """ - return self._conn.execute(CREATE_ROWS_TABLE).rowcount - - def delete_last_id_one_sqlite_type(self, *, id_: int) -> int | None: - """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - id_ : int - - Returns - ------- - int | None - The id of the last affected row. Will be `None` if no rows are affected. - - """ - return self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, )).lastrowid - - def delete_one_sqlite_type(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneSqliteType :exec`. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - id_ : int - - """ - self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, )) - - def delete_one_test_inner_sqlite_type(self, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. - - ```sql - DELETE FROM test_inner_sqlite_types - WHERE test_inner_sqlite_types.table_id = ? - ``` - - Parameters - ---------- - table_id : int - - """ - self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, )) - - def delete_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - id_ : int - - Returns - ------- - sqlite3.Cursor - The result returned when executing the query. - - """ - return self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, )) - - def delete_rows_one_sqlite_type(self, *, id_: int) -> int: - """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - id_ : int - - Returns - ------- - int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - - """ - return self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, )).rowcount - - def delete_type_override(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. - - ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = ? - ``` - - Parameters - ---------- - id_ : int - - """ - self._conn.execute(DELETE_TYPE_OVERRIDE, (id_, )) - - def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. - - ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Parameters ---------- id_ : int + int_test : int + bigint_test : int + smallint_test : int + tinyint_test : int + int2_test : int + int8_test : int + bigserial_test : int blob_test : memoryview - - Returns - ------- - QueryResults[memoryview] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[memoryview](self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) - - def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBool :many`. - - ```sql - SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? - ``` - - Parameters - ---------- - id_ : int - bool_test : bool - - Returns - ------- - QueryResults[bool] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[bool](self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) - - def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. - - ```sql - SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? - ``` - - Parameters - ---------- - id_ : int + real_test : float + double_test : float + double_precision_test : float + float_test : float + numeric_test : float + decimal_test : decimal.Decimal boolean_test : bool - - Returns - ------- - QueryResults[bool] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[bool](self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) - - def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: - """Fetch many from the db using the SQL query with `name: GetManyDate :many`. - - ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? - ``` - - Parameters - ---------- - id_ : int + bool_test : bool date_test : datetime.date - - Returns - ------- - QueryResults[datetime.date] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[datetime.date](self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) - - def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. - - ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? - ``` - - Parameters - ---------- - id_ : int datetime_test : datetime.datetime - - Returns - ------- - QueryResults[datetime.datetime] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) - - def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: - """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. - - ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? - ``` - - Parameters - ---------- - id_ : int - decimal_test : decimal.Decimal - - Returns - ------- - QueryResults[decimal.Decimal] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[decimal.Decimal](self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) - - def get_many_inner_sqlite_type(self, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? - ``` - - Parameters - ---------- - table_id : int - - Returns - ------- - QueryResults[models.TestInnerSqliteType] - Helper class that allows both iteration and normal fetching of data from the db. + timestamp_test : datetime.datetime + character_test : str + varchar_test : str + varyingcharacter_test : str + nchar_test : str + nativecharacter_test : str + nvarchar_test : str + text_test : str + clob_test : str + json_test : str """ - def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + self._conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) - def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. + def insert_one_inner_sqlite_type( + self, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, + ) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Parameters ---------- table_id : int int_test : int | None - - Returns - ------- - QueryResults[models.TestInnerSqliteType] - Helper class that allows both iteration and normal fetching of data from the db. + bigint_test : int | None + smallint_test : int | None + tinyint_test : int | None + int2_test : int | None + int8_test : int | None + bigserial_test : int | None + blob_test : memoryview | None + real_test : float | None + double_test : float | None + double_precision_test : float | None + float_test : float | None + numeric_test : float | None + decimal_test : decimal.Decimal | None + boolean_test : bool | None + bool_test : bool | None + date_test : datetime.date | None + datetime_test : datetime.datetime | None + timestamp_test : datetime.datetime | None + character_test : str | None + varchar_test : str | None + varyingcharacter_test : str | None + nchar_test : str | None + nativecharacter_test : str | None + nvarchar_test : str | None + text_test : str | None + clob_test : str | None + json_test : str | None """ - def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) - def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. + def get_one_sqlite_type(self, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. ```sql SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? @@ -732,95 +671,162 @@ def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteTyp Returns ------- - QueryResults[models.TestSqliteType] - Helper class that allows both iteration and normal fetching of data from the db. + models.TestSqliteType + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestSqliteType](self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + row = self._conn.execute(GET_ONE_SQLITE_TYPE, (id_,)).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) - def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Parameters ---------- - id_ : int + table_id : int Returns ------- - QueryResults[UserString] - Helper class that allows both iteration and normal fetching of data from the db. + models.TestInnerSqliteType + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> UserString: - return UserString(row[0]) - return QueryResults[UserString](self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + row = self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,)).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) - def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. + def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Parameters ---------- id_ : int - timestamp_test : datetime.datetime + date_test : datetime.date Returns ------- - QueryResults[datetime.datetime] - Helper class that allows both iteration and normal fetching of data from the db. + datetime.date + Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) + row = self._conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: - """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. + def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. ```sql - SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Parameters ---------- id_ : int + datetime_test : datetime.datetime Returns ------- - QueryResults[models.TestTypeOverride] - Helper class that allows both iteration and normal fetching of data from the db. + datetime.datetime + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - return QueryResults[models.TestTypeOverride](self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + row = self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() + if row is None: + return None + return row[0] - def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. + def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Parameters ---------- id_ : int - blob_test : memoryview + timestamp_test : datetime.datetime Returns ------- - memoryview + datetime.datetime Result fetched from the db. Will be `None` if not found. """ - row = self._conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() + row = self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() if row is None: return None return row[0] @@ -871,77 +877,107 @@ def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: return None return row[0] - def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: - """Fetch one from the db using the SQL query with `name: GetOneDate :one`. + def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Parameters ---------- id_ : int - date_test : datetime.date + decimal_test : decimal.Decimal Returns ------- - datetime.date + decimal.Decimal Result fetched from the db. Will be `None` if not found. """ - row = self._conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() + row = self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() if row is None: return None return row[0] - def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. + def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Parameters ---------- id_ : int - datetime_test : datetime.datetime + blob_test : memoryview Returns ------- - datetime.datetime + memoryview Result fetched from the db. Will be `None` if not found. """ - row = self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() + row = self._conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() if row is None: return None return row[0] - def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: - """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. + def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Parameters ---------- id_ : int - decimal_test : decimal.Decimal Returns ------- - decimal.Decimal - Result fetched from the db. Will be `None` if not found. + QueryResults[models.TestSqliteType] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() - if row is None: - return None - return row[0] - def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + + def get_many_inner_sqlite_type(self, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. ```sql SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? @@ -953,61 +989,142 @@ def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteT Returns ------- - models.TestInnerSqliteType - Result fetched from the db. Will be `None` if not found. + QueryResults[models.TestInnerSqliteType] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id, )).fetchone() - if row is None: - return None - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - def get_one_sqlite_type(self, *, id_: int) -> models.TestSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + + def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? + ``` + + Parameters + ---------- + table_id : int + int_test : int | None + + Returns + ------- + QueryResults[models.TestInnerSqliteType] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + + def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. + + ```sql + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Parameters ---------- id_ : int + date_test : datetime.date Returns ------- - models.TestSqliteType - Result fetched from the db. Will be `None` if not found. + QueryResults[datetime.date] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_SQLITE_TYPE, (id_, )).fetchone() - if row is None: - return None - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) - def get_one_text_type_override(self, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Parameters ---------- id_ : int + datetime_test : datetime.datetime Returns ------- - UserString - Result fetched from the db. Will be `None` if not found. + QueryResults[datetime.datetime] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_, )).fetchone() - if row is None: - return None - return UserString(row[0]) + return QueryResults(self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) - def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. + def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. ```sql SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? @@ -1020,150 +1137,157 @@ def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> d Returns ------- - datetime.datetime - Result fetched from the db. Will be `None` if not found. + QueryResults[datetime.datetime] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = ? + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? ``` Parameters ---------- id_ : int + bool_test : bool Returns ------- - models.TestTypeOverride - Result fetched from the db. Will be `None` if not found. + QueryResults[bool] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_, )).fetchone() - if row is None: - return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) + return QueryResults(self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) - def insert_last_id_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int | None: - """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. + def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. ```sql - INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? ``` Parameters ---------- id_ : int - int_test : int - bigint_test : int - smallint_test : int - tinyint_test : int - int2_test : int - int8_test : int - bigserial_test : int - blob_test : memoryview - real_test : float - double_test : float - double_precision_test : float - float_test : float - numeric_test : float - decimal_test : decimal.Decimal boolean_test : bool - bool_test : bool - date_test : datetime.date - datetime_test : datetime.datetime - timestamp_test : datetime.datetime - character_test : str - varchar_test : str - varyingcharacter_test : str - nchar_test : str - nativecharacter_test : str - nvarchar_test : str - text_test : str - clob_test : str - json_test : str Returns ------- - int | None - The id of the last affected row. Will be `None` if no rows are affected. + QueryResults[bool] + Helper class that allows both iteration and normal fetching of data from the db. """ - return self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)).lastrowid + return QueryResults(self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) - def insert_one_inner_sqlite_type(self, *, table_id: int, int_test: int | None, bigint_test: int | None, smallint_test: int | None, tinyint_test: int | None, int2_test: int | None, int8_test: int | None, bigserial_test: int | None, blob_test: memoryview | None, real_test: float | None, double_test: float | None, double_precision_test: float | None, float_test: float | None, numeric_test: float | None, decimal_test: decimal.Decimal | None, boolean_test: bool | None, bool_test: bool | None, date_test: datetime.date | None, datetime_test: datetime.datetime | None, timestamp_test: datetime.datetime | None, character_test: str | None, varchar_test: str | None, varyingcharacter_test: str | None, nchar_test: str | None, nativecharacter_test: str | None, nvarchar_test: str | None, text_test: str | None, clob_test: str | None, json_test: str | None) -> None: - """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. + def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. ```sql - INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Parameters ---------- - table_id : int - int_test : int | None - bigint_test : int | None - smallint_test : int | None - tinyint_test : int | None - int2_test : int | None - int8_test : int | None - bigserial_test : int | None - blob_test : memoryview | None - real_test : float | None - double_test : float | None - double_precision_test : float | None - float_test : float | None - numeric_test : float | None - decimal_test : decimal.Decimal | None - boolean_test : bool | None - bool_test : bool | None - date_test : datetime.date | None - datetime_test : datetime.datetime | None - timestamp_test : datetime.datetime | None - character_test : str | None - varchar_test : str | None - varyingcharacter_test : str | None - nchar_test : str | None - nativecharacter_test : str | None - nvarchar_test : str | None - text_test : str | None - clob_test : str | None - json_test : str | None + id_ : int + decimal_test : decimal.Decimal + + Returns + ------- + QueryResults[decimal.Decimal] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + return QueryResults(self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. + + ```sql + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + ``` + + Parameters + ---------- + id_ : int + blob_test : memoryview + + Returns + ------- + QueryResults[memoryview] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + return QueryResults(self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + + def delete_one_sqlite_type(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int """ - self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, (table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) - def insert_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> None: - """Execute SQL query with `name: InsertOneSqliteType :exec`. + def delete_one_test_inner_sqlite_type(self, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + + ```sql + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? + ``` + + Parameters + ---------- + table_id : int + + """ + self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) + + def insert_result_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. ```sql INSERT INTO test_sqlite_types ( @@ -1212,11 +1336,121 @@ def insert_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, s clob_test : str json_test : str + Returns + ------- + sqlite3.Cursor + The result returned when executing the query. + """ - self._conn.execute(INSERT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) - def insert_result_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. + def update_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + sqlite3.Cursor + The result returned when executing the query. + + """ + return self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + def delete_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + sqlite3.Cursor + The result returned when executing the query. + + """ + return self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + def insert_rows_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. ```sql INSERT INTO test_sqlite_types ( @@ -1267,14 +1501,138 @@ def insert_result_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: Returns ------- - sqlite3.Cursor - The result returned when executing the query. + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - return self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args).rowcount - def insert_rows_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int: - """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. + def update_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + + """ + return self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + def delete_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + + """ + return self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + def create_rows_table(self) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Returns + ------- + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + + """ + return self._conn.execute(CREATE_ROWS_TABLE).rowcount + + def insert_last_id_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. ```sql INSERT INTO test_sqlite_types ( @@ -1326,10 +1684,83 @@ def insert_rows_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: i Returns ------- int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + The id of the last affected row. Will be `None` if no rows are affected. + + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args).lastrowid + + def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + int + The id of the last affected row. Will be `None` if no rows are affected. + + """ + return self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid + + def delete_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + int + The id of the last affected row. Will be `None` if no rows are affected. """ - return self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)).rowcount + return self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: """Execute SQL query with `name: InsertTypeOverride :exec`. @@ -1346,15 +1777,13 @@ def insert_type_override(self, *, id_: int, text_test: UserString | None) -> Non text_test : UserString | None """ - self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test))) + self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) - def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: - """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE id = ? ``` Parameters @@ -1363,19 +1792,20 @@ def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: Returns ------- - int | None - The id of the last affected row. Will be `None` if no rows are affected. + models.TestTypeOverride + Result fetched from the db. Will be `None` if not found. """ - return self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_, )).lastrowid + row = self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - def update_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? ``` Parameters @@ -1384,19 +1814,21 @@ def update_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: Returns ------- - sqlite3.Cursor - The result returned when executing the query. + QueryResults[models.TestTypeOverride] + Helper class that allows both iteration and normal fetching of data from the db. """ - return self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_, )) - def update_rows_one_sqlite_type(self, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + def get_one_text_type_override(self, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? ``` Parameters @@ -1405,8 +1837,50 @@ def update_rows_one_sqlite_type(self, *, id_: int) -> int: Returns ------- - int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + UserString + Result fetched from the db. Will be `None` if not found. + + """ + row = self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + QueryResults[UserString | None] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + def delete_type_override(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Parameters + ---------- + id_ : int """ - return self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_, )).rowcount + self._conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_sqlite3/attrs/classes/queries_case.py b/test/driver_sqlite3/attrs/classes/queries_case.py new file mode 100644 index 00000000..6428d218 --- /dev/null +++ b/test/driver_sqlite3/attrs/classes/queries_case.py @@ -0,0 +1,182 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_case.sql +"""Module containing queries from file queries_case.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "GetCaseRowRow", + "QueriesCase", +) + +import attrs +import ciso8601 +import datetime +import decimal +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _convert_decimal(val: bytes) -> decimal.Decimal: + return decimal.Decimal(val.decode()) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return ciso8601.parse_datetime(val.decode()) + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + +sqlite3.register_converter("decimal", _convert_decimal) +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +@attrs.define() +class GetCaseRowRow: + """Model representing GetCaseRowRow. + + Attributes + ---------- + upper_dt : datetime.datetime + prec_dec : decimal.Decimal + + """ + + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + + +INSERT_CASE_ROW: typing.Final[str] = """-- name: InsertCaseRow :exec +INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) +""" + +GET_CASE_ROW: typing.Final[str] = """-- name: GetCaseRow :one +SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? +""" + +INSERT_RESERVED_ARG: typing.Final[str] = """-- name: InsertReservedArg :exec +INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) +""" + +GET_RESERVED_ARG: typing.Final[str] = """-- name: GetReservedArg :one +SELECT id FROM test_reserved_args WHERE conn = ? +""" + + +class QueriesCase: + """Queries from file queries_case.sql. + + Parameters + ---------- + conn : sqlite3.Connection + The connection object used to execute queries. + + """ + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection.""" + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns + ------- + sqlite3.Connection + + """ + return self._conn + + def insert_case_row(self, *, id_: int, upper_dt: datetime.datetime, prec_dec: decimal.Decimal) -> None: + """Execute SQL query with `name: InsertCaseRow :exec`. + + ```sql + INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) + ``` + + Parameters + ---------- + id_ : int + upper_dt : datetime.datetime + prec_dec : decimal.Decimal + + """ + self._conn.execute(INSERT_CASE_ROW, (id_, upper_dt, prec_dec)) + + def get_case_row(self, *, id_: int) -> GetCaseRowRow | None: + """Fetch one from the db using the SQL query with `name: GetCaseRow :one`. + + ```sql + SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + GetCaseRowRow + Result fetched from the db. Will be `None` if not found. + + """ + row = self._conn.execute(GET_CASE_ROW, (id_,)).fetchone() + if row is None: + return None + return GetCaseRowRow(upper_dt=row[0], prec_dec=row[1]) + + def insert_reserved_arg(self, *, id_: int, conn: str) -> None: + """Execute SQL query with `name: InsertReservedArg :exec`. + + ```sql + INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) + ``` + + Parameters + ---------- + id_ : int + conn : str + + """ + self._conn.execute(INSERT_RESERVED_ARG, (id_, conn)) + + def get_reserved_arg(self, *, conn: str) -> int | None: + """Fetch one from the db using the SQL query with `name: GetReservedArg :one`. + + ```sql + SELECT id FROM test_reserved_args WHERE conn = ? + ``` + + Parameters + ---------- + conn : str + + Returns + ------- + int + Result fetched from the db. Will be `None` if not found. + + """ + row = self._conn.execute(GET_RESERVED_ARG, (conn,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/attrs/classes/queries_override_adapter.py b/test/driver_sqlite3/attrs/classes/queries_override_adapter.py new file mode 100644 index 00000000..36cad38e --- /dev/null +++ b/test/driver_sqlite3/attrs/classes/queries_override_adapter.py @@ -0,0 +1,105 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_adapter.sql +"""Module containing queries from file queries_override_adapter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("QueriesOverrideAdapter",) + +import datetime +import decimal +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + + +INSERT_OVERRIDE_CONVERSION: typing.Final[str] = """-- name: InsertOverrideConversion :exec +INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) +""" + +GET_OVERRIDE_PRICE: typing.Final[str] = """-- name: GetOverridePrice :one +SELECT price FROM test_override_conversion WHERE id = ? +""" + + +class QueriesOverrideAdapter: + """Queries from file queries_override_adapter.sql. + + Parameters + ---------- + conn : sqlite3.Connection + The connection object used to execute queries. + + """ + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection.""" + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns + ------- + sqlite3.Connection + + """ + return self._conn + + def insert_override_conversion(self, *, id_: int, price: float, happened_at: datetime.datetime) -> None: + """Execute SQL query with `name: InsertOverrideConversion :exec`. + + ```sql + INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) + ``` + + Parameters + ---------- + id_ : int + price : float + happened_at : datetime.datetime + + """ + self._conn.execute(INSERT_OVERRIDE_CONVERSION, (id_, decimal.Decimal(price), happened_at)) + + def get_override_price(self, *, id_: int) -> float | None: + """Fetch one from the db using the SQL query with `name: GetOverridePrice :one`. + + ```sql + SELECT price FROM test_override_conversion WHERE id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + float + Result fetched from the db. Will be `None` if not found. + + """ + row = self._conn.execute(GET_OVERRIDE_PRICE, (id_,)).fetchone() + if row is None: + return None + return float(row[0]) diff --git a/test/driver_sqlite3/attrs/classes/queries_override_converter.py b/test/driver_sqlite3/attrs/classes/queries_override_converter.py new file mode 100644 index 00000000..602d1b8e --- /dev/null +++ b/test/driver_sqlite3/attrs/classes/queries_override_converter.py @@ -0,0 +1,81 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_converter.sql +"""Module containing queries from file queries_override_converter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("QueriesOverrideConverter",) + +import ciso8601 +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + import datetime + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return ciso8601.parse_datetime(val.decode()) + + +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +GET_OVERRIDE_HAPPENED_AT: typing.Final[str] = """-- name: GetOverrideHappenedAt :one +SELECT happened_at FROM test_override_conversion WHERE id = ? +""" + + +class QueriesOverrideConverter: + """Queries from file queries_override_converter.sql. + + Parameters + ---------- + conn : sqlite3.Connection + The connection object used to execute queries. + + """ + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection.""" + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns + ------- + sqlite3.Connection + + """ + return self._conn + + def get_override_happened_at(self, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOverrideHappenedAt :one`. + + ```sql + SELECT happened_at FROM test_override_conversion WHERE id = ? + ``` + + Parameters + ---------- + id_ : int + + Returns + ------- + datetime.datetime + Result fetched from the db. Will be `None` if not found. + + """ + row = self._conn.execute(GET_OVERRIDE_HAPPENED_AT, (id_,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/attrs/functions/__init__.py b/test/driver_sqlite3/attrs/functions/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_sqlite3/attrs/functions/__init__.py +++ b/test/driver_sqlite3/attrs/functions/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_sqlite3/attrs/functions/models.py b/test/driver_sqlite3/attrs/functions/models.py index 36327a67..988c54ce 100644 --- a/test/driver_sqlite3/attrs/functions/models.py +++ b/test/driver_sqlite3/attrs/functions/models.py @@ -1,8 +1,9 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -96,7 +97,7 @@ class TestSqliteType: Attributes ---------- - id : int + id_ : int int_test : int bigint_test : int smallint_test : int @@ -128,7 +129,7 @@ class TestSqliteType: """ - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -165,10 +166,10 @@ class TestTypeOverride: Attributes ---------- - id : int + id_ : int text_test : UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_sqlite3/attrs/functions/queries.py b/test/driver_sqlite3/attrs/functions/queries.py index 658aa929..ada7af2f 100644 --- a/test/driver_sqlite3/attrs/functions/queries.py +++ b/test/driver_sqlite3/attrs/functions/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -58,7 +60,7 @@ if typing.TYPE_CHECKING: import collections.abc - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None from test.driver_sqlite3.attrs.functions import models @@ -118,71 +120,74 @@ def _convert_memoryview(val: bytes) -> memoryview: sqlite3.register_converter("blob", _convert_memoryview) -CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows -CREATE TABLE test_create_rows_table -( - id int PRIMARY KEY NOT NULL, - test int NOT NULL -) -""" - -DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec -DELETE FROM test_inner_sqlite_types -WHERE test_inner_sqlite_types.table_id = ? +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ -DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? """ -DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec -DELETE -FROM test_type_override -WHERE test_type_override.id = ? +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ -GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many -SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many @@ -193,67 +198,46 @@ def _convert_memoryview(val: bytes) -> memoryview: SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? """ -GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? -""" - -GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? -""" - -GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? -""" - -GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? -""" - -GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one -SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? -""" - -GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one -SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = ? +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? """ -INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -268,37 +252,19 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec -INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? """ -INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec -INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -313,7 +279,27 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -328,35 +314,48 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec INSERT INTO test_type_override ( id, text_test ) VALUES (? ,?) """ -UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? """ -UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? """ -UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? """ +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" -T = typing.TypeVar("T") +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db. Parameters @@ -437,62 +436,54 @@ def __next__(self) -> T: return self._decode_hook(record) -def create_rows_table(conn: sqlite3.Connection) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. +def insert_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Parameters - ---------- - conn : sqlite3.Connection - Connection object of type `sqlite3.Connection` used to execute the query. - - Returns - ------- - int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - - """ - return conn.execute(CREATE_ROWS_TABLE).rowcount - - -def delete_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: - """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - conn : sqlite3.Connection - Connection object of type `sqlite3.Connection` used to execute the query. - id_ : int - - Returns - ------- - int | None - The id of the last affected row. Will be `None` if no rows are affected. - - """ - return conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, )).lastrowid - - -def delete_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneSqliteType :exec`. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Parameters @@ -500,17 +491,118 @@ def delete_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> None: conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int + int_test : int + bigint_test : int + smallint_test : int + tinyint_test : int + int2_test : int + int8_test : int + bigserial_test : int + blob_test : memoryview + real_test : float + double_test : float + double_precision_test : float + float_test : float + numeric_test : float + decimal_test : decimal.Decimal + boolean_test : bool + bool_test : bool + date_test : datetime.date + datetime_test : datetime.datetime + timestamp_test : datetime.datetime + character_test : str + varchar_test : str + varyingcharacter_test : str + nchar_test : str + nativecharacter_test : str + nvarchar_test : str + text_test : str + clob_test : str + json_test : str """ - conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, )) - - -def delete_one_test_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) + + +def insert_one_inner_sqlite_type( + conn: sqlite3.Connection, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, +) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. ```sql - DELETE FROM test_inner_sqlite_types - WHERE test_inner_sqlite_types.table_id = ? + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Parameters @@ -518,106 +610,75 @@ def delete_one_test_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. table_id : int + int_test : int | None + bigint_test : int | None + smallint_test : int | None + tinyint_test : int | None + int2_test : int | None + int8_test : int | None + bigserial_test : int | None + blob_test : memoryview | None + real_test : float | None + double_test : float | None + double_precision_test : float | None + float_test : float | None + numeric_test : float | None + decimal_test : decimal.Decimal | None + boolean_test : bool | None + bool_test : bool | None + date_test : datetime.date | None + datetime_test : datetime.datetime | None + timestamp_test : datetime.datetime | None + character_test : str | None + varchar_test : str | None + varyingcharacter_test : str | None + nchar_test : str | None + nativecharacter_test : str | None + nvarchar_test : str | None + text_test : str | None + clob_test : str | None + json_test : str | None """ - conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, )) - - -def delete_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - conn : sqlite3.Connection - Connection object of type `sqlite3.Connection` used to execute the query. - id_ : int - - Returns - ------- - sqlite3.Cursor - The result returned when executing the query. - - """ - return conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, )) - - -def delete_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: - """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? - ``` - - Parameters - ---------- - conn : sqlite3.Connection - Connection object of type `sqlite3.Connection` used to execute the query. - id_ : int - - Returns - ------- - int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - - """ - return conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, )).rowcount - - -def delete_type_override(conn: sqlite3.Connection, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. - - ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = ? - ``` - - Parameters - ---------- - conn : sqlite3.Connection - Connection object of type `sqlite3.Connection` used to execute the query. - id_ : int - - """ - conn.execute(DELETE_TYPE_OVERRIDE, (id_, )) - - -def get_many_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. - - ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? - ``` - - Parameters - ---------- - conn : sqlite3.Connection - Connection object of type `sqlite3.Connection` used to execute the query. - id_ : int - blob_test : memoryview - - Returns - ------- - QueryResults[memoryview] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[memoryview](conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) -def get_many_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBool :many`. +def get_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. ```sql - SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Parameters @@ -625,42 +686,106 @@ def get_many_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> Que conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int - bool_test : bool Returns ------- - QueryResults[bool] - Helper class that allows both iteration and normal fetching of data from the db. + models.TestSqliteType + Result fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + row = conn.execute(GET_ONE_SQLITE_TYPE, (id_,)).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) -def get_many_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. +def get_one_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. ```sql - SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Parameters ---------- conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. - id_ : int - boolean_test : bool + table_id : int Returns ------- - QueryResults[bool] - Helper class that allows both iteration and normal fetching of data from the db. + models.TestInnerSqliteType + Result fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + row = conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,)).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) -def get_many_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: - """Fetch many from the db using the SQL query with `name: GetManyDate :many`. +def get_one_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. ```sql SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? @@ -675,15 +800,18 @@ def get_many_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.dat Returns ------- - QueryResults[datetime.date] - Helper class that allows both iteration and normal fetching of data from the db. + datetime.date + Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.date](conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + row = conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. +def get_one_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. ```sql SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? @@ -698,114 +826,21 @@ def get_many_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: date Returns ------- - QueryResults[datetime.datetime] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[datetime.datetime](conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) - - -def get_many_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: - """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. - - ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? - ``` - - Parameters - ---------- - conn : sqlite3.Connection - Connection object of type `sqlite3.Connection` used to execute the query. - id_ : int - decimal_test : decimal.Decimal - - Returns - ------- - QueryResults[decimal.Decimal] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - return QueryResults[decimal.Decimal](conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) - - -def get_many_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? - ``` - - Parameters - ---------- - conn : sqlite3.Connection - Connection object of type `sqlite3.Connection` used to execute the query. - table_id : int - - Returns - ------- - QueryResults[models.TestInnerSqliteType] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) - - -def get_many_nullable_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? - ``` - - Parameters - ---------- - conn : sqlite3.Connection - Connection object of type `sqlite3.Connection` used to execute the query. - table_id : int - int_test : int | None - - Returns - ------- - QueryResults[models.TestInnerSqliteType] - Helper class that allows both iteration and normal fetching of data from the db. - - """ - def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) - - -def get_many_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. - - ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? - ``` - - Parameters - ---------- - conn : sqlite3.Connection - Connection object of type `sqlite3.Connection` used to execute the query. - id_ : int - - Returns - ------- - QueryResults[models.TestSqliteType] - Helper class that allows both iteration and normal fetching of data from the db. + datetime.datetime + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestSqliteType](conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + row = conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_text_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. +def get_one_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Parameters @@ -813,23 +848,25 @@ def get_many_text_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryR conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int + timestamp_test : datetime.datetime Returns ------- - QueryResults[UserString] - Helper class that allows both iteration and normal fetching of data from the db. + datetime.datetime + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> UserString: - return UserString(row[0]) - return QueryResults[UserString](conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + row = conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. +def get_one_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? ``` Parameters @@ -837,22 +874,25 @@ def get_many_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: da conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int - timestamp_test : datetime.datetime + bool_test : bool Returns ------- - QueryResults[datetime.datetime] - Helper class that allows both iteration and normal fetching of data from the db. + bool + Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.datetime](conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) + row = conn.execute(GET_ONE_BOOL, (id_, bool_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: - """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. +def get_one_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. ```sql - SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? ``` Parameters @@ -860,23 +900,25 @@ def get_many_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResult conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int + boolean_test : bool Returns ------- - QueryResults[models.TestTypeOverride] - Helper class that allows both iteration and normal fetching of data from the db. + bool + Result fetched from the db. Will be `None` if not found. """ - def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - return QueryResults[models.TestTypeOverride](conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + row = conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test)).fetchone() + if row is None: + return None + return row[0] -def get_one_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. +def get_one_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Parameters @@ -884,25 +926,25 @@ def get_one_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) - conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int - blob_test : memoryview + decimal_test : decimal.Decimal Returns ------- - memoryview + decimal.Decimal Result fetched from the db. Will be `None` if not found. """ - row = conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() + row = conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() if row is None: return None return row[0] -def get_one_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBool :one`. +def get_one_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. ```sql - SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Parameters @@ -910,25 +952,25 @@ def get_one_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> bool conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int - bool_test : bool + blob_test : memoryview Returns ------- - bool + memoryview Result fetched from the db. Will be `None` if not found. """ - row = conn.execute(GET_ONE_BOOL, (id_, bool_test)).fetchone() + row = conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() if row is None: return None return row[0] -def get_one_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. +def get_many_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. ```sql - SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Parameters @@ -936,77 +978,168 @@ def get_one_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) - conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int - boolean_test : bool Returns ------- - bool - Result fetched from the db. Will be `None` if not found. + QueryResults[models.TestSqliteType] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test)).fetchone() - if row is None: - return None - return row[0] + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) -def get_one_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: - """Fetch one from the db using the SQL query with `name: GetOneDate :one`. + +def get_many_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Parameters ---------- conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. - id_ : int - date_test : datetime.date + table_id : int Returns ------- - datetime.date - Result fetched from the db. Will be `None` if not found. + QueryResults[models.TestInnerSqliteType] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() - if row is None: - return None - return row[0] + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) -def get_one_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. +def get_many_nullable_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? ``` Parameters ---------- conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. - id_ : int - datetime_test : datetime.datetime + table_id : int + int_test : int | None Returns ------- - datetime.datetime - Result fetched from the db. Will be `None` if not found. + QueryResults[models.TestInnerSqliteType] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() - if row is None: - return None - return row[0] + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) -def get_one_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: - """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. +def get_many_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Parameters @@ -1014,50 +1147,45 @@ def get_one_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int - decimal_test : decimal.Decimal + date_test : datetime.date Returns ------- - decimal.Decimal - Result fetched from the db. Will be `None` if not found. + QueryResults[datetime.date] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) -def get_one_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. +def get_many_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Parameters ---------- conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. - table_id : int + id_ : int + datetime_test : datetime.datetime Returns ------- - models.TestInnerSqliteType - Result fetched from the db. Will be `None` if not found. + QueryResults[datetime.datetime] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id, )).fetchone() - if row is None: - return None - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) -def get_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> models.TestSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. +def get_many_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Parameters @@ -1065,24 +1193,22 @@ def get_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> models.TestSql conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int + timestamp_test : datetime.datetime Returns ------- - models.TestSqliteType - Result fetched from the db. Will be `None` if not found. + QueryResults[datetime.datetime] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_SQLITE_TYPE, (id_, )).fetchone() - if row is None: - return None - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) -def get_one_text_type_override(conn: sqlite3.Connection, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. +def get_many_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? ``` Parameters @@ -1090,24 +1216,22 @@ def get_one_text_type_override(conn: sqlite3.Connection, *, id_: int) -> UserStr conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int + bool_test : bool Returns ------- - UserString - Result fetched from the db. Will be `None` if not found. + QueryResults[bool] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_, )).fetchone() - if row is None: - return None - return UserString(row[0]) + return QueryResults(conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) -def get_one_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. +def get_many_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? ``` Parameters @@ -1115,25 +1239,22 @@ def get_one_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: dat conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int - timestamp_test : datetime.datetime + boolean_test : bool Returns ------- - datetime.datetime - Result fetched from the db. Will be `None` if not found. + QueryResults[bool] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) -def get_one_type_override(conn: sqlite3.Connection, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. +def get_many_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Parameters @@ -1141,35 +1262,22 @@ def get_one_type_override(conn: sqlite3.Connection, *, id_: int) -> models.TestT conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int + decimal_test : decimal.Decimal Returns ------- - models.TestTypeOverride - Result fetched from the db. Will be `None` if not found. + QueryResults[decimal.Decimal] + Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_TYPE_OVERRIDE, (id_, )).fetchone() - if row is None: - return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) + return QueryResults(conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) -def insert_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int | None: - """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. +def get_many_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. ```sql - INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Parameters @@ -1177,102 +1285,88 @@ def insert_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_te conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. id_ : int - int_test : int - bigint_test : int - smallint_test : int - tinyint_test : int - int2_test : int - int8_test : int - bigserial_test : int blob_test : memoryview - real_test : float - double_test : float - double_precision_test : float - float_test : float - numeric_test : float - decimal_test : decimal.Decimal - boolean_test : bool - bool_test : bool - date_test : datetime.date - datetime_test : datetime.datetime - timestamp_test : datetime.datetime - character_test : str - varchar_test : str - varyingcharacter_test : str - nchar_test : str - nativecharacter_test : str - nvarchar_test : str - text_test : str - clob_test : str - json_test : str Returns ------- - int | None - The id of the last affected row. Will be `None` if no rows are affected. + QueryResults[memoryview] + Helper class that allows both iteration and normal fetching of data from the db. """ - return conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)).lastrowid + return QueryResults(conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) -def insert_one_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int, int_test: int | None, bigint_test: int | None, smallint_test: int | None, tinyint_test: int | None, int2_test: int | None, int8_test: int | None, bigserial_test: int | None, blob_test: memoryview | None, real_test: float | None, double_test: float | None, double_precision_test: float | None, float_test: float | None, numeric_test: float | None, decimal_test: decimal.Decimal | None, boolean_test: bool | None, bool_test: bool | None, date_test: datetime.date | None, datetime_test: datetime.datetime | None, timestamp_test: datetime.datetime | None, character_test: str | None, varchar_test: str | None, varyingcharacter_test: str | None, nchar_test: str | None, nativecharacter_test: str | None, nvarchar_test: str | None, text_test: str | None, clob_test: str | None, json_test: str | None) -> None: - """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. +def delete_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. ```sql - INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? ``` Parameters ---------- conn : sqlite3.Connection Connection object of type `sqlite3.Connection` used to execute the query. - table_id : int - int_test : int | None - bigint_test : int | None - smallint_test : int | None - tinyint_test : int | None - int2_test : int | None - int8_test : int | None - bigserial_test : int | None - blob_test : memoryview | None - real_test : float | None - double_test : float | None - double_precision_test : float | None - float_test : float | None - numeric_test : float | None - decimal_test : decimal.Decimal | None - boolean_test : bool | None - bool_test : bool | None - date_test : datetime.date | None - datetime_test : datetime.datetime | None - timestamp_test : datetime.datetime | None - character_test : str | None - varchar_test : str | None - varyingcharacter_test : str | None - nchar_test : str | None - nativecharacter_test : str | None - nvarchar_test : str | None - text_test : str | None - clob_test : str | None - json_test : str | None + id_ : int """ - conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, (table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) -def insert_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> None: - """Execute SQL query with `name: InsertOneSqliteType :exec`. +def delete_one_test_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + + ```sql + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + table_id : int + + """ + conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) + + +def insert_result_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. ```sql INSERT INTO test_sqlite_types ( @@ -1323,12 +1417,128 @@ def insert_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, clob_test : str json_test : str + Returns + ------- + sqlite3.Cursor + The result returned when executing the query. + """ - conn.execute(INSERT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) -def insert_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. +def update_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + + Returns + ------- + sqlite3.Cursor + The result returned when executing the query. + + """ + return conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +def delete_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + + Returns + ------- + sqlite3.Cursor + The result returned when executing the query. + + """ + return conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +def insert_rows_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. ```sql INSERT INTO test_sqlite_types ( @@ -1381,15 +1591,151 @@ def insert_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_tes Returns ------- - sqlite3.Cursor - The result returned when executing the query. + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - return conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args).rowcount -def insert_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int: - """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. +def update_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + + Returns + ------- + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + + """ + return conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + +def delete_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + + Returns + ------- + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + + """ + return conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + +def create_rows_table(conn: sqlite3.Connection) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + + Returns + ------- + int + The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + + """ + return conn.execute(CREATE_ROWS_TABLE).rowcount + + +def insert_last_id_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. ```sql INSERT INTO test_sqlite_types ( @@ -1443,10 +1789,89 @@ def insert_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: Returns ------- int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + The id of the last affected row. Will be `None` if no rows are affected. + + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args).lastrowid + + +def update_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + + Returns + ------- + int + The id of the last affected row. Will be `None` if no rows are affected. + + """ + return conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid + + +def delete_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + + Returns + ------- + int + The id of the last affected row. Will be `None` if no rows are affected. """ - return conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)).rowcount + return conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid def insert_type_override(conn: sqlite3.Connection, *, id_: int, text_test: UserString | None) -> None: @@ -1466,16 +1891,14 @@ def insert_type_override(conn: sqlite3.Connection, *, id_: int, text_test: UserS text_test : UserString | None """ - conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test))) + conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) -def update_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: - """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. +def get_one_type_override(conn: sqlite3.Connection, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE id = ? ``` Parameters @@ -1486,20 +1909,21 @@ def update_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int Returns ------- - int | None - The id of the last affected row. Will be `None` if no rows are affected. + models.TestTypeOverride + Result fetched from the db. Will be `None` if not found. """ - return conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_, )).lastrowid + row = conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) -def update_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. +def get_many_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? ``` Parameters @@ -1510,20 +1934,22 @@ def update_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqli Returns ------- - sqlite3.Cursor - The result returned when executing the query. + QueryResults[models.TestTypeOverride] + Helper class that allows both iteration and normal fetching of data from the db. """ - return conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_, )) + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) -def update_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + return QueryResults(conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + +def get_one_text_type_override(conn: sqlite3.Connection, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? ``` Parameters @@ -1534,8 +1960,56 @@ def update_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: Returns ------- - int - The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + UserString + Result fetched from the db. Will be `None` if not found. + + """ + row = conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + +def get_many_text_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + + Returns + ------- + QueryResults[UserString | None] + Helper class that allows both iteration and normal fetching of data from the db. + + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + +def delete_type_override(conn: sqlite3.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int """ - return conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_, )).rowcount + conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_sqlite3/attrs/functions/queries_case.py b/test/driver_sqlite3/attrs/functions/queries_case.py new file mode 100644 index 00000000..ba8380d9 --- /dev/null +++ b/test/driver_sqlite3/attrs/functions/queries_case.py @@ -0,0 +1,168 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_case.sql +"""Module containing queries from file queries_case.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "GetCaseRowRow", + "get_case_row", + "get_reserved_arg", + "insert_case_row", + "insert_reserved_arg", +) + +import attrs +import datetime +import decimal +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _convert_decimal(val: bytes) -> decimal.Decimal: + return decimal.Decimal(val.decode()) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + +sqlite3.register_converter("decimal", _convert_decimal) +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +@attrs.define() +class GetCaseRowRow: + """Model representing GetCaseRowRow. + + Attributes + ---------- + upper_dt : datetime.datetime + prec_dec : decimal.Decimal + + """ + + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + + +INSERT_CASE_ROW: typing.Final[str] = """-- name: InsertCaseRow :exec +INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) +""" + +GET_CASE_ROW: typing.Final[str] = """-- name: GetCaseRow :one +SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? +""" + +INSERT_RESERVED_ARG: typing.Final[str] = """-- name: InsertReservedArg :exec +INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) +""" + +GET_RESERVED_ARG: typing.Final[str] = """-- name: GetReservedArg :one +SELECT id FROM test_reserved_args WHERE conn = ? +""" + + +def insert_case_row(conn: sqlite3.Connection, *, id_: int, upper_dt: datetime.datetime, prec_dec: decimal.Decimal) -> None: + """Execute SQL query with `name: InsertCaseRow :exec`. + + ```sql + INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + upper_dt : datetime.datetime + prec_dec : decimal.Decimal + + """ + conn.execute(INSERT_CASE_ROW, (id_, upper_dt, prec_dec)) + + +def get_case_row(conn: sqlite3.Connection, *, id_: int) -> GetCaseRowRow | None: + """Fetch one from the db using the SQL query with `name: GetCaseRow :one`. + + ```sql + SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + + Returns + ------- + GetCaseRowRow + Result fetched from the db. Will be `None` if not found. + + """ + row = conn.execute(GET_CASE_ROW, (id_,)).fetchone() + if row is None: + return None + return GetCaseRowRow(upper_dt=row[0], prec_dec=row[1]) + + +def insert_reserved_arg(conn: sqlite3.Connection, *, id_: int, conn_2: str) -> None: + """Execute SQL query with `name: InsertReservedArg :exec`. + + ```sql + INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + conn_2 : str + + """ + conn.execute(INSERT_RESERVED_ARG, (id_, conn_2)) + + +def get_reserved_arg(conn: sqlite3.Connection, *, conn_2: str) -> int | None: + """Fetch one from the db using the SQL query with `name: GetReservedArg :one`. + + ```sql + SELECT id FROM test_reserved_args WHERE conn = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + conn_2 : str + + Returns + ------- + int + Result fetched from the db. Will be `None` if not found. + + """ + row = conn.execute(GET_RESERVED_ARG, (conn_2,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/attrs/functions/queries_override_adapter.py b/test/driver_sqlite3/attrs/functions/queries_override_adapter.py new file mode 100644 index 00000000..23298e1d --- /dev/null +++ b/test/driver_sqlite3/attrs/functions/queries_override_adapter.py @@ -0,0 +1,86 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_adapter.sql +"""Module containing queries from file queries_override_adapter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "get_override_price", + "insert_override_conversion", +) + +import datetime +import decimal +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + + +INSERT_OVERRIDE_CONVERSION: typing.Final[str] = """-- name: InsertOverrideConversion :exec +INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) +""" + +GET_OVERRIDE_PRICE: typing.Final[str] = """-- name: GetOverridePrice :one +SELECT price FROM test_override_conversion WHERE id = ? +""" + + +def insert_override_conversion(conn: sqlite3.Connection, *, id_: int, price: float, happened_at: datetime.datetime) -> None: + """Execute SQL query with `name: InsertOverrideConversion :exec`. + + ```sql + INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + price : float + happened_at : datetime.datetime + + """ + conn.execute(INSERT_OVERRIDE_CONVERSION, (id_, decimal.Decimal(price), happened_at)) + + +def get_override_price(conn: sqlite3.Connection, *, id_: int) -> float | None: + """Fetch one from the db using the SQL query with `name: GetOverridePrice :one`. + + ```sql + SELECT price FROM test_override_conversion WHERE id = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + + Returns + ------- + float + Result fetched from the db. Will be `None` if not found. + + """ + row = conn.execute(GET_OVERRIDE_PRICE, (id_,)).fetchone() + if row is None: + return None + return float(row[0]) diff --git a/test/driver_sqlite3/attrs/functions/queries_override_converter.py b/test/driver_sqlite3/attrs/functions/queries_override_converter.py new file mode 100644 index 00000000..0061d43b --- /dev/null +++ b/test/driver_sqlite3/attrs/functions/queries_override_converter.py @@ -0,0 +1,55 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_converter.sql +"""Module containing queries from file queries_override_converter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("get_override_happened_at",) + +import datetime +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +GET_OVERRIDE_HAPPENED_AT: typing.Final[str] = """-- name: GetOverrideHappenedAt :one +SELECT happened_at FROM test_override_conversion WHERE id = ? +""" + + +def get_override_happened_at(conn: sqlite3.Connection, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOverrideHappenedAt :one`. + + ```sql + SELECT happened_at FROM test_override_conversion WHERE id = ? + ``` + + Parameters + ---------- + conn : sqlite3.Connection + Connection object of type `sqlite3.Connection` used to execute the query. + id_ : int + + Returns + ------- + datetime.datetime + Result fetched from the db. Will be `None` if not found. + + """ + row = conn.execute(GET_OVERRIDE_HAPPENED_AT, (id_,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/attrs/test_sqlite3_attrs_classes.py b/test/driver_sqlite3/attrs/test_sqlite3_attrs_classes.py index 619a58fd..9c174ca9 100644 --- a/test/driver_sqlite3/attrs/test_sqlite3_attrs_classes.py +++ b/test/driver_sqlite3/attrs/test_sqlite3_attrs_classes.py @@ -36,12 +36,12 @@ class TestSqlite3AttrsClasses: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestSqliteType: return models.TestSqliteType( - id=random.randint(1, 10000000), + id_=random.randint(1, 10000000), int_test=42, bigint_test=9_007_199_254_740_991, smallint_test=32_767, @@ -75,7 +75,7 @@ def model(self) -> models.TestSqliteType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: return models.TestInnerSqliteType( - table_id=model.id, + table_id=model.id_, int_test=None, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -120,7 +120,7 @@ def test_insert( model: models.TestSqliteType, ) -> None: queries_obj.insert_one_sqlite_type( - id_=model.id, + id_=model.id_, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -195,7 +195,7 @@ def test_get_one( queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_sqlite_type(id_=model.id) + result = queries_obj.get_one_sqlite_type(id_=model.id_) assert result is not None @@ -212,9 +212,7 @@ def test_get_one_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_one_inner", depends=["Sqlite3TestAttrsClasses::get_one_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_one_inner", depends=["Sqlite3TestAttrsClasses::get_one_none"]) def test_get_one_inner( self, queries_obj: queries.Queries, @@ -227,9 +225,7 @@ def test_get_one_inner( assert isinstance(result, models.TestInnerSqliteType) assert result == inner_model - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_one_inner_none", depends=["Sqlite3TestAttrsClasses::get_one_inner"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_one_inner_none", depends=["Sqlite3TestAttrsClasses::get_one_inner"]) def test_get_one_inner_none( self, queries_obj: queries.Queries, @@ -238,24 +234,20 @@ def test_get_one_inner_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_date", depends=["Sqlite3TestAttrsClasses::get_one_inner_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_date", depends=["Sqlite3TestAttrsClasses::get_one_inner_none"]) def test_get_date( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_date(id_=model.id, date_test=model.date_test) + result = queries_obj.get_one_date(id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, datetime.date) assert result == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_date_none", depends=["Sqlite3TestAttrsClasses::get_date"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_date_none", depends=["Sqlite3TestAttrsClasses::get_date"]) def test_get_date_none( self, queries_obj: queries.Queries, @@ -264,24 +256,20 @@ def test_get_date_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_datetime", depends=["Sqlite3TestAttrsClasses::get_date_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_datetime", depends=["Sqlite3TestAttrsClasses::get_date_none"]) def test_get_datetime( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_datetime(id_=model.id, datetime_test=model.datetime_test) + result = queries_obj.get_one_datetime(id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.datetime_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_datetime_none", depends=["Sqlite3TestAttrsClasses::get_datetime"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_datetime_none", depends=["Sqlite3TestAttrsClasses::get_datetime"]) def test_get_datetime_none( self, queries_obj: queries.Queries, @@ -290,24 +278,20 @@ def test_get_datetime_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_timestamp", depends=["Sqlite3TestAttrsClasses::get_datetime_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_timestamp", depends=["Sqlite3TestAttrsClasses::get_datetime_none"]) def test_get_timestamp( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_timestamp(id_=model.id, timestamp_test=model.timestamp_test) + result = queries_obj.get_one_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_timestamp_none", depends=["Sqlite3TestAttrsClasses::get_timestamp"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_timestamp_none", depends=["Sqlite3TestAttrsClasses::get_timestamp"]) def test_get_timestamp_none( self, queries_obj: queries.Queries, @@ -316,24 +300,20 @@ def test_get_timestamp_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_bool", depends=["Sqlite3TestAttrsClasses::get_timestamp_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_bool", depends=["Sqlite3TestAttrsClasses::get_timestamp_none"]) def test_get_bool( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_bool(id_=model.id, bool_test=model.bool_test) + result = queries_obj.get_one_bool(id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, bool) assert result == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_bool_none", depends=["Sqlite3TestAttrsClasses::get_bool"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_bool_none", depends=["Sqlite3TestAttrsClasses::get_bool"]) def test_get_bool_none( self, queries_obj: queries.Queries, @@ -342,24 +322,20 @@ def test_get_bool_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_boolean", depends=["Sqlite3TestAttrsClasses::get_bool_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_boolean", depends=["Sqlite3TestAttrsClasses::get_bool_none"]) def test_get_boolean( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_boolean(id_=model.id, boolean_test=model.boolean_test) + result = queries_obj.get_one_boolean(id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, bool) assert result == model.boolean_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_boolean_none", depends=["Sqlite3TestAttrsClasses::get_boolean"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_boolean_none", depends=["Sqlite3TestAttrsClasses::get_boolean"]) def test_get_boolean_none( self, queries_obj: queries.Queries, @@ -368,24 +344,20 @@ def test_get_boolean_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_decimal", depends=["Sqlite3TestAttrsClasses::get_boolean_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_decimal", depends=["Sqlite3TestAttrsClasses::get_boolean_none"]) def test_get_decimal( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_decimal(id_=model.id, decimal_test=model.decimal_test) + result = queries_obj.get_one_decimal(id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, decimal.Decimal) assert result == model.decimal_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_decimal_none", depends=["Sqlite3TestAttrsClasses::get_decimal"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_decimal_none", depends=["Sqlite3TestAttrsClasses::get_decimal"]) def test_get_decimal_none( self, queries_obj: queries.Queries, @@ -394,24 +366,20 @@ def test_get_decimal_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_blob", depends=["Sqlite3TestAttrsClasses::get_decimal_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_blob", depends=["Sqlite3TestAttrsClasses::get_decimal_none"]) def test_get_blob( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_blob(id_=model.id, blob_test=model.blob_test) + result = queries_obj.get_one_blob(id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_blob_none", depends=["Sqlite3TestAttrsClasses::get_blob"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_blob_none", depends=["Sqlite3TestAttrsClasses::get_blob"]) def test_get_blob_none( self, queries_obj: queries.Queries, @@ -420,11 +388,9 @@ def test_get_blob_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many", depends=["Sqlite3TestAttrsClasses::get_blob_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many", depends=["Sqlite3TestAttrsClasses::get_blob_none"]) def test_get_many(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_sqlite_type(id_=model.id) + result = queries_obj.get_many_sqlite_type(id_=model.id_) assert result is not None assert isinstance(result, queries.QueryResults) @@ -437,19 +403,15 @@ def test_get_many(self, queries_obj: queries.Queries, model: models.TestSqliteTy assert results[0] == model - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_iter", depends=["Sqlite3TestAttrsClasses::get_many"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_iter", depends=["Sqlite3TestAttrsClasses::get_many"]) def test_get_many_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_sqlite_type(id_=model.id): + for result in queries_obj.get_many_sqlite_type(id_=model.id_): assert result is not None assert isinstance(result, models.TestSqliteType) assert result == model - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_inner", depends=["Sqlite3TestAttrsClasses::get_many_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_inner", depends=["Sqlite3TestAttrsClasses::get_many_iter"]) def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: result = queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id) @@ -460,9 +422,7 @@ def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: models. assert results[0] == inner_model - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_inner_iter", depends=["Sqlite3TestAttrsClasses::get_many_inner"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_inner_iter", depends=["Sqlite3TestAttrsClasses::get_many_inner"]) def test_get_many_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: for result in queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id): assert result is not None @@ -474,12 +434,8 @@ def test_get_many_inner_iter(self, queries_obj: queries.Queries, inner_model: mo name="Sqlite3TestAttrsClasses::get_many_nullable_inner", depends=["Sqlite3TestAttrsClasses::get_many_inner_iter"], ) - def test_get_many_nullable_inner( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: - result = queries_obj.get_many_nullable_inner_sqlite_type( - table_id=inner_model.table_id, int_test=inner_model.int_test - ) + def test_get_many_nullable_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + result = queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -492,22 +448,16 @@ def test_get_many_nullable_inner( name="Sqlite3TestAttrsClasses::get_many_nullable_inner_iter", depends=["Sqlite3TestAttrsClasses::get_many_nullable_inner"], ) - def test_get_many_nullable_inner_iter( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: - for result in queries_obj.get_many_nullable_inner_sqlite_type( - table_id=inner_model.table_id, int_test=inner_model.int_test - ): + def test_get_many_nullable_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + for result in queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test): assert result is not None assert isinstance(result, models.TestInnerSqliteType) assert result == inner_model - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_date", depends=["Sqlite3TestAttrsClasses::get_many_nullable_inner_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_date", depends=["Sqlite3TestAttrsClasses::get_many_nullable_inner_iter"]) def test_get_many_date(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_date(id_=model.id, date_test=model.date_test) + result = queries_obj.get_many_date(id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -516,21 +466,17 @@ def test_get_many_date(self, queries_obj: queries.Queries, model: models.TestSql assert results[0] == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_date_iter", depends=["Sqlite3TestAttrsClasses::get_many_date"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_date_iter", depends=["Sqlite3TestAttrsClasses::get_many_date"]) def test_get_many_date_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_date(id_=model.id, date_test=model.date_test): + for result in queries_obj.get_many_date(id_=model.id_, date_test=model.date_test): assert result is not None assert isinstance(result, datetime.date) assert result == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_datetime", depends=["Sqlite3TestAttrsClasses::get_many_date_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_datetime", depends=["Sqlite3TestAttrsClasses::get_many_date_iter"]) def test_get_many_datetime(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_datetime(id_=model.id, datetime_test=model.datetime_test) + result = queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -539,11 +485,9 @@ def test_get_many_datetime(self, queries_obj: queries.Queries, model: models.Tes assert results[0] == model.datetime_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_datetime_iter", depends=["Sqlite3TestAttrsClasses::get_many_datetime"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_datetime_iter", depends=["Sqlite3TestAttrsClasses::get_many_datetime"]) def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_datetime(id_=model.id, datetime_test=model.datetime_test): + for result in queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -554,7 +498,7 @@ def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: model depends=["Sqlite3TestAttrsClasses::get_many_datetime_iter"], ) def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_timestamp(id_=model.id, timestamp_test=model.timestamp_test) + result = queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -568,17 +512,15 @@ def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.Te depends=["Sqlite3TestAttrsClasses::get_many_timestamp"], ) def test_get_many_timestamp_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_timestamp(id_=model.id, timestamp_test=model.timestamp_test): + for result in queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test): assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_bool", depends=["Sqlite3TestAttrsClasses::get_many_timestamp_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_bool", depends=["Sqlite3TestAttrsClasses::get_many_timestamp_iter"]) def test_get_many_bool(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_bool(id_=model.id, bool_test=model.bool_test) + result = queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -587,21 +529,17 @@ def test_get_many_bool(self, queries_obj: queries.Queries, model: models.TestSql assert results[0] == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_bool_iter", depends=["Sqlite3TestAttrsClasses::get_many_bool"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_bool_iter", depends=["Sqlite3TestAttrsClasses::get_many_bool"]) def test_get_many_bool_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_bool(id_=model.id, bool_test=model.bool_test): + for result in queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test): assert result is not None assert isinstance(result, bool) assert result == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_boolean", depends=["Sqlite3TestAttrsClasses::get_many_bool_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_boolean", depends=["Sqlite3TestAttrsClasses::get_many_bool_iter"]) def test_get_many_boolean(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_boolean(id_=model.id, boolean_test=model.boolean_test) + result = queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -610,21 +548,17 @@ def test_get_many_boolean(self, queries_obj: queries.Queries, model: models.Test assert results[0] == model.boolean_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_boolean_iter", depends=["Sqlite3TestAttrsClasses::get_many_boolean"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_boolean_iter", depends=["Sqlite3TestAttrsClasses::get_many_boolean"]) def test_get_many_boolean_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_boolean(id_=model.id, boolean_test=model.boolean_test): + for result in queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test): assert result is not None assert isinstance(result, bool) assert result == model.boolean_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_decimal", depends=["Sqlite3TestAttrsClasses::get_many_boolean_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_decimal", depends=["Sqlite3TestAttrsClasses::get_many_boolean_iter"]) def test_get_many_decimal(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_decimal(id_=model.id, decimal_test=model.decimal_test) + result = queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -633,21 +567,17 @@ def test_get_many_decimal(self, queries_obj: queries.Queries, model: models.Test assert results[0] == model.decimal_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_decimal_iter", depends=["Sqlite3TestAttrsClasses::get_many_decimal"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_decimal_iter", depends=["Sqlite3TestAttrsClasses::get_many_decimal"]) def test_get_many_decimal_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_decimal(id_=model.id, decimal_test=model.decimal_test): + for result in queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test): assert result is not None assert isinstance(result, decimal.Decimal) assert result == model.decimal_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_blob", depends=["Sqlite3TestAttrsClasses::get_many_decimal_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_blob", depends=["Sqlite3TestAttrsClasses::get_many_decimal_iter"]) def test_get_many_blob(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_blob(id_=model.id, blob_test=model.blob_test) + result = queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -656,26 +586,22 @@ def test_get_many_blob(self, queries_obj: queries.Queries, model: models.TestSql assert results[0] == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::get_many_blob_iter", depends=["Sqlite3TestAttrsClasses::get_many_blob"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::get_many_blob_iter", depends=["Sqlite3TestAttrsClasses::get_many_blob"]) def test_get_many_blob_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_blob(id_=model.id, blob_test=model.blob_test): + for result in queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test): assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::insert_result", depends=["Sqlite3TestAttrsClasses::get_many_blob_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::insert_result", depends=["Sqlite3TestAttrsClasses::get_many_blob_iter"]) def test_insert_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = queries_obj.insert_result_one_sqlite_type( - id_=model.id + 1, + id_=model.id_ + 1, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -707,38 +633,32 @@ def test_insert_result( ) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::update_result", depends=["Sqlite3TestAttrsClasses::insert_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::update_result", depends=["Sqlite3TestAttrsClasses::insert_result"]) def test_update_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.update_result_one_sqlite_type(id_=model.id + 1) + result = queries_obj.update_result_one_sqlite_type(id_=model.id_ + 1) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::delete_result", depends=["Sqlite3TestAttrsClasses::update_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::delete_result", depends=["Sqlite3TestAttrsClasses::update_result"]) def test_delete_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.delete_result_one_sqlite_type(id_=model.id + 1) + result = queries_obj.delete_result_one_sqlite_type(id_=model.id_ + 1) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::insert_rows", depends=["Sqlite3TestAttrsClasses::delete_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::insert_rows", depends=["Sqlite3TestAttrsClasses::delete_result"]) def test_insert_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = queries_obj.insert_rows_one_sqlite_type( - id_=model.id + 2, + id_=model.id_ + 2, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -771,33 +691,27 @@ def test_insert_rows( assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::update_rows", depends=["Sqlite3TestAttrsClasses::insert_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::update_rows", depends=["Sqlite3TestAttrsClasses::insert_rows"]) def test_update_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.update_rows_one_sqlite_type(id_=model.id + 2) + result = queries_obj.update_rows_one_sqlite_type(id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::delete_rows", depends=["Sqlite3TestAttrsClasses::update_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::delete_rows", depends=["Sqlite3TestAttrsClasses::update_rows"]) def test_delete_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.delete_rows_one_sqlite_type(id_=model.id + 2) + result = queries_obj.delete_rows_one_sqlite_type(id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::create_table_rows", depends=["Sqlite3TestAttrsClasses::delete_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::create_table_rows", depends=["Sqlite3TestAttrsClasses::delete_rows"]) def test_create_table_rows( self, queries_obj: queries.Queries, @@ -809,16 +723,14 @@ def test_create_table_rows( sqlite3_conn.commit() assert result == -1 - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::insert_last_id", depends=["Sqlite3TestAttrsClasses::create_table_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::insert_last_id", depends=["Sqlite3TestAttrsClasses::create_table_rows"]) def test_insert_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = queries_obj.insert_last_id_one_sqlite_type( - id_=model.id + 3, + id_=model.id_ + 3, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -849,59 +761,51 @@ def test_insert_last_id( json_test=model.json_test, ) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::update_last_id", depends=["Sqlite3TestAttrsClasses::insert_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::update_last_id", depends=["Sqlite3TestAttrsClasses::insert_last_id"]) def test_update_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.update_last_id_one_sqlite_type(id_=model.id + 3) + result = queries_obj.update_last_id_one_sqlite_type(id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::delete_last_id", depends=["Sqlite3TestAttrsClasses::update_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::delete_last_id", depends=["Sqlite3TestAttrsClasses::update_last_id"]) def test_delete_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.delete_last_id_one_sqlite_type(id_=model.id + 3) + result = queries_obj.delete_last_id_one_sqlite_type(id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestAttrsClasses::delete_sqlite_type", depends=["Sqlite3TestAttrsClasses::delete_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsClasses::delete_sqlite_type", depends=["Sqlite3TestAttrsClasses::delete_last_id"]) def test_delete_sqlite_type(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - queries_obj.delete_one_sqlite_type(id_=model.id) + queries_obj.delete_one_sqlite_type(id_=model.id_) @pytest.mark.dependency( name="Sqlite3TestAttrsClasses::delete_inner_sqlite_type", depends=["Sqlite3TestAttrsClasses::delete_sqlite_type"], ) - def test_delete_inner_sqlite_type( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: + def test_delete_inner_sqlite_type(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: queries_obj.delete_one_test_inner_sqlite_type(table_id=inner_model.table_id) @pytest.mark.dependency( name="Sqlite3TestAttrsClasses::insert_type_override", ) def test_insert_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: - queries_obj.insert_type_override(id_=override_model.id, text_test=override_model.text_test) + queries_obj.insert_type_override(id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.dependency( name="Sqlite3TestAttrsClasses::get_one_type_override", depends=["Sqlite3TestAttrsClasses::insert_type_override"], ) def test_get_one_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: - result = queries_obj.get_one_type_override(id_=override_model.id) + result = queries_obj.get_one_type_override(id_=override_model.id_) assert result is not None assert result == override_model @@ -909,20 +813,16 @@ def test_get_one_type_override(self, queries_obj: queries.Queries, override_mode name="Sqlite3TestAttrsClasses::get_one_type_override_none", depends=["Sqlite3TestAttrsClasses::get_one_type_override"], ) - def test_get_one_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_one_type_override(id_=override_model.id - 1) + def test_get_one_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.dependency( name="Sqlite3TestAttrsClasses::get_many_type_override", depends=["Sqlite3TestAttrsClasses::get_one_type_override_none"], ) - def test_get_many_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_many_type_override(id_=override_model.id) + def test_get_many_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_many_type_override(id_=override_model.id_) assert result is not None assert isinstance(result, queries.QueryResults) results = list(result) @@ -934,10 +834,8 @@ def test_get_many_type_override( name="Sqlite3TestAttrsClasses::get_one_text_type_override", depends=["Sqlite3TestAttrsClasses::get_many_type_override"], ) - def test_get_one_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_one_text_type_override(id_=override_model.id) + def test_get_one_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_text_type_override(id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -945,20 +843,16 @@ def test_get_one_text_type_override( name="Sqlite3TestAttrsClasses::get_one_text_type_override_none", depends=["Sqlite3TestAttrsClasses::get_one_text_type_override"], ) - def test_get_one_text_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_one_text_type_override(id_=override_model.id - 1) + def test_get_one_text_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_text_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.dependency( name="Sqlite3TestAttrsClasses::get_many_text_type_override", depends=["Sqlite3TestAttrsClasses::get_one_text_type_override_none"], ) - def test_get_many_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_many_text_type_override(id_=override_model.id) + def test_get_many_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_many_text_type_override(id_=override_model.id_) assert result is not None assert isinstance(result, queries.QueryResults) results = list(result) @@ -971,4 +865,4 @@ def test_get_many_text_type_override( depends=["Sqlite3TestAttrsClasses::get_many_text_type_override"], ) def test_delete_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: - queries_obj.delete_type_override(id_=override_model.id) + queries_obj.delete_type_override(id_=override_model.id_) diff --git a/test/driver_sqlite3/attrs/test_sqlite3_attrs_functions.py b/test/driver_sqlite3/attrs/test_sqlite3_attrs_functions.py index 4689afaf..04a94ad5 100644 --- a/test/driver_sqlite3/attrs/test_sqlite3_attrs_functions.py +++ b/test/driver_sqlite3/attrs/test_sqlite3_attrs_functions.py @@ -36,12 +36,12 @@ class TestSqlite3AttrsFunctions: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestSqliteType: return models.TestSqliteType( - id=random.randint(1, 10000000), + id_=random.randint(1, 10000000), int_test=42, bigint_test=9_007_199_254_740_991, smallint_test=32_767, @@ -75,7 +75,7 @@ def model(self) -> models.TestSqliteType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: return models.TestInnerSqliteType( - table_id=model.id, + table_id=model.id_, int_test=None, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -114,7 +114,7 @@ def test_insert( ) -> None: queries.insert_one_sqlite_type( conn=sqlite3_conn, - id_=model.id, + id_=model.id_, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -145,9 +145,7 @@ def test_insert( json_test=model.json_test, ) - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::inner_insert", depends=["Sqlite3TestAttrsFunctions::insert"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::inner_insert", depends=["Sqlite3TestAttrsFunctions::insert"]) def test_inner_insert( self, sqlite3_conn: sqlite3.Connection, @@ -186,15 +184,13 @@ def test_inner_insert( json_test=inner_model.json_test, ) - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_one", depends=["Sqlite3TestAttrsFunctions::inner_insert"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_one", depends=["Sqlite3TestAttrsFunctions::inner_insert"]) def test_get_one( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_sqlite_type(conn=sqlite3_conn, id_=model.id) + result = queries.get_one_sqlite_type(conn=sqlite3_conn, id_=model.id_) assert result is not None @@ -202,9 +198,7 @@ def test_get_one( assert result == model - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_one_none", depends=["Sqlite3TestAttrsFunctions::get_one"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_one_none", depends=["Sqlite3TestAttrsFunctions::get_one"]) def test_get_one_none( self, sqlite3_conn: sqlite3.Connection, @@ -213,9 +207,7 @@ def test_get_one_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_one_inner", depends=["Sqlite3TestAttrsFunctions::get_one_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_one_inner", depends=["Sqlite3TestAttrsFunctions::get_one_none"]) def test_get_one_inner( self, sqlite3_conn: sqlite3.Connection, @@ -228,9 +220,7 @@ def test_get_one_inner( assert isinstance(result, models.TestInnerSqliteType) assert result == inner_model - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_one_inner_none", depends=["Sqlite3TestAttrsFunctions::get_one_inner"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_one_inner_none", depends=["Sqlite3TestAttrsFunctions::get_one_inner"]) def test_get_one_inner_none( self, sqlite3_conn: sqlite3.Connection, @@ -239,24 +229,20 @@ def test_get_one_inner_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_date", depends=["Sqlite3TestAttrsFunctions::get_one_inner_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_date", depends=["Sqlite3TestAttrsFunctions::get_one_inner_none"]) def test_get_date( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_date(conn=sqlite3_conn, id_=model.id, date_test=model.date_test) + result = queries.get_one_date(conn=sqlite3_conn, id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, datetime.date) assert result == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_date_none", depends=["Sqlite3TestAttrsFunctions::get_date"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_date_none", depends=["Sqlite3TestAttrsFunctions::get_date"]) def test_get_date_none( self, sqlite3_conn: sqlite3.Connection, @@ -265,24 +251,20 @@ def test_get_date_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_datetime", depends=["Sqlite3TestAttrsFunctions::get_date_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_datetime", depends=["Sqlite3TestAttrsFunctions::get_date_none"]) def test_get_datetime( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_datetime(conn=sqlite3_conn, id_=model.id, datetime_test=model.datetime_test) + result = queries.get_one_datetime(conn=sqlite3_conn, id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.datetime_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_datetime_none", depends=["Sqlite3TestAttrsFunctions::get_datetime"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_datetime_none", depends=["Sqlite3TestAttrsFunctions::get_datetime"]) def test_get_datetime_none( self, sqlite3_conn: sqlite3.Connection, @@ -291,24 +273,20 @@ def test_get_datetime_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_timestamp", depends=["Sqlite3TestAttrsFunctions::get_datetime_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_timestamp", depends=["Sqlite3TestAttrsFunctions::get_datetime_none"]) def test_get_timestamp( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_timestamp(conn=sqlite3_conn, id_=model.id, timestamp_test=model.timestamp_test) + result = queries.get_one_timestamp(conn=sqlite3_conn, id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_timestamp_none", depends=["Sqlite3TestAttrsFunctions::get_timestamp"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_timestamp_none", depends=["Sqlite3TestAttrsFunctions::get_timestamp"]) def test_get_timestamp_none( self, sqlite3_conn: sqlite3.Connection, @@ -317,24 +295,20 @@ def test_get_timestamp_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_bool", depends=["Sqlite3TestAttrsFunctions::get_timestamp_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_bool", depends=["Sqlite3TestAttrsFunctions::get_timestamp_none"]) def test_get_bool( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_bool(conn=sqlite3_conn, id_=model.id, bool_test=model.bool_test) + result = queries.get_one_bool(conn=sqlite3_conn, id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, bool) assert result == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_bool_none", depends=["Sqlite3TestAttrsFunctions::get_bool"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_bool_none", depends=["Sqlite3TestAttrsFunctions::get_bool"]) def test_get_bool_none( self, sqlite3_conn: sqlite3.Connection, @@ -343,24 +317,20 @@ def test_get_bool_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_boolean", depends=["Sqlite3TestAttrsFunctions::get_bool_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_boolean", depends=["Sqlite3TestAttrsFunctions::get_bool_none"]) def test_get_boolean( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_boolean(conn=sqlite3_conn, id_=model.id, boolean_test=model.boolean_test) + result = queries.get_one_boolean(conn=sqlite3_conn, id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, bool) assert result == model.boolean_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_boolean_none", depends=["Sqlite3TestAttrsFunctions::get_boolean"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_boolean_none", depends=["Sqlite3TestAttrsFunctions::get_boolean"]) def test_get_boolean_none( self, sqlite3_conn: sqlite3.Connection, @@ -369,24 +339,20 @@ def test_get_boolean_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_decimal", depends=["Sqlite3TestAttrsFunctions::get_boolean_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_decimal", depends=["Sqlite3TestAttrsFunctions::get_boolean_none"]) def test_get_decimal( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_decimal(conn=sqlite3_conn, id_=model.id, decimal_test=model.decimal_test) + result = queries.get_one_decimal(conn=sqlite3_conn, id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, decimal.Decimal) assert result == model.decimal_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_decimal_none", depends=["Sqlite3TestAttrsFunctions::get_decimal"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_decimal_none", depends=["Sqlite3TestAttrsFunctions::get_decimal"]) def test_get_decimal_none( self, sqlite3_conn: sqlite3.Connection, @@ -395,24 +361,20 @@ def test_get_decimal_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_blob", depends=["Sqlite3TestAttrsFunctions::get_decimal_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_blob", depends=["Sqlite3TestAttrsFunctions::get_decimal_none"]) def test_get_blob( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_blob(conn=sqlite3_conn, id_=model.id, blob_test=model.blob_test) + result = queries.get_one_blob(conn=sqlite3_conn, id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_blob_none", depends=["Sqlite3TestAttrsFunctions::get_blob"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_blob_none", depends=["Sqlite3TestAttrsFunctions::get_blob"]) def test_get_blob_none( self, sqlite3_conn: sqlite3.Connection, @@ -421,11 +383,9 @@ def test_get_blob_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many", depends=["Sqlite3TestAttrsFunctions::get_blob_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many", depends=["Sqlite3TestAttrsFunctions::get_blob_none"]) def test_get_many(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id) + result = queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id_) assert result is not None assert isinstance(result, queries.QueryResults) @@ -439,19 +399,15 @@ def test_get_many(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqli assert results[0] == model - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_iter", depends=["Sqlite3TestAttrsFunctions::get_many"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_iter", depends=["Sqlite3TestAttrsFunctions::get_many"]) def test_get_many_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id): + for result in queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id_): assert result is not None assert isinstance(result, models.TestSqliteType) assert result == model - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_inner", depends=["Sqlite3TestAttrsFunctions::get_many_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_inner", depends=["Sqlite3TestAttrsFunctions::get_many_iter"]) def test_get_many_inner(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: result = queries.get_many_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id) @@ -462,12 +418,8 @@ def test_get_many_inner(self, sqlite3_conn: sqlite3.Connection, inner_model: mod assert results[0] == inner_model - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_inner_iter", depends=["Sqlite3TestAttrsFunctions::get_many_inner"] - ) - def test_get_many_inner_iter( - self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_inner_iter", depends=["Sqlite3TestAttrsFunctions::get_many_inner"]) + def test_get_many_inner_iter(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: for result in queries.get_many_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -478,12 +430,8 @@ def test_get_many_inner_iter( name="Sqlite3TestAttrsFunctions::get_many_nullable_inner", depends=["Sqlite3TestAttrsFunctions::get_many_inner_iter"], ) - def test_get_many_nullable_inner( - self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType - ) -> None: - result = queries.get_many_nullable_inner_sqlite_type( - conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test - ) + def test_get_many_nullable_inner(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: + result = queries.get_many_nullable_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -496,12 +444,8 @@ def test_get_many_nullable_inner( name="Sqlite3TestAttrsFunctions::get_many_nullable_inner_iter", depends=["Sqlite3TestAttrsFunctions::get_many_nullable_inner"], ) - def test_get_many_nullable_inner_iter( - self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType - ) -> None: - for result in queries.get_many_nullable_inner_sqlite_type( - conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test - ): + def test_get_many_nullable_inner_iter(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: + for result in queries.get_many_nullable_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -512,7 +456,7 @@ def test_get_many_nullable_inner_iter( depends=["Sqlite3TestAttrsFunctions::get_many_nullable_inner_iter"], ) def test_get_many_date(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_date(conn=sqlite3_conn, id_=model.id, date_test=model.date_test) + result = queries.get_many_date(conn=sqlite3_conn, id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -521,21 +465,17 @@ def test_get_many_date(self, sqlite3_conn: sqlite3.Connection, model: models.Tes assert results[0] == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_date_iter", depends=["Sqlite3TestAttrsFunctions::get_many_date"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_date_iter", depends=["Sqlite3TestAttrsFunctions::get_many_date"]) def test_get_many_date_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_date(conn=sqlite3_conn, id_=model.id, date_test=model.date_test): + for result in queries.get_many_date(conn=sqlite3_conn, id_=model.id_, date_test=model.date_test): assert result is not None assert isinstance(result, datetime.date) assert result == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_datetime", depends=["Sqlite3TestAttrsFunctions::get_many_date_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_datetime", depends=["Sqlite3TestAttrsFunctions::get_many_date_iter"]) def test_get_many_datetime(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_datetime(conn=sqlite3_conn, id_=model.id, datetime_test=model.datetime_test) + result = queries.get_many_datetime(conn=sqlite3_conn, id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -549,7 +489,7 @@ def test_get_many_datetime(self, sqlite3_conn: sqlite3.Connection, model: models depends=["Sqlite3TestAttrsFunctions::get_many_datetime"], ) def test_get_many_datetime_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_datetime(conn=sqlite3_conn, id_=model.id, datetime_test=model.datetime_test): + for result in queries.get_many_datetime(conn=sqlite3_conn, id_=model.id_, datetime_test=model.datetime_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -560,7 +500,7 @@ def test_get_many_datetime_iter(self, sqlite3_conn: sqlite3.Connection, model: m depends=["Sqlite3TestAttrsFunctions::get_many_datetime_iter"], ) def test_get_many_timestamp(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id, timestamp_test=model.timestamp_test) + result = queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -574,17 +514,15 @@ def test_get_many_timestamp(self, sqlite3_conn: sqlite3.Connection, model: model depends=["Sqlite3TestAttrsFunctions::get_many_timestamp"], ) def test_get_many_timestamp_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id, timestamp_test=model.timestamp_test): + for result in queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id_, timestamp_test=model.timestamp_test): assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_bool", depends=["Sqlite3TestAttrsFunctions::get_many_timestamp_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_bool", depends=["Sqlite3TestAttrsFunctions::get_many_timestamp_iter"]) def test_get_many_bool(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_bool(conn=sqlite3_conn, id_=model.id, bool_test=model.bool_test) + result = queries.get_many_bool(conn=sqlite3_conn, id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -593,21 +531,17 @@ def test_get_many_bool(self, sqlite3_conn: sqlite3.Connection, model: models.Tes assert results[0] == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_bool_iter", depends=["Sqlite3TestAttrsFunctions::get_many_bool"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_bool_iter", depends=["Sqlite3TestAttrsFunctions::get_many_bool"]) def test_get_many_bool_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_bool(conn=sqlite3_conn, id_=model.id, bool_test=model.bool_test): + for result in queries.get_many_bool(conn=sqlite3_conn, id_=model.id_, bool_test=model.bool_test): assert result is not None assert isinstance(result, bool) assert result == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_boolean", depends=["Sqlite3TestAttrsFunctions::get_many_bool_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_boolean", depends=["Sqlite3TestAttrsFunctions::get_many_bool_iter"]) def test_get_many_boolean(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_boolean(conn=sqlite3_conn, id_=model.id, boolean_test=model.boolean_test) + result = queries.get_many_boolean(conn=sqlite3_conn, id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -616,21 +550,17 @@ def test_get_many_boolean(self, sqlite3_conn: sqlite3.Connection, model: models. assert results[0] == model.boolean_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_boolean_iter", depends=["Sqlite3TestAttrsFunctions::get_many_boolean"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_boolean_iter", depends=["Sqlite3TestAttrsFunctions::get_many_boolean"]) def test_get_many_boolean_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_boolean(conn=sqlite3_conn, id_=model.id, boolean_test=model.boolean_test): + for result in queries.get_many_boolean(conn=sqlite3_conn, id_=model.id_, boolean_test=model.boolean_test): assert result is not None assert isinstance(result, bool) assert result == model.boolean_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_decimal", depends=["Sqlite3TestAttrsFunctions::get_many_boolean_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_decimal", depends=["Sqlite3TestAttrsFunctions::get_many_boolean_iter"]) def test_get_many_decimal(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_decimal(conn=sqlite3_conn, id_=model.id, decimal_test=model.decimal_test) + result = queries.get_many_decimal(conn=sqlite3_conn, id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -639,21 +569,17 @@ def test_get_many_decimal(self, sqlite3_conn: sqlite3.Connection, model: models. assert results[0] == model.decimal_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_decimal_iter", depends=["Sqlite3TestAttrsFunctions::get_many_decimal"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_decimal_iter", depends=["Sqlite3TestAttrsFunctions::get_many_decimal"]) def test_get_many_decimal_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_decimal(conn=sqlite3_conn, id_=model.id, decimal_test=model.decimal_test): + for result in queries.get_many_decimal(conn=sqlite3_conn, id_=model.id_, decimal_test=model.decimal_test): assert result is not None assert isinstance(result, decimal.Decimal) assert result == model.decimal_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_blob", depends=["Sqlite3TestAttrsFunctions::get_many_decimal_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_blob", depends=["Sqlite3TestAttrsFunctions::get_many_decimal_iter"]) def test_get_many_blob(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_blob(conn=sqlite3_conn, id_=model.id, blob_test=model.blob_test) + result = queries.get_many_blob(conn=sqlite3_conn, id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -662,19 +588,15 @@ def test_get_many_blob(self, sqlite3_conn: sqlite3.Connection, model: models.Tes assert results[0] == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::get_many_blob_iter", depends=["Sqlite3TestAttrsFunctions::get_many_blob"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::get_many_blob_iter", depends=["Sqlite3TestAttrsFunctions::get_many_blob"]) def test_get_many_blob_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_blob(conn=sqlite3_conn, id_=model.id, blob_test=model.blob_test): + for result in queries.get_many_blob(conn=sqlite3_conn, id_=model.id_, blob_test=model.blob_test): assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::insert_result", depends=["Sqlite3TestAttrsFunctions::get_many_blob_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::insert_result", depends=["Sqlite3TestAttrsFunctions::get_many_blob_iter"]) def test_insert_result( self, sqlite3_conn: sqlite3.Connection, @@ -682,7 +604,7 @@ def test_insert_result( ) -> None: result = queries.insert_result_one_sqlite_type( conn=sqlite3_conn, - id_=model.id + 1, + id_=model.id_ + 1, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -714,31 +636,25 @@ def test_insert_result( ) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::update_result", depends=["Sqlite3TestAttrsFunctions::insert_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::update_result", depends=["Sqlite3TestAttrsFunctions::insert_result"]) def test_update_result( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.update_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 1) + result = queries.update_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 1) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::delete_result", depends=["Sqlite3TestAttrsFunctions::update_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::delete_result", depends=["Sqlite3TestAttrsFunctions::update_result"]) def test_delete_result( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.delete_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 1) + result = queries.delete_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 1) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::insert_rows", depends=["Sqlite3TestAttrsFunctions::delete_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::insert_rows", depends=["Sqlite3TestAttrsFunctions::delete_result"]) def test_insert_rows( self, sqlite3_conn: sqlite3.Connection, @@ -746,7 +662,7 @@ def test_insert_rows( ) -> None: result = queries.insert_rows_one_sqlite_type( conn=sqlite3_conn, - id_=model.id + 2, + id_=model.id_ + 2, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -779,33 +695,27 @@ def test_insert_rows( assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::update_rows", depends=["Sqlite3TestAttrsFunctions::insert_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::update_rows", depends=["Sqlite3TestAttrsFunctions::insert_rows"]) def test_update_rows( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.update_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 2) + result = queries.update_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::delete_rows", depends=["Sqlite3TestAttrsFunctions::update_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::delete_rows", depends=["Sqlite3TestAttrsFunctions::update_rows"]) def test_delete_rows( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.delete_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 2) + result = queries.delete_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::create_table_rows", depends=["Sqlite3TestAttrsFunctions::delete_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::create_table_rows", depends=["Sqlite3TestAttrsFunctions::delete_rows"]) def test_create_table_rows( self, sqlite3_conn: sqlite3.Connection, @@ -816,9 +726,7 @@ def test_create_table_rows( sqlite3_conn.commit() assert result == -1 - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::insert_last_id", depends=["Sqlite3TestAttrsFunctions::create_table_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::insert_last_id", depends=["Sqlite3TestAttrsFunctions::create_table_rows"]) def test_insert_last_id( self, sqlite3_conn: sqlite3.Connection, @@ -826,7 +734,7 @@ def test_insert_last_id( ) -> None: result = queries.insert_last_id_one_sqlite_type( conn=sqlite3_conn, - id_=model.id + 3, + id_=model.id_ + 3, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -857,63 +765,51 @@ def test_insert_last_id( json_test=model.json_test, ) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::update_last_id", depends=["Sqlite3TestAttrsFunctions::insert_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::update_last_id", depends=["Sqlite3TestAttrsFunctions::insert_last_id"]) def test_update_last_id( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.update_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 3) + result = queries.update_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::delete_last_id", depends=["Sqlite3TestAttrsFunctions::update_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::delete_last_id", depends=["Sqlite3TestAttrsFunctions::update_last_id"]) def test_delete_last_id( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.delete_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 3) + result = queries.delete_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestAttrsFunctions::delete_sqlite_type", depends=["Sqlite3TestAttrsFunctions::delete_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestAttrsFunctions::delete_sqlite_type", depends=["Sqlite3TestAttrsFunctions::delete_last_id"]) def test_delete_sqlite_type(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - queries.delete_one_sqlite_type(conn=sqlite3_conn, id_=model.id) + queries.delete_one_sqlite_type(conn=sqlite3_conn, id_=model.id_) @pytest.mark.dependency( name="Sqlite3TestAttrsFunctions::delete_inner_sqlite_type", depends=["Sqlite3TestAttrsFunctions::delete_sqlite_type"], ) - def test_delete_inner_sqlite_type( - self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + def test_delete_inner_sqlite_type(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: queries.delete_one_test_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id) @pytest.mark.dependency( name="Sqlite3TestAttrsFunctions::insert_type_override", ) - def test_insert_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - queries.insert_type_override(conn=sqlite3_conn, id_=override_model.id, text_test=override_model.text_test) + def test_insert_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + queries.insert_type_override(conn=sqlite3_conn, id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.dependency( name="Sqlite3TestAttrsFunctions::get_one_type_override", depends=["Sqlite3TestAttrsFunctions::insert_type_override"], ) - def test_get_one_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_get_one_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id_) assert result is not None assert result == override_model @@ -921,20 +817,16 @@ def test_get_one_type_override( name="Sqlite3TestAttrsFunctions::get_one_type_override_none", depends=["Sqlite3TestAttrsFunctions::get_one_type_override"], ) - def test_get_one_type_override_none( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id - 1) + def test_get_one_type_override_none(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.dependency( name="Sqlite3TestAttrsFunctions::get_many_type_override", depends=["Sqlite3TestAttrsFunctions::get_one_type_override_none"], ) - def test_get_many_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_many_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_get_many_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_many_type_override(conn=sqlite3_conn, id_=override_model.id_) assert result is not None assert isinstance(result, queries.QueryResults) results = list(result) @@ -951,10 +843,8 @@ def test_get_many_type_override( name="Sqlite3TestAttrsFunctions::get_one_text_type_override", depends=["Sqlite3TestAttrsFunctions::get_many_type_override"], ) - def test_get_one_text_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_get_one_text_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -962,20 +852,16 @@ def test_get_one_text_type_override( name="Sqlite3TestAttrsFunctions::get_one_text_type_override_none", depends=["Sqlite3TestAttrsFunctions::get_one_text_type_override"], ) - def test_get_one_text_type_override_none( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id - 1) + def test_get_one_text_type_override_none(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.dependency( name="Sqlite3TestAttrsFunctions::get_many_text_type_override", depends=["Sqlite3TestAttrsFunctions::get_one_text_type_override_none"], ) - def test_get_many_text_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_many_text_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_get_many_text_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_many_text_type_override(conn=sqlite3_conn, id_=override_model.id_) assert result is not None assert isinstance(result, queries.QueryResults) results = list(result) @@ -992,7 +878,5 @@ def test_get_many_text_type_override( name="Sqlite3TestAttrsFunctions::delete_type_override", depends=["Sqlite3TestAttrsFunctions::get_many_text_type_override"], ) - def test_delete_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - queries.delete_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_delete_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + queries.delete_type_override(conn=sqlite3_conn, id_=override_model.id_) diff --git a/test/driver_sqlite3/dataclass/classes/__init__.py b/test/driver_sqlite3/dataclass/classes/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_sqlite3/dataclass/classes/__init__.py +++ b/test/driver_sqlite3/dataclass/classes/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_sqlite3/dataclass/classes/models.py b/test/driver_sqlite3/dataclass/classes/models.py index 086490f6..42ec832a 100644 --- a/test/driver_sqlite3/dataclass/classes/models.py +++ b/test/driver_sqlite3/dataclass/classes/models.py @@ -1,8 +1,9 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -93,7 +94,7 @@ class TestSqliteType: """Model representing TestSqliteType. Attributes: - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -124,7 +125,7 @@ class TestSqliteType: json_test: str """ - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -160,9 +161,9 @@ class TestTypeOverride: """Model representing TestTypeOverride. Attributes: - id: int + id_: int text_test: UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_sqlite3/dataclass/classes/queries.py b/test/driver_sqlite3/dataclass/classes/queries.py index fe53d245..9cde42b9 100644 --- a/test/driver_sqlite3/dataclass/classes/queries.py +++ b/test/driver_sqlite3/dataclass/classes/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -20,7 +22,7 @@ if typing.TYPE_CHECKING: import collections.abc - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None from test.driver_sqlite3.dataclass.classes import models @@ -80,71 +82,74 @@ def _convert_memoryview(val: bytes) -> memoryview: sqlite3.register_converter("blob", _convert_memoryview) -CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows -CREATE TABLE test_create_rows_table -( - id int PRIMARY KEY NOT NULL, - test int NOT NULL -) -""" - -DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec -DELETE FROM test_inner_sqlite_types -WHERE test_inner_sqlite_types.table_id = ? +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ -DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? """ -DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec -DELETE -FROM test_type_override -WHERE test_type_override.id = ? +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ -GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many -SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many @@ -155,67 +160,46 @@ def _convert_memoryview(val: bytes) -> memoryview: SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? """ -GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? -""" - -GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? -""" - -GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? -""" - -GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? -""" - -GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one -SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? -""" - -GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one -SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = ? +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? """ -INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -230,37 +214,19 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec -INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? """ -INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec -INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -275,7 +241,27 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -290,35 +276,48 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec INSERT INTO test_type_override ( id, text_test ) VALUES (? ,?) """ -UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? """ -UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? """ -UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? """ +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" -T = typing.TypeVar("T") +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db.""" __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") @@ -412,132 +411,389 @@ def conn(self) -> sqlite3.Connection: """ return self._conn - def create_rows_table(self) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + def insert_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. - """ - return self._conn.execute(CREATE_ROWS_TABLE).rowcount - - def delete_last_id_one_sqlite_type(self, *, id_: int) -> int | None: - """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Args: id_: int. - - Returns: - The id (`int | None`) of the last affected row. Will be `None` if no rows are affected. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. """ - return self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, )).lastrowid + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + self._conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) - def delete_one_sqlite_type(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneSqliteType :exec`. + def insert_one_inner_sqlite_type( + self, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, + ) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Args: - id_: int. + table_id: int. + int_test: int | None. + bigint_test: int | None. + smallint_test: int | None. + tinyint_test: int | None. + int2_test: int | None. + int8_test: int | None. + bigserial_test: int | None. + blob_test: memoryview | None. + real_test: float | None. + double_test: float | None. + double_precision_test: float | None. + float_test: float | None. + numeric_test: float | None. + decimal_test: decimal.Decimal | None. + boolean_test: bool | None. + bool_test: bool | None. + date_test: datetime.date | None. + datetime_test: datetime.datetime | None. + timestamp_test: datetime.datetime | None. + character_test: str | None. + varchar_test: str | None. + varyingcharacter_test: str | None. + nchar_test: str | None. + nativecharacter_test: str | None. + nvarchar_test: str | None. + text_test: str | None. + clob_test: str | None. + json_test: str | None. """ - self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, )) + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) - def delete_one_test_inner_sqlite_type(self, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + def get_one_sqlite_type(self, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. ```sql - DELETE FROM test_inner_sqlite_types - WHERE test_inner_sqlite_types.table_id = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Args: - table_id: int. + id_: int. + + Returns: + Result of type `models.TestSqliteType` fetched from the db. Will be `None` if not found. """ - self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, )) + row = self._conn.execute(GET_ONE_SQLITE_TYPE, (id_,)).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) - def delete_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Args: - id_: int. + table_id: int. Returns: - The result of type `sqlite3.Cursor` returned when executing the query. + Result of type `models.TestInnerSqliteType` fetched from the db. Will be `None` if not found. """ - return self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, )) + row = self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,)).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) - def delete_rows_one_sqlite_type(self, *, id_: int) -> int: - """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Args: id_: int. + date_test: datetime.date. Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + Result of type `datetime.date` fetched from the db. Will be `None` if not found. """ - return self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, )).rowcount + row = self._conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() + if row is None: + return None + return row[0] - def delete_type_override(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. + def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Args: id_: int. + datetime_test: datetime.datetime. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. """ - self._conn.execute(DELETE_TYPE_OVERRIDE, (id_, )) + row = self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. + def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Args: id_: int. - blob_test: memoryview. + timestamp_test: datetime.datetime. Returns: - Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. """ - return QueryResults[memoryview](self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + row = self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBool :many`. + def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -548,12 +804,15 @@ def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: bool_test: bool. Returns: - Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + Result of type `bool` fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + row = self._conn.execute(GET_ONE_BOOL, (id_, bool_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. + def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -564,57 +823,99 @@ def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool boolean_test: bool. Returns: - Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + Result of type `bool` fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + row = self._conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: - """Fetch many from the db using the SQL query with `name: GetManyDate :many`. + def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Args: id_: int. - date_test: datetime.date. + decimal_test: decimal.Decimal. Returns: - Helper class of type `QueryResults[datetime.date]` that allows both iteration and normal fetching of data from the db. + Result of type `decimal.Decimal` fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.date](self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + row = self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. + def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Args: id_: int. - datetime_test: datetime.datetime. + blob_test: memoryview. Returns: - Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + Result of type `memoryview` fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) + row = self._conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: - """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. + def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Args: id_: int. - decimal_test: decimal.Decimal. Returns: - Helper class of type `QueryResults[decimal.Decimal]` that allows both iteration and normal fetching of data from the db. + Helper class of type `QueryResults[models.TestSqliteType]` that allows both iteration and normal fetching of data from the db. """ - return QueryResults[decimal.Decimal](self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) def get_many_inner_sqlite_type(self, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. @@ -629,9 +930,41 @@ def get_many_inner_sqlite_type(self, *, table_id: int) -> QueryResults[models.Te Returns: Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. @@ -647,43 +980,73 @@ def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | Returns: Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) - def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. + def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Args: id_: int. + date_test: datetime.date. Returns: - Helper class of type `QueryResults[models.TestSqliteType]` that allows both iteration and normal fetching of data from the db. + Helper class of type `QueryResults[datetime.date]` that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestSqliteType](self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + return QueryResults(self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) - def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Args: id_: int. + datetime_test: datetime.datetime. Returns: - Helper class of type `QueryResults[UserString]` that allows both iteration and normal fetching of data from the db. + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> UserString: - return UserString(row[0]) - return QueryResults[UserString](self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + return QueryResults(self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. @@ -699,46 +1062,10 @@ def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> Returns: Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - - def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: - """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. - - ```sql - SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? - ``` - - Args: - id_: int. - - Returns: - Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. - """ - def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - return QueryResults[models.TestTypeOverride](self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) - - def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. - - ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? - ``` - - Args: - id_: int. - blob_test: memoryview. - - Returns: - Result of type `memoryview` fetched from the db. Will be `None` if not found. - """ - row = self._conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBool :one`. + def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -749,15 +1076,12 @@ def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: bool_test: bool. Returns: - Result of type `bool` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_BOOL, (id_, bool_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) - def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. + def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -768,53 +1092,12 @@ def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: boolean_test: bool. Returns: - Result of type `bool` fetched from the db. Will be `None` if not found. - """ - row = self._conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test)).fetchone() - if row is None: - return None - return row[0] - - def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: - """Fetch one from the db using the SQL query with `name: GetOneDate :one`. - - ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? - ``` - - Args: - id_: int. - date_test: datetime.date. - - Returns: - Result of type `datetime.date` fetched from the db. Will be `None` if not found. - """ - row = self._conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() - if row is None: - return None - return row[0] - - def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. - - ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? - ``` - - Args: - id_: int. - datetime_test: datetime.datetime. - - Returns: - Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) - def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: - """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. + def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. ```sql SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? @@ -825,106 +1108,87 @@ def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal decimal_test: decimal.Decimal. Returns: - Result of type `decimal.Decimal` fetched from the db. Will be `None` if not found. - """ - row = self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() - if row is None: - return None - return row[0] - - def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? - ``` - - Args: - table_id: int. - - Returns: - Result of type `models.TestInnerSqliteType` fetched from the db. Will be `None` if not found. - """ - row = self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id, )).fetchone() - if row is None: - return None - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - - def get_one_sqlite_type(self, *, id_: int) -> models.TestSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. - - ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? - ``` - - Args: - id_: int. - - Returns: - Result of type `models.TestSqliteType` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[decimal.Decimal]` that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_SQLITE_TYPE, (id_, )).fetchone() - if row is None: - return None - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) - def get_one_text_type_override(self, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Args: id_: int. + blob_test: memoryview. Returns: - Result of type `UserString` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_, )).fetchone() - if row is None: - return None - return UserString(row[0]) + return QueryResults(self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) - def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. + def delete_one_sqlite_type(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? ``` Args: id_: int. - timestamp_test: datetime.datetime. - - Returns: - Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. """ - row = self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() - if row is None: - return None - return row[0] + self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) - def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + def delete_one_test_inner_sqlite_type(self, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = ? + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? ``` - - Args: - id_: int. - - Returns: - Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. + + Args: + table_id: int. """ - row = self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_, )).fetchone() - if row is None: - return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) + self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) - def insert_last_id_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int | None: - """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. + def insert_result_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. ```sql INSERT INTO test_sqlite_types ( @@ -973,114 +1237,109 @@ def insert_last_id_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test json_test: str. Returns: - The id (`int | None`) of the last affected row. Will be `None` if no rows are affected. + The result of type `sqlite3.Cursor` returned when executing the query. """ - return self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)).lastrowid + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) - def insert_one_inner_sqlite_type(self, *, table_id: int, int_test: int | None, bigint_test: int | None, smallint_test: int | None, tinyint_test: int | None, int2_test: int | None, int8_test: int | None, bigserial_test: int | None, blob_test: memoryview | None, real_test: float | None, double_test: float | None, double_precision_test: float | None, float_test: float | None, numeric_test: float | None, decimal_test: decimal.Decimal | None, boolean_test: bool | None, bool_test: bool | None, date_test: datetime.date | None, datetime_test: datetime.datetime | None, timestamp_test: datetime.datetime | None, character_test: str | None, varchar_test: str | None, varyingcharacter_test: str | None, nchar_test: str | None, nativecharacter_test: str | None, nvarchar_test: str | None, text_test: str | None, clob_test: str | None, json_test: str | None) -> None: - """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. + def update_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. ```sql - INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? ``` Args: - table_id: int. - int_test: int | None. - bigint_test: int | None. - smallint_test: int | None. - tinyint_test: int | None. - int2_test: int | None. - int8_test: int | None. - bigserial_test: int | None. - blob_test: memoryview | None. - real_test: float | None. - double_test: float | None. - double_precision_test: float | None. - float_test: float | None. - numeric_test: float | None. - decimal_test: decimal.Decimal | None. - boolean_test: bool | None. - bool_test: bool | None. - date_test: datetime.date | None. - datetime_test: datetime.datetime | None. - timestamp_test: datetime.datetime | None. - character_test: str | None. - varchar_test: str | None. - varyingcharacter_test: str | None. - nchar_test: str | None. - nativecharacter_test: str | None. - nvarchar_test: str | None. - text_test: str | None. - clob_test: str | None. - json_test: str | None. + id_: int. + + Returns: + The result of type `sqlite3.Cursor` returned when executing the query. """ - self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, (table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + return self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) - def insert_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> None: - """Execute SQL query with `name: InsertOneSqliteType :exec`. + def delete_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. ```sql - INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? ``` Args: id_: int. - int_test: int. - bigint_test: int. - smallint_test: int. - tinyint_test: int. - int2_test: int. - int8_test: int. - bigserial_test: int. - blob_test: memoryview. - real_test: float. - double_test: float. - double_precision_test: float. - float_test: float. - numeric_test: float. - decimal_test: decimal.Decimal. - boolean_test: bool. - bool_test: bool. - date_test: datetime.date. - datetime_test: datetime.datetime. - timestamp_test: datetime.datetime. - character_test: str. - varchar_test: str. - varyingcharacter_test: str. - nchar_test: str. - nativecharacter_test: str. - nvarchar_test: str. - text_test: str. - clob_test: str. - json_test: str. + + Returns: + The result of type `sqlite3.Cursor` returned when executing the query. """ - self._conn.execute(INSERT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + return self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) - def insert_result_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. + def insert_rows_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. ```sql INSERT INTO test_sqlite_types ( @@ -1129,12 +1388,125 @@ def insert_result_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: json_test: str. Returns: - The result of type `sqlite3.Cursor` returned when executing the query. + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - return self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args).rowcount - def insert_rows_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int: - """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. + def update_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + def delete_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + def create_rows_table(self) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return self._conn.execute(CREATE_ROWS_TABLE).rowcount + + def insert_last_id_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. ```sql INSERT INTO test_sqlite_types ( @@ -1183,9 +1555,74 @@ def insert_rows_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: i json_test: str. Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args).lastrowid + + def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + return self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid + + def delete_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. """ - return self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)).rowcount + return self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: """Execute SQL query with `name: InsertTypeOverride :exec`. @@ -1200,55 +1637,92 @@ def insert_type_override(self, *, id_: int, text_test: UserString | None) -> Non id_: int. text_test: UserString | None. """ - self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test))) + self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) - def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: - """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE id = ? ``` Args: id_: int. Returns: - The id (`int | None`) of the last affected row. Will be `None` if no rows are affected. + Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. """ - return self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_, )).lastrowid + row = self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - def update_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? ``` Args: id_: int. Returns: - The result of type `sqlite3.Cursor` returned when executing the query. + Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. """ - return self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_, )) - def update_rows_one_sqlite_type(self, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + def get_one_text_type_override(self, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `UserString` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? ``` Args: id_: int. Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + Helper class of type `QueryResults[UserString | None]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + def delete_type_override(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Args: + id_: int. """ - return self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_, )).rowcount + self._conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_sqlite3/dataclass/classes/queries_case.py b/test/driver_sqlite3/dataclass/classes/queries_case.py new file mode 100644 index 00000000..84ad9514 --- /dev/null +++ b/test/driver_sqlite3/dataclass/classes/queries_case.py @@ -0,0 +1,163 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_case.sql +"""Module containing queries from file queries_case.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "GetCaseRowRow", + "QueriesCase", +) + +import dataclasses +import datetime +import decimal +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _convert_decimal(val: bytes) -> decimal.Decimal: + return decimal.Decimal(val.decode()) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + +sqlite3.register_converter("decimal", _convert_decimal) +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +@dataclasses.dataclass() +class GetCaseRowRow: + """Model representing GetCaseRowRow. + + Attributes: + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + """ + + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + + +INSERT_CASE_ROW: typing.Final[str] = """-- name: InsertCaseRow :exec +INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) +""" + +GET_CASE_ROW: typing.Final[str] = """-- name: GetCaseRow :one +SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? +""" + +INSERT_RESERVED_ARG: typing.Final[str] = """-- name: InsertReservedArg :exec +INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) +""" + +GET_RESERVED_ARG: typing.Final[str] = """-- name: GetReservedArg :one +SELECT id FROM test_reserved_args WHERE conn = ? +""" + + +class QueriesCase: + """Queries from file queries_case.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns: + Connection object of type `sqlite3.Connection` used to make queries. + """ + return self._conn + + def insert_case_row(self, *, id_: int, upper_dt: datetime.datetime, prec_dec: decimal.Decimal) -> None: + """Execute SQL query with `name: InsertCaseRow :exec`. + + ```sql + INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) + ``` + + Args: + id_: int. + upper_dt: datetime.datetime. + prec_dec: decimal.Decimal. + """ + self._conn.execute(INSERT_CASE_ROW, (id_, upper_dt, prec_dec)) + + def get_case_row(self, *, id_: int) -> GetCaseRowRow | None: + """Fetch one from the db using the SQL query with `name: GetCaseRow :one`. + + ```sql + SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `GetCaseRowRow` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_CASE_ROW, (id_,)).fetchone() + if row is None: + return None + return GetCaseRowRow(upper_dt=row[0], prec_dec=row[1]) + + def insert_reserved_arg(self, *, id_: int, conn: str) -> None: + """Execute SQL query with `name: InsertReservedArg :exec`. + + ```sql + INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) + ``` + + Args: + id_: int. + conn: str. + """ + self._conn.execute(INSERT_RESERVED_ARG, (id_, conn)) + + def get_reserved_arg(self, *, conn: str) -> int | None: + """Fetch one from the db using the SQL query with `name: GetReservedArg :one`. + + ```sql + SELECT id FROM test_reserved_args WHERE conn = ? + ``` + + Args: + conn: str. + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_RESERVED_ARG, (conn,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/dataclass/classes/queries_override_adapter.py b/test/driver_sqlite3/dataclass/classes/queries_override_adapter.py new file mode 100644 index 00000000..cdbcccb6 --- /dev/null +++ b/test/driver_sqlite3/dataclass/classes/queries_override_adapter.py @@ -0,0 +1,95 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_adapter.sql +"""Module containing queries from file queries_override_adapter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("QueriesOverrideAdapter",) + +import datetime +import decimal +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + + +INSERT_OVERRIDE_CONVERSION: typing.Final[str] = """-- name: InsertOverrideConversion :exec +INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) +""" + +GET_OVERRIDE_PRICE: typing.Final[str] = """-- name: GetOverridePrice :one +SELECT price FROM test_override_conversion WHERE id = ? +""" + + +class QueriesOverrideAdapter: + """Queries from file queries_override_adapter.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns: + Connection object of type `sqlite3.Connection` used to make queries. + """ + return self._conn + + def insert_override_conversion(self, *, id_: int, price: float, happened_at: datetime.datetime) -> None: + """Execute SQL query with `name: InsertOverrideConversion :exec`. + + ```sql + INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) + ``` + + Args: + id_: int. + price: float. + happened_at: datetime.datetime. + """ + self._conn.execute(INSERT_OVERRIDE_CONVERSION, (id_, decimal.Decimal(price), happened_at)) + + def get_override_price(self, *, id_: int) -> float | None: + """Fetch one from the db using the SQL query with `name: GetOverridePrice :one`. + + ```sql + SELECT price FROM test_override_conversion WHERE id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `float` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_OVERRIDE_PRICE, (id_,)).fetchone() + if row is None: + return None + return float(row[0]) diff --git a/test/driver_sqlite3/dataclass/classes/queries_override_converter.py b/test/driver_sqlite3/dataclass/classes/queries_override_converter.py new file mode 100644 index 00000000..4e142b82 --- /dev/null +++ b/test/driver_sqlite3/dataclass/classes/queries_override_converter.py @@ -0,0 +1,72 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_converter.sql +"""Module containing queries from file queries_override_converter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("QueriesOverrideConverter",) + +import datetime +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +GET_OVERRIDE_HAPPENED_AT: typing.Final[str] = """-- name: GetOverrideHappenedAt :one +SELECT happened_at FROM test_override_conversion WHERE id = ? +""" + + +class QueriesOverrideConverter: + """Queries from file queries_override_converter.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns: + Connection object of type `sqlite3.Connection` used to make queries. + """ + return self._conn + + def get_override_happened_at(self, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOverrideHappenedAt :one`. + + ```sql + SELECT happened_at FROM test_override_conversion WHERE id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_OVERRIDE_HAPPENED_AT, (id_,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/dataclass/functions/__init__.py b/test/driver_sqlite3/dataclass/functions/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_sqlite3/dataclass/functions/__init__.py +++ b/test/driver_sqlite3/dataclass/functions/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_sqlite3/dataclass/functions/models.py b/test/driver_sqlite3/dataclass/functions/models.py index 086490f6..42ec832a 100644 --- a/test/driver_sqlite3/dataclass/functions/models.py +++ b/test/driver_sqlite3/dataclass/functions/models.py @@ -1,8 +1,9 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -93,7 +94,7 @@ class TestSqliteType: """Model representing TestSqliteType. Attributes: - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -124,7 +125,7 @@ class TestSqliteType: json_test: str """ - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -160,9 +161,9 @@ class TestTypeOverride: """Model representing TestTypeOverride. Attributes: - id: int + id_: int text_test: UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_sqlite3/dataclass/functions/queries.py b/test/driver_sqlite3/dataclass/functions/queries.py index 2b63420f..5e51d3d5 100644 --- a/test/driver_sqlite3/dataclass/functions/queries.py +++ b/test/driver_sqlite3/dataclass/functions/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -58,7 +60,7 @@ if typing.TYPE_CHECKING: import collections.abc - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None from test.driver_sqlite3.dataclass.functions import models @@ -118,71 +120,74 @@ def _convert_memoryview(val: bytes) -> memoryview: sqlite3.register_converter("blob", _convert_memoryview) -CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows -CREATE TABLE test_create_rows_table -( - id int PRIMARY KEY NOT NULL, - test int NOT NULL -) -""" - -DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec -DELETE FROM test_inner_sqlite_types -WHERE test_inner_sqlite_types.table_id = ? +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ -DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? """ -DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec -DELETE -FROM test_type_override -WHERE test_type_override.id = ? +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ -GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many -SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many @@ -193,67 +198,46 @@ def _convert_memoryview(val: bytes) -> memoryview: SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? """ -GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? -""" - -GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? -""" - -GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? -""" - -GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? -""" - -GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one -SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? -""" - -GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one -SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = ? +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? """ -INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -268,37 +252,19 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec -INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? """ -INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec -INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -313,7 +279,27 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -328,35 +314,48 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec INSERT INTO test_type_override ( id, text_test ) VALUES (? ,?) """ -UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? """ -UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? """ -UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? """ +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" -T = typing.TypeVar("T") +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db.""" __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") @@ -427,158 +426,410 @@ def __next__(self) -> T: return self._decode_hook(record) -def create_rows_table(conn: sqlite3.Connection) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. +def insert_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Args: - conn: - Connection object of type `sqlite3.Connection` used to execute the query. - - Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. - """ - return conn.execute(CREATE_ROWS_TABLE).rowcount - - -def delete_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: - """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. id_: int. - - Returns: - The id (`int | None`) of the last affected row. Will be `None` if no rows are affected. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. """ - return conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, )).lastrowid - - -def delete_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneSqliteType :exec`. + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) + + +def insert_one_inner_sqlite_type( + conn: sqlite3.Connection, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, +) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. - id_: int. + table_id: int. + int_test: int | None. + bigint_test: int | None. + smallint_test: int | None. + tinyint_test: int | None. + int2_test: int | None. + int8_test: int | None. + bigserial_test: int | None. + blob_test: memoryview | None. + real_test: float | None. + double_test: float | None. + double_precision_test: float | None. + float_test: float | None. + numeric_test: float | None. + decimal_test: decimal.Decimal | None. + boolean_test: bool | None. + bool_test: bool | None. + date_test: datetime.date | None. + datetime_test: datetime.datetime | None. + timestamp_test: datetime.datetime | None. + character_test: str | None. + varchar_test: str | None. + varyingcharacter_test: str | None. + nchar_test: str | None. + nativecharacter_test: str | None. + nvarchar_test: str | None. + text_test: str | None. + clob_test: str | None. + json_test: str | None. """ - conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, )) + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) -def delete_one_test_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. +def get_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. ```sql - DELETE FROM test_inner_sqlite_types - WHERE test_inner_sqlite_types.table_id = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. - table_id: int. + id_: int. + + Returns: + Result of type `models.TestSqliteType` fetched from the db. Will be `None` if not found. """ - conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, )) + row = conn.execute(GET_ONE_SQLITE_TYPE, (id_,)).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) -def delete_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. +def get_one_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. - id_: int. + table_id: int. Returns: - The result of type `sqlite3.Cursor` returned when executing the query. + Result of type `models.TestInnerSqliteType` fetched from the db. Will be `None` if not found. """ - return conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, )) + row = conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,)).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) -def delete_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: - """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. +def get_one_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. id_: int. + date_test: datetime.date. Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + Result of type `datetime.date` fetched from the db. Will be `None` if not found. """ - return conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, )).rowcount + row = conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() + if row is None: + return None + return row[0] -def delete_type_override(conn: sqlite3.Connection, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. +def get_one_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. id_: int. + datetime_test: datetime.datetime. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. """ - conn.execute(DELETE_TYPE_OVERRIDE, (id_, )) + row = conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. +def get_one_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. id_: int. - blob_test: memoryview. + timestamp_test: datetime.datetime. Returns: - Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. """ - return QueryResults[memoryview](conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + row = conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBool :many`. +def get_one_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -591,13 +842,16 @@ def get_many_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> Que bool_test: bool. Returns: - Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + Result of type `bool` fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + row = conn.execute(GET_ONE_BOOL, (id_, bool_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. +def get_one_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -610,66 +864,108 @@ def get_many_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) boolean_test: bool. Returns: - Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + Result of type `bool` fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + row = conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: - """Fetch many from the db using the SQL query with `name: GetManyDate :many`. +def get_one_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. id_: int. - date_test: datetime.date. + decimal_test: decimal.Decimal. Returns: - Helper class of type `QueryResults[datetime.date]` that allows both iteration and normal fetching of data from the db. + Result of type `decimal.Decimal` fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.date](conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + row = conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. +def get_one_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. id_: int. - datetime_test: datetime.datetime. + blob_test: memoryview. Returns: - Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + Result of type `memoryview` fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.datetime](conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) + row = conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: - """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. +def get_many_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. id_: int. - decimal_test: decimal.Decimal. Returns: - Helper class of type `QueryResults[decimal.Decimal]` that allows both iteration and normal fetching of data from the db. + Helper class of type `QueryResults[models.TestSqliteType]` that allows both iteration and normal fetching of data from the db. """ - return QueryResults[decimal.Decimal](conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) def get_many_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: @@ -687,9 +983,41 @@ def get_many_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> Qu Returns: Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) def get_many_nullable_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: @@ -708,49 +1036,79 @@ def get_many_nullable_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: i Returns: Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) -def get_many_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. +def get_many_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. id_: int. + date_test: datetime.date. Returns: - Helper class of type `QueryResults[models.TestSqliteType]` that allows both iteration and normal fetching of data from the db. + Helper class of type `QueryResults[datetime.date]` that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestSqliteType](conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + return QueryResults(conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) -def get_many_text_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. +def get_many_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. id_: int. + datetime_test: datetime.datetime. Returns: - Helper class of type `QueryResults[UserString]` that allows both iteration and normal fetching of data from the db. + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> UserString: - return UserString(row[0]) - return QueryResults[UserString](conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + return QueryResults(conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) def get_many_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: @@ -769,53 +1127,11 @@ def get_many_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: da Returns: Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. """ - return QueryResults[datetime.datetime](conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - + return QueryResults(conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) -def get_many_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: - """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. - ```sql - SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? - ``` - - Args: - conn: - Connection object of type `sqlite3.Connection` used to execute the query. - id_: int. - - Returns: - Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. - """ - def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - return QueryResults[models.TestTypeOverride](conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) - - -def get_one_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. - - ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? - ``` - - Args: - conn: - Connection object of type `sqlite3.Connection` used to execute the query. - id_: int. - blob_test: memoryview. - - Returns: - Result of type `memoryview` fetched from the db. Will be `None` if not found. - """ - row = conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() - if row is None: - return None - return row[0] - - -def get_one_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBool :one`. +def get_many_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -828,16 +1144,13 @@ def get_one_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> bool bool_test: bool. Returns: - Result of type `bool` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_BOOL, (id_, bool_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) -def get_one_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. +def get_many_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -850,60 +1163,13 @@ def get_one_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) - boolean_test: bool. Returns: - Result of type `bool` fetched from the db. Will be `None` if not found. - """ - row = conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test)).fetchone() - if row is None: - return None - return row[0] - - -def get_one_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: - """Fetch one from the db using the SQL query with `name: GetOneDate :one`. - - ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? - ``` - - Args: - conn: - Connection object of type `sqlite3.Connection` used to execute the query. - id_: int. - date_test: datetime.date. - - Returns: - Result of type `datetime.date` fetched from the db. Will be `None` if not found. - """ - row = conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() - if row is None: - return None - return row[0] - - -def get_one_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. - - ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? - ``` - - Args: - conn: - Connection object of type `sqlite3.Connection` used to execute the query. - id_: int. - datetime_test: datetime.datetime. - - Returns: - Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) -def get_one_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: - """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. +def get_many_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. ```sql SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? @@ -916,122 +1182,97 @@ def get_one_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal decimal_test: decimal.Decimal. Returns: - Result of type `decimal.Decimal` fetched from the db. Will be `None` if not found. - """ - row = conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() - if row is None: - return None - return row[0] - - -def get_one_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? - ``` - - Args: - conn: - Connection object of type `sqlite3.Connection` used to execute the query. - table_id: int. - - Returns: - Result of type `models.TestInnerSqliteType` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[decimal.Decimal]` that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id, )).fetchone() - if row is None: - return None - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) -def get_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> models.TestSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. +def get_many_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. id_: int. + blob_test: memoryview. Returns: - Result of type `models.TestSqliteType` fetched from the db. Will be `None` if not found. + Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_SQLITE_TYPE, (id_, )).fetchone() - if row is None: - return None - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) -def get_one_text_type_override(conn: sqlite3.Connection, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. +def delete_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. id_: int. - - Returns: - Result of type `UserString` fetched from the db. Will be `None` if not found. """ - row = conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_, )).fetchone() - if row is None: - return None - return UserString(row[0]) - + conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) -def get_one_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. - ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? - ``` - - Args: - conn: - Connection object of type `sqlite3.Connection` used to execute the query. - id_: int. - timestamp_test: datetime.datetime. - - Returns: - Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. - """ - row = conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() - if row is None: - return None - return row[0] - - -def get_one_type_override(conn: sqlite3.Connection, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. +def delete_one_test_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = ? + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. - id_: int. - - Returns: - Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. + table_id: int. """ - row = conn.execute(GET_ONE_TYPE_OVERRIDE, (id_, )).fetchone() - if row is None: - return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - - -def insert_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int | None: - """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. + conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) + + +def insert_result_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. ```sql INSERT INTO test_sqlite_types ( @@ -1082,67 +1323,116 @@ def insert_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_te json_test: str. Returns: - The id (`int | None`) of the last affected row. Will be `None` if no rows are affected. + The result of type `sqlite3.Cursor` returned when executing the query. """ - return conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)).lastrowid + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) -def insert_one_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int, int_test: int | None, bigint_test: int | None, smallint_test: int | None, tinyint_test: int | None, int2_test: int | None, int8_test: int | None, bigserial_test: int | None, blob_test: memoryview | None, real_test: float | None, double_test: float | None, double_precision_test: float | None, float_test: float | None, numeric_test: float | None, decimal_test: decimal.Decimal | None, boolean_test: bool | None, bool_test: bool | None, date_test: datetime.date | None, datetime_test: datetime.datetime | None, timestamp_test: datetime.datetime | None, character_test: str | None, varchar_test: str | None, varyingcharacter_test: str | None, nchar_test: str | None, nativecharacter_test: str | None, nvarchar_test: str | None, text_test: str | None, clob_test: str | None, json_test: str | None) -> None: - """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. +def update_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. ```sql - INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. - table_id: int. - int_test: int | None. - bigint_test: int | None. - smallint_test: int | None. - tinyint_test: int | None. - int2_test: int | None. - int8_test: int | None. - bigserial_test: int | None. - blob_test: memoryview | None. - real_test: float | None. - double_test: float | None. - double_precision_test: float | None. - float_test: float | None. - numeric_test: float | None. - decimal_test: decimal.Decimal | None. - boolean_test: bool | None. - bool_test: bool | None. - date_test: datetime.date | None. - datetime_test: datetime.datetime | None. - timestamp_test: datetime.datetime | None. - character_test: str | None. - varchar_test: str | None. - varyingcharacter_test: str | None. - nchar_test: str | None. - nativecharacter_test: str | None. - nvarchar_test: str | None. - text_test: str | None. - clob_test: str | None. - json_test: str | None. + id_: int. + + Returns: + The result of type `sqlite3.Cursor` returned when executing the query. """ - conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, (table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + return conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) -def insert_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> None: - """Execute SQL query with `name: InsertOneSqliteType :exec`. +def delete_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + The result of type `sqlite3.Cursor` returned when executing the query. + """ + return conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +def insert_rows_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. ```sql INSERT INTO test_sqlite_types ( @@ -1191,69 +1481,139 @@ def insert_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, text_test: str. clob_test: str. json_test: str. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - conn.execute(INSERT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args).rowcount -def insert_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. +def update_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. ```sql - INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? ``` Args: conn: Connection object of type `sqlite3.Connection` used to execute the query. id_: int. - int_test: int. - bigint_test: int. - smallint_test: int. - tinyint_test: int. - int2_test: int. - int8_test: int. - bigserial_test: int. - blob_test: memoryview. - real_test: float. - double_test: float. - double_precision_test: float. - float_test: float. - numeric_test: float. - decimal_test: decimal.Decimal. - boolean_test: bool. - bool_test: bool. - date_test: datetime.date. - datetime_test: datetime.datetime. - timestamp_test: datetime.datetime. - character_test: str. - varchar_test: str. - varyingcharacter_test: str. - nchar_test: str. - nativecharacter_test: str. - nvarchar_test: str. - text_test: str. - clob_test: str. - json_test: str. Returns: - The result of type `sqlite3.Cursor` returned when executing the query. + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - return conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + return conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount -def insert_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int: - """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. +def delete_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + +def create_rows_table(conn: sqlite3.Connection) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return conn.execute(CREATE_ROWS_TABLE).rowcount + + +def insert_last_id_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. ```sql INSERT INTO test_sqlite_types ( @@ -1304,9 +1664,80 @@ def insert_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: json_test: str. Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args).lastrowid + + +def update_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. """ - return conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)).rowcount + return conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid + + +def delete_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + return conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid def insert_type_override(conn: sqlite3.Connection, *, id_: int, text_test: UserString | None) -> None: @@ -1324,16 +1755,14 @@ def insert_type_override(conn: sqlite3.Connection, *, id_: int, text_test: UserS id_: int. text_test: UserString | None. """ - conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test))) + conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) -def update_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: - """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. +def get_one_type_override(conn: sqlite3.Connection, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE id = ? ``` Args: @@ -1342,18 +1771,19 @@ def update_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int id_: int. Returns: - The id (`int | None`) of the last affected row. Will be `None` if no rows are affected. + Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. """ - return conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_, )).lastrowid + row = conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) -def update_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. +def get_many_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? ``` Args: @@ -1362,18 +1792,20 @@ def update_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqli id_: int. Returns: - The result of type `sqlite3.Cursor` returned when executing the query. + Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. """ - return conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_, )) + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) -def update_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + +def get_one_text_type_override(conn: sqlite3.Connection, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? ``` Args: @@ -1382,6 +1814,48 @@ def update_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: id_: int. Returns: - The number (`int`) of affected rows. This will be 0 for queries like `CREATE TABLE`. + Result of type `UserString` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + +def get_many_text_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[UserString | None]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + +def delete_type_override(conn: sqlite3.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. """ - return conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_, )).rowcount + conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_sqlite3/dataclass/functions/queries_case.py b/test/driver_sqlite3/dataclass/functions/queries_case.py new file mode 100644 index 00000000..5b607d8c --- /dev/null +++ b/test/driver_sqlite3/dataclass/functions/queries_case.py @@ -0,0 +1,154 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_case.sql +"""Module containing queries from file queries_case.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "GetCaseRowRow", + "get_case_row", + "get_reserved_arg", + "insert_case_row", + "insert_reserved_arg", +) + +import dataclasses +import datetime +import decimal +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _convert_decimal(val: bytes) -> decimal.Decimal: + return decimal.Decimal(val.decode()) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + +sqlite3.register_converter("decimal", _convert_decimal) +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +@dataclasses.dataclass() +class GetCaseRowRow: + """Model representing GetCaseRowRow. + + Attributes: + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + """ + + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + + +INSERT_CASE_ROW: typing.Final[str] = """-- name: InsertCaseRow :exec +INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) +""" + +GET_CASE_ROW: typing.Final[str] = """-- name: GetCaseRow :one +SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? +""" + +INSERT_RESERVED_ARG: typing.Final[str] = """-- name: InsertReservedArg :exec +INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) +""" + +GET_RESERVED_ARG: typing.Final[str] = """-- name: GetReservedArg :one +SELECT id FROM test_reserved_args WHERE conn = ? +""" + + +def insert_case_row(conn: sqlite3.Connection, *, id_: int, upper_dt: datetime.datetime, prec_dec: decimal.Decimal) -> None: + """Execute SQL query with `name: InsertCaseRow :exec`. + + ```sql + INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + upper_dt: datetime.datetime. + prec_dec: decimal.Decimal. + """ + conn.execute(INSERT_CASE_ROW, (id_, upper_dt, prec_dec)) + + +def get_case_row(conn: sqlite3.Connection, *, id_: int) -> GetCaseRowRow | None: + """Fetch one from the db using the SQL query with `name: GetCaseRow :one`. + + ```sql + SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Result of type `GetCaseRowRow` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_CASE_ROW, (id_,)).fetchone() + if row is None: + return None + return GetCaseRowRow(upper_dt=row[0], prec_dec=row[1]) + + +def insert_reserved_arg(conn: sqlite3.Connection, *, id_: int, conn_2: str) -> None: + """Execute SQL query with `name: InsertReservedArg :exec`. + + ```sql + INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + conn_2: str. + """ + conn.execute(INSERT_RESERVED_ARG, (id_, conn_2)) + + +def get_reserved_arg(conn: sqlite3.Connection, *, conn_2: str) -> int | None: + """Fetch one from the db using the SQL query with `name: GetReservedArg :one`. + + ```sql + SELECT id FROM test_reserved_args WHERE conn = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + conn_2: str. + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_RESERVED_ARG, (conn_2,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/dataclass/functions/queries_override_adapter.py b/test/driver_sqlite3/dataclass/functions/queries_override_adapter.py new file mode 100644 index 00000000..8e3390cc --- /dev/null +++ b/test/driver_sqlite3/dataclass/functions/queries_override_adapter.py @@ -0,0 +1,80 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_adapter.sql +"""Module containing queries from file queries_override_adapter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "get_override_price", + "insert_override_conversion", +) + +import datetime +import decimal +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + + +INSERT_OVERRIDE_CONVERSION: typing.Final[str] = """-- name: InsertOverrideConversion :exec +INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) +""" + +GET_OVERRIDE_PRICE: typing.Final[str] = """-- name: GetOverridePrice :one +SELECT price FROM test_override_conversion WHERE id = ? +""" + + +def insert_override_conversion(conn: sqlite3.Connection, *, id_: int, price: float, happened_at: datetime.datetime) -> None: + """Execute SQL query with `name: InsertOverrideConversion :exec`. + + ```sql + INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + price: float. + happened_at: datetime.datetime. + """ + conn.execute(INSERT_OVERRIDE_CONVERSION, (id_, decimal.Decimal(price), happened_at)) + + +def get_override_price(conn: sqlite3.Connection, *, id_: int) -> float | None: + """Fetch one from the db using the SQL query with `name: GetOverridePrice :one`. + + ```sql + SELECT price FROM test_override_conversion WHERE id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Result of type `float` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_OVERRIDE_PRICE, (id_,)).fetchone() + if row is None: + return None + return float(row[0]) diff --git a/test/driver_sqlite3/dataclass/functions/queries_override_converter.py b/test/driver_sqlite3/dataclass/functions/queries_override_converter.py new file mode 100644 index 00000000..42151a7d --- /dev/null +++ b/test/driver_sqlite3/dataclass/functions/queries_override_converter.py @@ -0,0 +1,51 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_converter.sql +"""Module containing queries from file queries_override_converter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("get_override_happened_at",) + +import datetime +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +GET_OVERRIDE_HAPPENED_AT: typing.Final[str] = """-- name: GetOverrideHappenedAt :one +SELECT happened_at FROM test_override_conversion WHERE id = ? +""" + + +def get_override_happened_at(conn: sqlite3.Connection, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOverrideHappenedAt :one`. + + ```sql + SELECT happened_at FROM test_override_conversion WHERE id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_OVERRIDE_HAPPENED_AT, (id_,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/dataclass/test_sqlite3_dataclass_classes.py b/test/driver_sqlite3/dataclass/test_sqlite3_dataclass_classes.py index 12517b61..edc22164 100644 --- a/test/driver_sqlite3/dataclass/test_sqlite3_dataclass_classes.py +++ b/test/driver_sqlite3/dataclass/test_sqlite3_dataclass_classes.py @@ -36,12 +36,12 @@ class TestSqlite3DataclassClasses: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestSqliteType: return models.TestSqliteType( - id=random.randint(1, 10000000), + id_=random.randint(1, 10000000), int_test=42, bigint_test=9_007_199_254_740_991, smallint_test=32_767, @@ -75,7 +75,7 @@ def model(self) -> models.TestSqliteType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: return models.TestInnerSqliteType( - table_id=model.id, + table_id=model.id_, int_test=None, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -120,7 +120,7 @@ def test_insert( model: models.TestSqliteType, ) -> None: queries_obj.insert_one_sqlite_type( - id_=model.id, + id_=model.id_, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -151,9 +151,7 @@ def test_insert( json_test=model.json_test, ) - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::inner_insert", depends=["Sqlite3TestDataclassClasses::insert"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::inner_insert", depends=["Sqlite3TestDataclassClasses::insert"]) def test_inner_insert( self, queries_obj: queries.Queries, @@ -191,15 +189,13 @@ def test_inner_insert( json_test=inner_model.json_test, ) - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_one", depends=["Sqlite3TestDataclassClasses::inner_insert"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_one", depends=["Sqlite3TestDataclassClasses::inner_insert"]) def test_get_one( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_sqlite_type(id_=model.id) + result = queries_obj.get_one_sqlite_type(id_=model.id_) assert result is not None @@ -207,9 +203,7 @@ def test_get_one( assert result == model - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_one_none", depends=["Sqlite3TestDataclassClasses::get_one"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_one_none", depends=["Sqlite3TestDataclassClasses::get_one"]) def test_get_one_none( self, queries_obj: queries.Queries, @@ -218,9 +212,7 @@ def test_get_one_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_one_inner", depends=["Sqlite3TestDataclassClasses::get_one_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_one_inner", depends=["Sqlite3TestDataclassClasses::get_one_none"]) def test_get_one_inner( self, queries_obj: queries.Queries, @@ -233,9 +225,7 @@ def test_get_one_inner( assert isinstance(result, models.TestInnerSqliteType) assert result == inner_model - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_one_inner_none", depends=["Sqlite3TestDataclassClasses::get_one_inner"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_one_inner_none", depends=["Sqlite3TestDataclassClasses::get_one_inner"]) def test_get_one_inner_none( self, queries_obj: queries.Queries, @@ -244,24 +234,20 @@ def test_get_one_inner_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_date", depends=["Sqlite3TestDataclassClasses::get_one_inner_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_date", depends=["Sqlite3TestDataclassClasses::get_one_inner_none"]) def test_get_date( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_date(id_=model.id, date_test=model.date_test) + result = queries_obj.get_one_date(id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, datetime.date) assert result == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_date_none", depends=["Sqlite3TestDataclassClasses::get_date"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_date_none", depends=["Sqlite3TestDataclassClasses::get_date"]) def test_get_date_none( self, queries_obj: queries.Queries, @@ -270,24 +256,20 @@ def test_get_date_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_datetime", depends=["Sqlite3TestDataclassClasses::get_date_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_datetime", depends=["Sqlite3TestDataclassClasses::get_date_none"]) def test_get_datetime( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_datetime(id_=model.id, datetime_test=model.datetime_test) + result = queries_obj.get_one_datetime(id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.datetime_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_datetime_none", depends=["Sqlite3TestDataclassClasses::get_datetime"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_datetime_none", depends=["Sqlite3TestDataclassClasses::get_datetime"]) def test_get_datetime_none( self, queries_obj: queries.Queries, @@ -296,24 +278,20 @@ def test_get_datetime_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_timestamp", depends=["Sqlite3TestDataclassClasses::get_datetime_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_timestamp", depends=["Sqlite3TestDataclassClasses::get_datetime_none"]) def test_get_timestamp( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_timestamp(id_=model.id, timestamp_test=model.timestamp_test) + result = queries_obj.get_one_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_timestamp_none", depends=["Sqlite3TestDataclassClasses::get_timestamp"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_timestamp_none", depends=["Sqlite3TestDataclassClasses::get_timestamp"]) def test_get_timestamp_none( self, queries_obj: queries.Queries, @@ -322,24 +300,20 @@ def test_get_timestamp_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_bool", depends=["Sqlite3TestDataclassClasses::get_timestamp_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_bool", depends=["Sqlite3TestDataclassClasses::get_timestamp_none"]) def test_get_bool( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_bool(id_=model.id, bool_test=model.bool_test) + result = queries_obj.get_one_bool(id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, bool) assert result == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_bool_none", depends=["Sqlite3TestDataclassClasses::get_bool"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_bool_none", depends=["Sqlite3TestDataclassClasses::get_bool"]) def test_get_bool_none( self, queries_obj: queries.Queries, @@ -348,24 +322,20 @@ def test_get_bool_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_boolean", depends=["Sqlite3TestDataclassClasses::get_bool_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_boolean", depends=["Sqlite3TestDataclassClasses::get_bool_none"]) def test_get_boolean( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_boolean(id_=model.id, boolean_test=model.boolean_test) + result = queries_obj.get_one_boolean(id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, bool) assert result == model.boolean_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_boolean_none", depends=["Sqlite3TestDataclassClasses::get_boolean"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_boolean_none", depends=["Sqlite3TestDataclassClasses::get_boolean"]) def test_get_boolean_none( self, queries_obj: queries.Queries, @@ -374,24 +344,20 @@ def test_get_boolean_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_decimal", depends=["Sqlite3TestDataclassClasses::get_boolean_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_decimal", depends=["Sqlite3TestDataclassClasses::get_boolean_none"]) def test_get_decimal( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_decimal(id_=model.id, decimal_test=model.decimal_test) + result = queries_obj.get_one_decimal(id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, decimal.Decimal) assert result == model.decimal_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_decimal_none", depends=["Sqlite3TestDataclassClasses::get_decimal"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_decimal_none", depends=["Sqlite3TestDataclassClasses::get_decimal"]) def test_get_decimal_none( self, queries_obj: queries.Queries, @@ -400,24 +366,20 @@ def test_get_decimal_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_blob", depends=["Sqlite3TestDataclassClasses::get_decimal_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_blob", depends=["Sqlite3TestDataclassClasses::get_decimal_none"]) def test_get_blob( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_blob(id_=model.id, blob_test=model.blob_test) + result = queries_obj.get_one_blob(id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_blob_none", depends=["Sqlite3TestDataclassClasses::get_blob"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_blob_none", depends=["Sqlite3TestDataclassClasses::get_blob"]) def test_get_blob_none( self, queries_obj: queries.Queries, @@ -426,11 +388,9 @@ def test_get_blob_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_many", depends=["Sqlite3TestDataclassClasses::get_blob_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_many", depends=["Sqlite3TestDataclassClasses::get_blob_none"]) def test_get_many(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_sqlite_type(id_=model.id) + result = queries_obj.get_many_sqlite_type(id_=model.id_) assert result is not None assert isinstance(result, queries.QueryResults) @@ -444,19 +404,15 @@ def test_get_many(self, queries_obj: queries.Queries, model: models.TestSqliteTy assert results[0] == model - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_many_iter", depends=["Sqlite3TestDataclassClasses::get_many"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_many_iter", depends=["Sqlite3TestDataclassClasses::get_many"]) def test_get_many_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_sqlite_type(id_=model.id): + for result in queries_obj.get_many_sqlite_type(id_=model.id_): assert result is not None assert isinstance(result, models.TestSqliteType) assert result == model - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_many_inner", depends=["Sqlite3TestDataclassClasses::get_many_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_many_inner", depends=["Sqlite3TestDataclassClasses::get_many_iter"]) def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: result = queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id) @@ -467,9 +423,7 @@ def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: models. assert results[0] == inner_model - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_many_inner_iter", depends=["Sqlite3TestDataclassClasses::get_many_inner"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_many_inner_iter", depends=["Sqlite3TestDataclassClasses::get_many_inner"]) def test_get_many_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: for result in queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id): assert result is not None @@ -482,12 +436,8 @@ def test_get_many_inner_iter(self, queries_obj: queries.Queries, inner_model: mo name="Sqlite3TestDataclassClasses::get_many_nullable_inner", depends=["Sqlite3TestDataclassClasses::get_many_inner_iter"], ) - async def test_get_many_nullable_inner( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: - result = queries_obj.get_many_nullable_inner_sqlite_type( - table_id=inner_model.table_id, int_test=inner_model.int_test - ) + async def test_get_many_nullable_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + result = queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -501,12 +451,8 @@ async def test_get_many_nullable_inner( name="Sqlite3TestDataclassClasses::get_many_nullable_inner_iter", depends=["Sqlite3TestDataclassClasses::get_many_nullable_inner"], ) - async def test_get_many_nullable_inner_iter( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: - for result in queries_obj.get_many_nullable_inner_sqlite_type( - table_id=inner_model.table_id, int_test=inner_model.int_test - ): + async def test_get_many_nullable_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + for result in queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -517,7 +463,7 @@ async def test_get_many_nullable_inner_iter( depends=["Sqlite3TestDataclassClasses::get_many_nullable_inner_iter"], ) def test_get_many_date(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_date(id_=model.id, date_test=model.date_test) + result = queries_obj.get_many_date(id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -526,11 +472,9 @@ def test_get_many_date(self, queries_obj: queries.Queries, model: models.TestSql assert results[0] == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_many_date_iter", depends=["Sqlite3TestDataclassClasses::get_many_date"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_many_date_iter", depends=["Sqlite3TestDataclassClasses::get_many_date"]) def test_get_many_date_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_date(id_=model.id, date_test=model.date_test): + for result in queries_obj.get_many_date(id_=model.id_, date_test=model.date_test): assert result is not None assert isinstance(result, datetime.date) @@ -541,7 +485,7 @@ def test_get_many_date_iter(self, queries_obj: queries.Queries, model: models.Te depends=["Sqlite3TestDataclassClasses::get_many_date_iter"], ) def test_get_many_datetime(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_datetime(id_=model.id, datetime_test=model.datetime_test) + result = queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -555,7 +499,7 @@ def test_get_many_datetime(self, queries_obj: queries.Queries, model: models.Tes depends=["Sqlite3TestDataclassClasses::get_many_datetime"], ) def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_datetime(id_=model.id, datetime_test=model.datetime_test): + for result in queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -566,7 +510,7 @@ def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: model depends=["Sqlite3TestDataclassClasses::get_many_datetime_iter"], ) def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_timestamp(id_=model.id, timestamp_test=model.timestamp_test) + result = queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -580,7 +524,7 @@ def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.Te depends=["Sqlite3TestDataclassClasses::get_many_timestamp"], ) def test_get_many_timestamp_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_timestamp(id_=model.id, timestamp_test=model.timestamp_test): + for result in queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -591,7 +535,7 @@ def test_get_many_timestamp_iter(self, queries_obj: queries.Queries, model: mode depends=["Sqlite3TestDataclassClasses::get_many_timestamp_iter"], ) def test_get_many_bool(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_bool(id_=model.id, bool_test=model.bool_test) + result = queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -600,11 +544,9 @@ def test_get_many_bool(self, queries_obj: queries.Queries, model: models.TestSql assert results[0] == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_many_bool_iter", depends=["Sqlite3TestDataclassClasses::get_many_bool"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_many_bool_iter", depends=["Sqlite3TestDataclassClasses::get_many_bool"]) def test_get_many_bool_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_bool(id_=model.id, bool_test=model.bool_test): + for result in queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test): assert result is not None assert isinstance(result, bool) @@ -615,7 +557,7 @@ def test_get_many_bool_iter(self, queries_obj: queries.Queries, model: models.Te depends=["Sqlite3TestDataclassClasses::get_many_bool_iter"], ) def test_get_many_boolean(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_boolean(id_=model.id, boolean_test=model.boolean_test) + result = queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -629,7 +571,7 @@ def test_get_many_boolean(self, queries_obj: queries.Queries, model: models.Test depends=["Sqlite3TestDataclassClasses::get_many_boolean"], ) def test_get_many_boolean_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_boolean(id_=model.id, boolean_test=model.boolean_test): + for result in queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test): assert result is not None assert isinstance(result, bool) @@ -640,7 +582,7 @@ def test_get_many_boolean_iter(self, queries_obj: queries.Queries, model: models depends=["Sqlite3TestDataclassClasses::get_many_boolean_iter"], ) def test_get_many_decimal(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_decimal(id_=model.id, decimal_test=model.decimal_test) + result = queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -654,7 +596,7 @@ def test_get_many_decimal(self, queries_obj: queries.Queries, model: models.Test depends=["Sqlite3TestDataclassClasses::get_many_decimal"], ) def test_get_many_decimal_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_decimal(id_=model.id, decimal_test=model.decimal_test): + for result in queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test): assert result is not None assert isinstance(result, decimal.Decimal) @@ -665,7 +607,7 @@ def test_get_many_decimal_iter(self, queries_obj: queries.Queries, model: models depends=["Sqlite3TestDataclassClasses::get_many_decimal_iter"], ) def test_get_many_blob(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_blob(id_=model.id, blob_test=model.blob_test) + result = queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -674,26 +616,22 @@ def test_get_many_blob(self, queries_obj: queries.Queries, model: models.TestSql assert results[0] == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::get_many_blob_iter", depends=["Sqlite3TestDataclassClasses::get_many_blob"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::get_many_blob_iter", depends=["Sqlite3TestDataclassClasses::get_many_blob"]) def test_get_many_blob_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_blob(id_=model.id, blob_test=model.blob_test): + for result in queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test): assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::insert_result", depends=["Sqlite3TestDataclassClasses::get_many_blob_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::insert_result", depends=["Sqlite3TestDataclassClasses::get_many_blob_iter"]) def test_insert_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = queries_obj.insert_result_one_sqlite_type( - id_=model.id + 1, + id_=model.id_ + 1, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -725,38 +663,32 @@ def test_insert_result( ) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::update_result", depends=["Sqlite3TestDataclassClasses::insert_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::update_result", depends=["Sqlite3TestDataclassClasses::insert_result"]) def test_update_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.update_result_one_sqlite_type(id_=model.id + 1) + result = queries_obj.update_result_one_sqlite_type(id_=model.id_ + 1) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::delete_result", depends=["Sqlite3TestDataclassClasses::update_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::delete_result", depends=["Sqlite3TestDataclassClasses::update_result"]) def test_delete_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.delete_result_one_sqlite_type(id_=model.id + 1) + result = queries_obj.delete_result_one_sqlite_type(id_=model.id_ + 1) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::insert_rows", depends=["Sqlite3TestDataclassClasses::delete_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::insert_rows", depends=["Sqlite3TestDataclassClasses::delete_result"]) def test_insert_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = queries_obj.insert_rows_one_sqlite_type( - id_=model.id + 2, + id_=model.id_ + 2, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -789,33 +721,27 @@ def test_insert_rows( assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::update_rows", depends=["Sqlite3TestDataclassClasses::insert_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::update_rows", depends=["Sqlite3TestDataclassClasses::insert_rows"]) def test_update_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.update_rows_one_sqlite_type(id_=model.id + 2) + result = queries_obj.update_rows_one_sqlite_type(id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::delete_rows", depends=["Sqlite3TestDataclassClasses::update_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::delete_rows", depends=["Sqlite3TestDataclassClasses::update_rows"]) def test_delete_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.delete_rows_one_sqlite_type(id_=model.id + 2) + result = queries_obj.delete_rows_one_sqlite_type(id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::create_table_rows", depends=["Sqlite3TestDataclassClasses::delete_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::create_table_rows", depends=["Sqlite3TestDataclassClasses::delete_rows"]) def test_create_table_rows( self, queries_obj: queries.Queries, @@ -827,16 +753,14 @@ def test_create_table_rows( sqlite3_conn.commit() assert result == -1 - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::insert_last_id", depends=["Sqlite3TestDataclassClasses::create_table_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::insert_last_id", depends=["Sqlite3TestDataclassClasses::create_table_rows"]) def test_insert_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = queries_obj.insert_last_id_one_sqlite_type( - id_=model.id + 3, + id_=model.id_ + 3, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -867,59 +791,51 @@ def test_insert_last_id( json_test=model.json_test, ) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::update_last_id", depends=["Sqlite3TestDataclassClasses::insert_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::update_last_id", depends=["Sqlite3TestDataclassClasses::insert_last_id"]) def test_update_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.update_last_id_one_sqlite_type(id_=model.id + 3) + result = queries_obj.update_last_id_one_sqlite_type(id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::delete_last_id", depends=["Sqlite3TestDataclassClasses::update_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::delete_last_id", depends=["Sqlite3TestDataclassClasses::update_last_id"]) def test_delete_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.delete_last_id_one_sqlite_type(id_=model.id + 3) + result = queries_obj.delete_last_id_one_sqlite_type(id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestDataclassClasses::delete_sqlite_type", depends=["Sqlite3TestDataclassClasses::delete_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassClasses::delete_sqlite_type", depends=["Sqlite3TestDataclassClasses::delete_last_id"]) def test_delete_sqlite_type(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - queries_obj.delete_one_sqlite_type(id_=model.id) + queries_obj.delete_one_sqlite_type(id_=model.id_) @pytest.mark.dependency( name="Sqlite3TestDataclassClasses::delete_inner_sqlite_type", depends=["Sqlite3TestDataclassClasses::delete_sqlite_type"], ) - def test_delete_inner_sqlite_type( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: + def test_delete_inner_sqlite_type(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: queries_obj.delete_one_test_inner_sqlite_type(table_id=inner_model.table_id) @pytest.mark.dependency( name="Sqlite3TestDataclassClasses::insert_type_override", ) def test_insert_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: - queries_obj.insert_type_override(id_=override_model.id, text_test=override_model.text_test) + queries_obj.insert_type_override(id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.dependency( name="Sqlite3TestDataclassClasses::get_one_type_override", depends=["Sqlite3TestDataclassClasses::insert_type_override"], ) def test_get_one_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: - result = queries_obj.get_one_type_override(id_=override_model.id) + result = queries_obj.get_one_type_override(id_=override_model.id_) assert result is not None assert result == override_model @@ -927,20 +843,16 @@ def test_get_one_type_override(self, queries_obj: queries.Queries, override_mode name="Sqlite3TestDataclassClasses::get_one_type_override_none", depends=["Sqlite3TestDataclassClasses::get_one_type_override"], ) - def test_get_one_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_one_type_override(id_=override_model.id - 1) + def test_get_one_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.dependency( name="Sqlite3TestDataclassClasses::get_many_type_override", depends=["Sqlite3TestDataclassClasses::get_one_type_override_none"], ) - def test_get_many_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_many_type_override(id_=override_model.id) + def test_get_many_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_many_type_override(id_=override_model.id_) assert result is not None assert isinstance(result, queries.QueryResults) results = list(result) @@ -952,10 +864,8 @@ def test_get_many_type_override( name="Sqlite3TestDataclassClasses::get_one_text_type_override", depends=["Sqlite3TestDataclassClasses::get_many_type_override"], ) - def test_get_one_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_one_text_type_override(id_=override_model.id) + def test_get_one_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_text_type_override(id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -963,20 +873,16 @@ def test_get_one_text_type_override( name="Sqlite3TestDataclassClasses::get_one_text_type_override_none", depends=["Sqlite3TestDataclassClasses::get_one_text_type_override"], ) - def test_get_one_text_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_one_text_type_override(id_=override_model.id - 1) + def test_get_one_text_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_text_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.dependency( name="Sqlite3TestDataclassClasses::get_many_text_type_override", depends=["Sqlite3TestDataclassClasses::get_one_text_type_override_none"], ) - def test_get_many_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_many_text_type_override(id_=override_model.id) + def test_get_many_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_many_text_type_override(id_=override_model.id_) assert result is not None assert isinstance(result, queries.QueryResults) results = list(result) @@ -989,4 +895,4 @@ def test_get_many_text_type_override( depends=["Sqlite3TestDataclassClasses::get_many_text_type_override"], ) def test_delete_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: - queries_obj.delete_type_override(id_=override_model.id) + queries_obj.delete_type_override(id_=override_model.id_) diff --git a/test/driver_sqlite3/dataclass/test_sqlite3_dataclass_functions.py b/test/driver_sqlite3/dataclass/test_sqlite3_dataclass_functions.py index 2f4cbfcd..b6fb2439 100644 --- a/test/driver_sqlite3/dataclass/test_sqlite3_dataclass_functions.py +++ b/test/driver_sqlite3/dataclass/test_sqlite3_dataclass_functions.py @@ -31,17 +31,26 @@ from test.driver_sqlite3.dataclass.functions import models from test.driver_sqlite3.dataclass.functions import queries +from test.driver_sqlite3.dataclass.functions import queries_case +from test.driver_sqlite3.dataclass.functions import queries_override_adapter +from test.driver_sqlite3.dataclass.functions import queries_override_converter + +OVERRIDE_PRICE = 12.5 +OVERRIDE_HAPPENED_AT = datetime.datetime(2026, 7, 19, 12, 30) +CASE_DT = datetime.datetime(2026, 7, 19, 8, 15) +CASE_DEC = decimal.Decimal("12.34") +RESERVED_ARG_ID = 525252 class TestSqlite3DataclassFunctions: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestSqliteType: return models.TestSqliteType( - id=random.randint(1, 10000000), + id_=random.randint(1, 10000000), int_test=42, bigint_test=9_007_199_254_740_991, smallint_test=32_767, @@ -75,7 +84,7 @@ def model(self) -> models.TestSqliteType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: return models.TestInnerSqliteType( - table_id=model.id, + table_id=model.id_, int_test=None, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -114,7 +123,7 @@ def test_insert( ) -> None: queries.insert_one_sqlite_type( conn=sqlite3_conn, - id_=model.id, + id_=model.id_, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -145,9 +154,7 @@ def test_insert( json_test=model.json_test, ) - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::inner_insert", depends=["Sqlite3TestDataclassFunctions::insert"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::inner_insert", depends=["Sqlite3TestDataclassFunctions::insert"]) def test_inner_insert( self, sqlite3_conn: sqlite3.Connection, @@ -186,15 +193,13 @@ def test_inner_insert( json_test=inner_model.json_test, ) - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_one", depends=["Sqlite3TestDataclassFunctions::inner_insert"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_one", depends=["Sqlite3TestDataclassFunctions::inner_insert"]) def test_get_one( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_sqlite_type(conn=sqlite3_conn, id_=model.id) + result = queries.get_one_sqlite_type(conn=sqlite3_conn, id_=model.id_) assert result is not None @@ -202,9 +207,7 @@ def test_get_one( assert result == model - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_one_none", depends=["Sqlite3TestDataclassFunctions::get_one"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_one_none", depends=["Sqlite3TestDataclassFunctions::get_one"]) def test_get_one_none( self, sqlite3_conn: sqlite3.Connection, @@ -213,9 +216,7 @@ def test_get_one_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_one_inner", depends=["Sqlite3TestDataclassFunctions::get_one_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_one_inner", depends=["Sqlite3TestDataclassFunctions::get_one_none"]) def test_get_one_inner( self, sqlite3_conn: sqlite3.Connection, @@ -240,24 +241,20 @@ def test_get_one_inner_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_date", depends=["Sqlite3TestDataclassFunctions::get_one_inner_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_date", depends=["Sqlite3TestDataclassFunctions::get_one_inner_none"]) def test_get_date( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_date(conn=sqlite3_conn, id_=model.id, date_test=model.date_test) + result = queries.get_one_date(conn=sqlite3_conn, id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, datetime.date) assert result == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_date_none", depends=["Sqlite3TestDataclassFunctions::get_date"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_date_none", depends=["Sqlite3TestDataclassFunctions::get_date"]) def test_get_date_none( self, sqlite3_conn: sqlite3.Connection, @@ -266,24 +263,20 @@ def test_get_date_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_datetime", depends=["Sqlite3TestDataclassFunctions::get_date_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_datetime", depends=["Sqlite3TestDataclassFunctions::get_date_none"]) def test_get_datetime( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_datetime(conn=sqlite3_conn, id_=model.id, datetime_test=model.datetime_test) + result = queries.get_one_datetime(conn=sqlite3_conn, id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.datetime_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_datetime_none", depends=["Sqlite3TestDataclassFunctions::get_datetime"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_datetime_none", depends=["Sqlite3TestDataclassFunctions::get_datetime"]) def test_get_datetime_none( self, sqlite3_conn: sqlite3.Connection, @@ -301,7 +294,7 @@ def test_get_timestamp( sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_timestamp(conn=sqlite3_conn, id_=model.id, timestamp_test=model.timestamp_test) + result = queries.get_one_timestamp(conn=sqlite3_conn, id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None @@ -320,24 +313,20 @@ def test_get_timestamp_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_bool", depends=["Sqlite3TestDataclassFunctions::get_timestamp_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_bool", depends=["Sqlite3TestDataclassFunctions::get_timestamp_none"]) def test_get_bool( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_bool(conn=sqlite3_conn, id_=model.id, bool_test=model.bool_test) + result = queries.get_one_bool(conn=sqlite3_conn, id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, bool) assert result == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_bool_none", depends=["Sqlite3TestDataclassFunctions::get_bool"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_bool_none", depends=["Sqlite3TestDataclassFunctions::get_bool"]) def test_get_bool_none( self, sqlite3_conn: sqlite3.Connection, @@ -346,24 +335,20 @@ def test_get_bool_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_boolean", depends=["Sqlite3TestDataclassFunctions::get_bool_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_boolean", depends=["Sqlite3TestDataclassFunctions::get_bool_none"]) def test_get_boolean( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_boolean(conn=sqlite3_conn, id_=model.id, boolean_test=model.boolean_test) + result = queries.get_one_boolean(conn=sqlite3_conn, id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, bool) assert result == model.boolean_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_boolean_none", depends=["Sqlite3TestDataclassFunctions::get_boolean"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_boolean_none", depends=["Sqlite3TestDataclassFunctions::get_boolean"]) def test_get_boolean_none( self, sqlite3_conn: sqlite3.Connection, @@ -372,24 +357,20 @@ def test_get_boolean_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_decimal", depends=["Sqlite3TestDataclassFunctions::get_boolean_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_decimal", depends=["Sqlite3TestDataclassFunctions::get_boolean_none"]) def test_get_decimal( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_decimal(conn=sqlite3_conn, id_=model.id, decimal_test=model.decimal_test) + result = queries.get_one_decimal(conn=sqlite3_conn, id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, decimal.Decimal) assert result == model.decimal_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_decimal_none", depends=["Sqlite3TestDataclassFunctions::get_decimal"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_decimal_none", depends=["Sqlite3TestDataclassFunctions::get_decimal"]) def test_get_decimal_none( self, sqlite3_conn: sqlite3.Connection, @@ -398,24 +379,20 @@ def test_get_decimal_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_blob", depends=["Sqlite3TestDataclassFunctions::get_decimal_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_blob", depends=["Sqlite3TestDataclassFunctions::get_decimal_none"]) def test_get_blob( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_blob(conn=sqlite3_conn, id_=model.id, blob_test=model.blob_test) + result = queries.get_one_blob(conn=sqlite3_conn, id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_blob_none", depends=["Sqlite3TestDataclassFunctions::get_blob"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_blob_none", depends=["Sqlite3TestDataclassFunctions::get_blob"]) def test_get_blob_none( self, sqlite3_conn: sqlite3.Connection, @@ -424,11 +401,9 @@ def test_get_blob_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_many", depends=["Sqlite3TestDataclassFunctions::get_blob_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_many", depends=["Sqlite3TestDataclassFunctions::get_blob_none"]) def test_get_many(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id) + result = queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id_) assert result is not None assert isinstance(result, queries.QueryResults) @@ -441,19 +416,15 @@ def test_get_many(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqli assert results[0] == model - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_many_iter", depends=["Sqlite3TestDataclassFunctions::get_many"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_many_iter", depends=["Sqlite3TestDataclassFunctions::get_many"]) def test_get_many_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id): + for result in queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id_): assert result is not None assert isinstance(result, models.TestSqliteType) assert result == model - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::get_many_inner", depends=["Sqlite3TestDataclassFunctions::get_many_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::get_many_inner", depends=["Sqlite3TestDataclassFunctions::get_many_iter"]) def test_get_many_inner(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: result = queries.get_many_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id) @@ -468,9 +439,7 @@ def test_get_many_inner(self, sqlite3_conn: sqlite3.Connection, inner_model: mod name="Sqlite3TestDataclassFunctions::get_many_inner_iter", depends=["Sqlite3TestDataclassFunctions::get_many_inner"], ) - def test_get_many_inner_iter( - self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + def test_get_many_inner_iter(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: for result in queries.get_many_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -482,12 +451,8 @@ def test_get_many_inner_iter( name="Sqlite3TestDataclassFunctions::get_many_nullable_inner", depends=["Sqlite3TestDataclassFunctions::get_many_inner_iter"], ) - async def test_get_many_nullable_inner( - self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType - ) -> None: - result = queries.get_many_nullable_inner_sqlite_type( - conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test - ) + async def test_get_many_nullable_inner(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: + result = queries.get_many_nullable_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -501,12 +466,8 @@ async def test_get_many_nullable_inner( name="Sqlite3TestDataclassFunctions::get_many_nullable_inner_iter", depends=["Sqlite3TestDataclassFunctions::get_many_nullable_inner"], ) - async def test_get_many_nullable_inner_iter( - self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType - ) -> None: - for result in queries.get_many_nullable_inner_sqlite_type( - conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test - ): + async def test_get_many_nullable_inner_iter(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: + for result in queries.get_many_nullable_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -517,7 +478,7 @@ async def test_get_many_nullable_inner_iter( depends=["Sqlite3TestDataclassFunctions::get_many_nullable_inner_iter"], ) def test_get_many_date(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_date(conn=sqlite3_conn, id_=model.id, date_test=model.date_test) + result = queries.get_many_date(conn=sqlite3_conn, id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -531,7 +492,7 @@ def test_get_many_date(self, sqlite3_conn: sqlite3.Connection, model: models.Tes depends=["Sqlite3TestDataclassFunctions::get_many_date"], ) def test_get_many_date_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_date(conn=sqlite3_conn, id_=model.id, date_test=model.date_test): + for result in queries.get_many_date(conn=sqlite3_conn, id_=model.id_, date_test=model.date_test): assert result is not None assert isinstance(result, datetime.date) @@ -542,7 +503,7 @@ def test_get_many_date_iter(self, sqlite3_conn: sqlite3.Connection, model: model depends=["Sqlite3TestDataclassFunctions::get_many_date_iter"], ) def test_get_many_datetime(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_datetime(conn=sqlite3_conn, id_=model.id, datetime_test=model.datetime_test) + result = queries.get_many_datetime(conn=sqlite3_conn, id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -556,7 +517,7 @@ def test_get_many_datetime(self, sqlite3_conn: sqlite3.Connection, model: models depends=["Sqlite3TestDataclassFunctions::get_many_datetime"], ) def test_get_many_datetime_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_datetime(conn=sqlite3_conn, id_=model.id, datetime_test=model.datetime_test): + for result in queries.get_many_datetime(conn=sqlite3_conn, id_=model.id_, datetime_test=model.datetime_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -567,7 +528,7 @@ def test_get_many_datetime_iter(self, sqlite3_conn: sqlite3.Connection, model: m depends=["Sqlite3TestDataclassFunctions::get_many_datetime_iter"], ) def test_get_many_timestamp(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id, timestamp_test=model.timestamp_test) + result = queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -581,7 +542,7 @@ def test_get_many_timestamp(self, sqlite3_conn: sqlite3.Connection, model: model depends=["Sqlite3TestDataclassFunctions::get_many_timestamp"], ) def test_get_many_timestamp_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id, timestamp_test=model.timestamp_test): + for result in queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id_, timestamp_test=model.timestamp_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -592,7 +553,7 @@ def test_get_many_timestamp_iter(self, sqlite3_conn: sqlite3.Connection, model: depends=["Sqlite3TestDataclassFunctions::get_many_timestamp_iter"], ) def test_get_many_bool(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_bool(conn=sqlite3_conn, id_=model.id, bool_test=model.bool_test) + result = queries.get_many_bool(conn=sqlite3_conn, id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -606,7 +567,7 @@ def test_get_many_bool(self, sqlite3_conn: sqlite3.Connection, model: models.Tes depends=["Sqlite3TestDataclassFunctions::get_many_bool"], ) def test_get_many_bool_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_bool(conn=sqlite3_conn, id_=model.id, bool_test=model.bool_test): + for result in queries.get_many_bool(conn=sqlite3_conn, id_=model.id_, bool_test=model.bool_test): assert result is not None assert isinstance(result, bool) @@ -617,7 +578,7 @@ def test_get_many_bool_iter(self, sqlite3_conn: sqlite3.Connection, model: model depends=["Sqlite3TestDataclassFunctions::get_many_bool_iter"], ) def test_get_many_boolean(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_boolean(conn=sqlite3_conn, id_=model.id, boolean_test=model.boolean_test) + result = queries.get_many_boolean(conn=sqlite3_conn, id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -631,7 +592,7 @@ def test_get_many_boolean(self, sqlite3_conn: sqlite3.Connection, model: models. depends=["Sqlite3TestDataclassFunctions::get_many_boolean"], ) def test_get_many_boolean_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_boolean(conn=sqlite3_conn, id_=model.id, boolean_test=model.boolean_test): + for result in queries.get_many_boolean(conn=sqlite3_conn, id_=model.id_, boolean_test=model.boolean_test): assert result is not None assert isinstance(result, bool) @@ -642,7 +603,7 @@ def test_get_many_boolean_iter(self, sqlite3_conn: sqlite3.Connection, model: mo depends=["Sqlite3TestDataclassFunctions::get_many_boolean_iter"], ) def test_get_many_decimal(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_decimal(conn=sqlite3_conn, id_=model.id, decimal_test=model.decimal_test) + result = queries.get_many_decimal(conn=sqlite3_conn, id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -656,7 +617,7 @@ def test_get_many_decimal(self, sqlite3_conn: sqlite3.Connection, model: models. depends=["Sqlite3TestDataclassFunctions::get_many_decimal"], ) def test_get_many_decimal_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_decimal(conn=sqlite3_conn, id_=model.id, decimal_test=model.decimal_test): + for result in queries.get_many_decimal(conn=sqlite3_conn, id_=model.id_, decimal_test=model.decimal_test): assert result is not None assert isinstance(result, decimal.Decimal) @@ -667,7 +628,7 @@ def test_get_many_decimal_iter(self, sqlite3_conn: sqlite3.Connection, model: mo depends=["Sqlite3TestDataclassFunctions::get_many_decimal_iter"], ) def test_get_many_blob(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_blob(conn=sqlite3_conn, id_=model.id, blob_test=model.blob_test) + result = queries.get_many_blob(conn=sqlite3_conn, id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -681,7 +642,7 @@ def test_get_many_blob(self, sqlite3_conn: sqlite3.Connection, model: models.Tes depends=["Sqlite3TestDataclassFunctions::get_many_blob"], ) def test_get_many_blob_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_blob(conn=sqlite3_conn, id_=model.id, blob_test=model.blob_test): + for result in queries.get_many_blob(conn=sqlite3_conn, id_=model.id_, blob_test=model.blob_test): assert result is not None assert isinstance(result, memoryview) @@ -698,7 +659,7 @@ def test_insert_result( ) -> None: result = queries.insert_result_one_sqlite_type( conn=sqlite3_conn, - id_=model.id + 1, + id_=model.id_ + 1, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -730,31 +691,25 @@ def test_insert_result( ) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::update_result", depends=["Sqlite3TestDataclassFunctions::insert_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::update_result", depends=["Sqlite3TestDataclassFunctions::insert_result"]) def test_update_result( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.update_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 1) + result = queries.update_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 1) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::delete_result", depends=["Sqlite3TestDataclassFunctions::update_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::delete_result", depends=["Sqlite3TestDataclassFunctions::update_result"]) def test_delete_result( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.delete_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 1) + result = queries.delete_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 1) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::insert_rows", depends=["Sqlite3TestDataclassFunctions::delete_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::insert_rows", depends=["Sqlite3TestDataclassFunctions::delete_result"]) def test_insert_rows( self, sqlite3_conn: sqlite3.Connection, @@ -762,7 +717,7 @@ def test_insert_rows( ) -> None: result = queries.insert_rows_one_sqlite_type( conn=sqlite3_conn, - id_=model.id + 2, + id_=model.id_ + 2, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -795,33 +750,27 @@ def test_insert_rows( assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::update_rows", depends=["Sqlite3TestDataclassFunctions::insert_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::update_rows", depends=["Sqlite3TestDataclassFunctions::insert_rows"]) def test_update_rows( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.update_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 2) + result = queries.update_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::delete_rows", depends=["Sqlite3TestDataclassFunctions::update_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::delete_rows", depends=["Sqlite3TestDataclassFunctions::update_rows"]) def test_delete_rows( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.delete_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 2) + result = queries.delete_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::create_table_rows", depends=["Sqlite3TestDataclassFunctions::delete_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::create_table_rows", depends=["Sqlite3TestDataclassFunctions::delete_rows"]) def test_create_table_rows( self, sqlite3_conn: sqlite3.Connection, @@ -843,7 +792,7 @@ def test_insert_last_id( ) -> None: result = queries.insert_last_id_one_sqlite_type( conn=sqlite3_conn, - id_=model.id + 3, + id_=model.id_ + 3, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -874,64 +823,54 @@ def test_insert_last_id( json_test=model.json_test, ) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::update_last_id", depends=["Sqlite3TestDataclassFunctions::insert_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::update_last_id", depends=["Sqlite3TestDataclassFunctions::insert_last_id"]) def test_update_last_id( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.update_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 3) + result = queries.update_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestDataclassFunctions::delete_last_id", depends=["Sqlite3TestDataclassFunctions::update_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::delete_last_id", depends=["Sqlite3TestDataclassFunctions::update_last_id"]) def test_delete_last_id( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.delete_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 3) + result = queries.delete_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 @pytest.mark.dependency( name="Sqlite3TestDataclassFunctions::delete_sqlite_type", depends=["Sqlite3TestDataclassFunctions::delete_last_id"], ) def test_delete_sqlite_type(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - queries.delete_one_sqlite_type(conn=sqlite3_conn, id_=model.id) + queries.delete_one_sqlite_type(conn=sqlite3_conn, id_=model.id_) @pytest.mark.dependency( name="Sqlite3TestDataclassFunctions::delete_inner_sqlite_type", depends=["Sqlite3TestDataclassFunctions::delete_sqlite_type"], ) - def test_delete_inner_sqlite_type( - self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + def test_delete_inner_sqlite_type(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: queries.delete_one_test_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id) @pytest.mark.dependency( name="Sqlite3TestDataclassFunctions::insert_type_override", ) - def test_insert_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - queries.insert_type_override(conn=sqlite3_conn, id_=override_model.id, text_test=override_model.text_test) + def test_insert_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + queries.insert_type_override(conn=sqlite3_conn, id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.dependency( name="Sqlite3TestDataclassFunctions::get_one_type_override", depends=["Sqlite3TestDataclassFunctions::insert_type_override"], ) - def test_get_one_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_get_one_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id_) assert result is not None assert result == override_model @@ -939,20 +878,16 @@ def test_get_one_type_override( name="Sqlite3TestDataclassFunctions::get_one_type_override_none", depends=["Sqlite3TestDataclassFunctions::get_one_type_override"], ) - def test_get_one_type_override_none( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id - 1) + def test_get_one_type_override_none(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.dependency( name="Sqlite3TestDataclassFunctions::get_many_type_override", depends=["Sqlite3TestDataclassFunctions::get_one_type_override_none"], ) - def test_get_many_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_many_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_get_many_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_many_type_override(conn=sqlite3_conn, id_=override_model.id_) assert result is not None assert isinstance(result, queries.QueryResults) results = list(result) @@ -969,10 +904,8 @@ def test_get_many_type_override( name="Sqlite3TestDataclassFunctions::get_one_text_type_override", depends=["Sqlite3TestDataclassFunctions::get_many_type_override"], ) - def test_get_one_text_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_get_one_text_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -980,20 +913,16 @@ def test_get_one_text_type_override( name="Sqlite3TestDataclassFunctions::get_one_text_type_override_none", depends=["Sqlite3TestDataclassFunctions::get_one_text_type_override"], ) - def test_get_one_text_type_override_none( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id - 1) + def test_get_one_text_type_override_none(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.dependency( name="Sqlite3TestDataclassFunctions::get_many_text_type_override", depends=["Sqlite3TestDataclassFunctions::get_one_text_type_override_none"], ) - def test_get_many_text_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_many_text_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_get_many_text_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_many_text_type_override(conn=sqlite3_conn, id_=override_model.id_) assert result is not None assert isinstance(result, queries.QueryResults) results = list(result) @@ -1010,7 +939,60 @@ def test_get_many_text_type_override( name="Sqlite3TestDataclassFunctions::delete_type_override", depends=["Sqlite3TestDataclassFunctions::get_many_text_type_override"], ) - def test_delete_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - queries.delete_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_delete_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + queries.delete_type_override(conn=sqlite3_conn, id_=override_model.id_) + + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::insert_override_conversion") + def test_insert_override_conversion(self, sqlite3_conn: sqlite3.Connection) -> None: + # The overridden price parameter is a plain float; the generated code + # converts it back to decimal.Decimal, which the registered adapter + # then serializes. + queries_override_adapter.insert_override_conversion( + conn=sqlite3_conn, + id_=434343, + price=OVERRIDE_PRICE, + happened_at=OVERRIDE_HAPPENED_AT, + ) + + @pytest.mark.dependency( + name="Sqlite3TestDataclassFunctions::get_override_price", + depends=["Sqlite3TestDataclassFunctions::insert_override_conversion"], + ) + def test_get_override_price(self, sqlite3_conn: sqlite3.Connection) -> None: + price = queries_override_adapter.get_override_price(conn=sqlite3_conn, id_=434343) + assert price is not None + assert isinstance(price, float) + assert price == OVERRIDE_PRICE + + @pytest.mark.dependency(depends=["Sqlite3TestDataclassFunctions::get_override_price"]) + def test_get_override_happened_at(self, sqlite3_conn: sqlite3.Connection) -> None: + happened_at = queries_override_converter.get_override_happened_at(conn=sqlite3_conn, id_=434343) + assert happened_at is not None + assert isinstance(happened_at, datetime.datetime) + assert happened_at == OVERRIDE_HAPPENED_AT + + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::insert_case_row") + def test_insert_case_row(self, sqlite3_conn: sqlite3.Connection) -> None: + # The schema declares the columns as DATETIME and decimal(10,2); both + # must round-trip through the registered adapters and converters. + queries_case.insert_case_row(conn=sqlite3_conn, id_=515151, upper_dt=CASE_DT, prec_dec=CASE_DEC) + + @pytest.mark.dependency(depends=["Sqlite3TestDataclassFunctions::insert_case_row"]) + def test_get_case_row(self, sqlite3_conn: sqlite3.Connection) -> None: + row = queries_case.get_case_row(conn=sqlite3_conn, id_=515151) + assert row is not None + assert isinstance(row.upper_dt, datetime.datetime) + assert row.upper_dt == CASE_DT + assert isinstance(row.prec_dec, decimal.Decimal) + assert row.prec_dec == CASE_DEC + + @pytest.mark.dependency(name="Sqlite3TestDataclassFunctions::insert_reserved_arg") + def test_insert_reserved_arg(self, sqlite3_conn: sqlite3.Connection) -> None: + # The column is literally named "conn"; the generated parameter must + # be deduplicated against the implicit connection argument. + queries_case.insert_reserved_arg(conn=sqlite3_conn, id_=RESERVED_ARG_ID, conn_2="reserved-arg-value") + + @pytest.mark.dependency(depends=["Sqlite3TestDataclassFunctions::insert_reserved_arg"]) + def test_get_reserved_arg(self, sqlite3_conn: sqlite3.Connection) -> None: + found_id = queries_case.get_reserved_arg(conn=sqlite3_conn, conn_2="reserved-arg-value") + assert found_id == RESERVED_ARG_ID diff --git a/test/driver_sqlite3/msgspec/classes/__init__.py b/test/driver_sqlite3/msgspec/classes/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_sqlite3/msgspec/classes/__init__.py +++ b/test/driver_sqlite3/msgspec/classes/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_sqlite3/msgspec/classes/models.py b/test/driver_sqlite3/msgspec/classes/models.py index 0819a9c8..69e8f334 100644 --- a/test/driver_sqlite3/msgspec/classes/models.py +++ b/test/driver_sqlite3/msgspec/classes/models.py @@ -1,8 +1,9 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -91,7 +92,7 @@ class TestSqliteType(msgspec.Struct): """Model representing TestSqliteType. Attributes: - id -- int + id_ -- int int_test -- int bigint_test -- int smallint_test -- int @@ -122,7 +123,7 @@ class TestSqliteType(msgspec.Struct): json_test -- str """ - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -157,9 +158,9 @@ class TestTypeOverride(msgspec.Struct): """Model representing TestTypeOverride. Attributes: - id -- int + id_ -- int text_test -- UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_sqlite3/msgspec/classes/queries.py b/test/driver_sqlite3/msgspec/classes/queries.py index c1099fec..5b8cca6c 100644 --- a/test/driver_sqlite3/msgspec/classes/queries.py +++ b/test/driver_sqlite3/msgspec/classes/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -20,7 +22,7 @@ if typing.TYPE_CHECKING: import collections.abc - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None from test.driver_sqlite3.msgspec.classes import models @@ -80,71 +82,74 @@ def _convert_memoryview(val: bytes) -> memoryview: sqlite3.register_converter("blob", _convert_memoryview) -CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows -CREATE TABLE test_create_rows_table -( - id int PRIMARY KEY NOT NULL, - test int NOT NULL -) -""" - -DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec -DELETE FROM test_inner_sqlite_types -WHERE test_inner_sqlite_types.table_id = ? +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ -DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? """ -DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec -DELETE -FROM test_type_override -WHERE test_type_override.id = ? +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ -GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many -SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many @@ -155,67 +160,46 @@ def _convert_memoryview(val: bytes) -> memoryview: SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? """ -GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? -""" - -GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? -""" - -GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? -""" - -GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? -""" - -GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one -SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? -""" - -GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one -SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = ? +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? """ -INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -230,37 +214,19 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec -INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? """ -INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec -INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -275,7 +241,27 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -290,35 +276,48 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec INSERT INTO test_type_override ( id, text_test ) VALUES (? ,?) """ -UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? """ -UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? """ -UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? """ +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" -T = typing.TypeVar("T") +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db.""" __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") @@ -407,132 +406,389 @@ def conn(self) -> sqlite3.Connection: """ return self._conn - def create_rows_table(self) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + def insert_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - """ - return self._conn.execute(CREATE_ROWS_TABLE).rowcount - - def delete_last_id_one_sqlite_type(self, *, id_: int) -> int | None: - """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Arguments: id_ -- int. - - Returns: - int | None -- The id of the last affected row. Will be `None` if no rows are affected. + int_test -- int. + bigint_test -- int. + smallint_test -- int. + tinyint_test -- int. + int2_test -- int. + int8_test -- int. + bigserial_test -- int. + blob_test -- memoryview. + real_test -- float. + double_test -- float. + double_precision_test -- float. + float_test -- float. + numeric_test -- float. + decimal_test -- decimal.Decimal. + boolean_test -- bool. + bool_test -- bool. + date_test -- datetime.date. + datetime_test -- datetime.datetime. + timestamp_test -- datetime.datetime. + character_test -- str. + varchar_test -- str. + varyingcharacter_test -- str. + nchar_test -- str. + nativecharacter_test -- str. + nvarchar_test -- str. + text_test -- str. + clob_test -- str. + json_test -- str. """ - return self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, )).lastrowid + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + self._conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) - def delete_one_sqlite_type(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneSqliteType :exec`. + def insert_one_inner_sqlite_type( + self, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, + ) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Arguments: - id_ -- int. + table_id -- int. + int_test -- int | None. + bigint_test -- int | None. + smallint_test -- int | None. + tinyint_test -- int | None. + int2_test -- int | None. + int8_test -- int | None. + bigserial_test -- int | None. + blob_test -- memoryview | None. + real_test -- float | None. + double_test -- float | None. + double_precision_test -- float | None. + float_test -- float | None. + numeric_test -- float | None. + decimal_test -- decimal.Decimal | None. + boolean_test -- bool | None. + bool_test -- bool | None. + date_test -- datetime.date | None. + datetime_test -- datetime.datetime | None. + timestamp_test -- datetime.datetime | None. + character_test -- str | None. + varchar_test -- str | None. + varyingcharacter_test -- str | None. + nchar_test -- str | None. + nativecharacter_test -- str | None. + nvarchar_test -- str | None. + text_test -- str | None. + clob_test -- str | None. + json_test -- str | None. """ - self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, )) + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) - def delete_one_test_inner_sqlite_type(self, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + def get_one_sqlite_type(self, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. ```sql - DELETE FROM test_inner_sqlite_types - WHERE test_inner_sqlite_types.table_id = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Arguments: - table_id -- int. + id_ -- int. + + Returns: + models.TestSqliteType -- Result fetched from the db. Will be `None` if not found. """ - self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, )) + row = self._conn.execute(GET_ONE_SQLITE_TYPE, (id_,)).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) - def delete_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Arguments: - id_ -- int. + table_id -- int. Returns: - sqlite3.Cursor -- The result returned when executing the query. + models.TestInnerSqliteType -- Result fetched from the db. Will be `None` if not found. """ - return self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, )) + row = self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,)).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) - def delete_rows_one_sqlite_type(self, *, id_: int) -> int: - """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Arguments: id_ -- int. + date_test -- datetime.date. Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + datetime.date -- Result fetched from the db. Will be `None` if not found. """ - return self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, )).rowcount + row = self._conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() + if row is None: + return None + return row[0] - def delete_type_override(self, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. + def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Arguments: id_ -- int. + datetime_test -- datetime.datetime. + + Returns: + datetime.datetime -- Result fetched from the db. Will be `None` if not found. """ - self._conn.execute(DELETE_TYPE_OVERRIDE, (id_, )) + row = self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. + def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Arguments: id_ -- int. - blob_test -- memoryview. + timestamp_test -- datetime.datetime. Returns: - QueryResults[memoryview] -- Helper class that allows both iteration and normal fetching of data from the db. + datetime.datetime -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[memoryview](self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + row = self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBool :many`. + def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -543,12 +799,15 @@ def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: bool_test -- bool. Returns: - QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. + bool -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + row = self._conn.execute(GET_ONE_BOOL, (id_, bool_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. + def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -559,57 +818,99 @@ def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool boolean_test -- bool. Returns: - QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. + bool -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + row = self._conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: - """Fetch many from the db using the SQL query with `name: GetManyDate :many`. + def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Arguments: id_ -- int. - date_test -- datetime.date. + decimal_test -- decimal.Decimal. Returns: - QueryResults[datetime.date] -- Helper class that allows both iteration and normal fetching of data from the db. + decimal.Decimal -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.date](self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + row = self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. + def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Arguments: id_ -- int. - datetime_test -- datetime.datetime. + blob_test -- memoryview. Returns: - QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. + memoryview -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) + row = self._conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() + if row is None: + return None + return row[0] - def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: - """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. + def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Arguments: id_ -- int. - decimal_test -- decimal.Decimal. Returns: - QueryResults[decimal.Decimal] -- Helper class that allows both iteration and normal fetching of data from the db. + QueryResults[models.TestSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. """ - return QueryResults[decimal.Decimal](self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) def get_many_inner_sqlite_type(self, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. @@ -624,9 +925,41 @@ def get_many_inner_sqlite_type(self, *, table_id: int) -> QueryResults[models.Te Returns: QueryResults[models.TestInnerSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. @@ -642,43 +975,73 @@ def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | Returns: QueryResults[models.TestInnerSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) - def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. + def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Arguments: id_ -- int. + date_test -- datetime.date. Returns: - QueryResults[models.TestSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. + QueryResults[datetime.date] -- Helper class that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestSqliteType](self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + return QueryResults(self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) - def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Arguments: id_ -- int. + datetime_test -- datetime.datetime. Returns: - QueryResults[UserString] -- Helper class that allows both iteration and normal fetching of data from the db. + QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> UserString: - return UserString(row[0]) - return QueryResults[UserString](self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + return QueryResults(self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. @@ -694,46 +1057,10 @@ def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> Returns: QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. """ - return QueryResults[datetime.datetime](self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - - def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: - """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. - - ```sql - SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? - ``` - - Arguments: - id_ -- int. - - Returns: - QueryResults[models.TestTypeOverride] -- Helper class that allows both iteration and normal fetching of data from the db. - """ - def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - return QueryResults[models.TestTypeOverride](self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) - - def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. - - ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? - ``` - - Arguments: - id_ -- int. - blob_test -- memoryview. - - Returns: - memoryview -- Result fetched from the db. Will be `None` if not found. - """ - row = self._conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBool :one`. + def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -744,15 +1071,12 @@ def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: bool_test -- bool. Returns: - bool -- Result fetched from the db. Will be `None` if not found. + QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_BOOL, (id_, bool_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) - def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. + def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -763,53 +1087,12 @@ def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: boolean_test -- bool. Returns: - bool -- Result fetched from the db. Will be `None` if not found. - """ - row = self._conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test)).fetchone() - if row is None: - return None - return row[0] - - def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: - """Fetch one from the db using the SQL query with `name: GetOneDate :one`. - - ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? - ``` - - Arguments: - id_ -- int. - date_test -- datetime.date. - - Returns: - datetime.date -- Result fetched from the db. Will be `None` if not found. - """ - row = self._conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() - if row is None: - return None - return row[0] - - def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. - - ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? - ``` - - Arguments: - id_ -- int. - datetime_test -- datetime.datetime. - - Returns: - datetime.datetime -- Result fetched from the db. Will be `None` if not found. + QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) - def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: - """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. + def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. ```sql SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? @@ -820,106 +1103,87 @@ def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal decimal_test -- decimal.Decimal. Returns: - decimal.Decimal -- Result fetched from the db. Will be `None` if not found. - """ - row = self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() - if row is None: - return None - return row[0] - - def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? - ``` - - Arguments: - table_id -- int. - - Returns: - models.TestInnerSqliteType -- Result fetched from the db. Will be `None` if not found. - """ - row = self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id, )).fetchone() - if row is None: - return None - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - - def get_one_sqlite_type(self, *, id_: int) -> models.TestSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. - - ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? - ``` - - Arguments: - id_ -- int. - - Returns: - models.TestSqliteType -- Result fetched from the db. Will be `None` if not found. + QueryResults[decimal.Decimal] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_SQLITE_TYPE, (id_, )).fetchone() - if row is None: - return None - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) + return QueryResults(self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) - def get_one_text_type_override(self, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Arguments: id_ -- int. + blob_test -- memoryview. Returns: - UserString -- Result fetched from the db. Will be `None` if not found. + QueryResults[memoryview] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_, )).fetchone() - if row is None: - return None - return UserString(row[0]) + return QueryResults(self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) - def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. + def delete_one_sqlite_type(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? ``` Arguments: id_ -- int. - timestamp_test -- datetime.datetime. - - Returns: - datetime.datetime -- Result fetched from the db. Will be `None` if not found. """ - row = self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() - if row is None: - return None - return row[0] + self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) - def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + def delete_one_test_inner_sqlite_type(self, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = ? + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? ``` - - Arguments: - id_ -- int. - - Returns: - models.TestTypeOverride -- Result fetched from the db. Will be `None` if not found. + + Arguments: + table_id -- int. """ - row = self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_, )).fetchone() - if row is None: - return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) + self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) - def insert_last_id_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int | None: - """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. + def insert_result_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. ```sql INSERT INTO test_sqlite_types ( @@ -968,114 +1232,109 @@ def insert_last_id_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test json_test -- str. Returns: - int | None -- The id of the last affected row. Will be `None` if no rows are affected. + sqlite3.Cursor -- The result returned when executing the query. """ - return self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)).lastrowid + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) - def insert_one_inner_sqlite_type(self, *, table_id: int, int_test: int | None, bigint_test: int | None, smallint_test: int | None, tinyint_test: int | None, int2_test: int | None, int8_test: int | None, bigserial_test: int | None, blob_test: memoryview | None, real_test: float | None, double_test: float | None, double_precision_test: float | None, float_test: float | None, numeric_test: float | None, decimal_test: decimal.Decimal | None, boolean_test: bool | None, bool_test: bool | None, date_test: datetime.date | None, datetime_test: datetime.datetime | None, timestamp_test: datetime.datetime | None, character_test: str | None, varchar_test: str | None, varyingcharacter_test: str | None, nchar_test: str | None, nativecharacter_test: str | None, nvarchar_test: str | None, text_test: str | None, clob_test: str | None, json_test: str | None) -> None: - """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. + def update_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. ```sql - INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? ``` Arguments: - table_id -- int. - int_test -- int | None. - bigint_test -- int | None. - smallint_test -- int | None. - tinyint_test -- int | None. - int2_test -- int | None. - int8_test -- int | None. - bigserial_test -- int | None. - blob_test -- memoryview | None. - real_test -- float | None. - double_test -- float | None. - double_precision_test -- float | None. - float_test -- float | None. - numeric_test -- float | None. - decimal_test -- decimal.Decimal | None. - boolean_test -- bool | None. - bool_test -- bool | None. - date_test -- datetime.date | None. - datetime_test -- datetime.datetime | None. - timestamp_test -- datetime.datetime | None. - character_test -- str | None. - varchar_test -- str | None. - varyingcharacter_test -- str | None. - nchar_test -- str | None. - nativecharacter_test -- str | None. - nvarchar_test -- str | None. - text_test -- str | None. - clob_test -- str | None. - json_test -- str | None. + id_ -- int. + + Returns: + sqlite3.Cursor -- The result returned when executing the query. """ - self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, (table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + return self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) - def insert_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> None: - """Execute SQL query with `name: InsertOneSqliteType :exec`. + def delete_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. ```sql - INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? ``` Arguments: id_ -- int. - int_test -- int. - bigint_test -- int. - smallint_test -- int. - tinyint_test -- int. - int2_test -- int. - int8_test -- int. - bigserial_test -- int. - blob_test -- memoryview. - real_test -- float. - double_test -- float. - double_precision_test -- float. - float_test -- float. - numeric_test -- float. - decimal_test -- decimal.Decimal. - boolean_test -- bool. - bool_test -- bool. - date_test -- datetime.date. - datetime_test -- datetime.datetime. - timestamp_test -- datetime.datetime. - character_test -- str. - varchar_test -- str. - varyingcharacter_test -- str. - nchar_test -- str. - nativecharacter_test -- str. - nvarchar_test -- str. - text_test -- str. - clob_test -- str. - json_test -- str. + + Returns: + sqlite3.Cursor -- The result returned when executing the query. """ - self._conn.execute(INSERT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + return self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) - def insert_result_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. + def insert_rows_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. ```sql INSERT INTO test_sqlite_types ( @@ -1124,12 +1383,125 @@ def insert_result_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: json_test -- str. Returns: - sqlite3.Cursor -- The result returned when executing the query. + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - return self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args).rowcount - def insert_rows_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int: - """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. + def update_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + def delete_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + def create_rows_table(self) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Returns: + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return self._conn.execute(CREATE_ROWS_TABLE).rowcount + + def insert_last_id_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. ```sql INSERT INTO test_sqlite_types ( @@ -1178,9 +1550,74 @@ def insert_rows_one_sqlite_type(self, *, id_: int, int_test: int, bigint_test: i json_test -- str. Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + int -- The id of the last affected row. Will be `None` if no rows are affected. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args).lastrowid + + def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + int -- The id of the last affected row. Will be `None` if no rows are affected. + """ + return self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid + + def delete_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + int -- The id of the last affected row. Will be `None` if no rows are affected. """ - return self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)).rowcount + return self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: """Execute SQL query with `name: InsertTypeOverride :exec`. @@ -1195,55 +1632,92 @@ def insert_type_override(self, *, id_: int, text_test: UserString | None) -> Non id_ -- int. text_test -- UserString | None. """ - self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test))) + self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) - def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: - """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE id = ? ``` Arguments: id_ -- int. Returns: - int | None -- The id of the last affected row. Will be `None` if no rows are affected. + models.TestTypeOverride -- Result fetched from the db. Will be `None` if not found. """ - return self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_, )).lastrowid + row = self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) - def update_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? ``` Arguments: id_ -- int. Returns: - sqlite3.Cursor -- The result returned when executing the query. + QueryResults[models.TestTypeOverride] -- Helper class that allows both iteration and normal fetching of data from the db. """ - return self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_, )) - def update_rows_one_sqlite_type(self, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + def get_one_text_type_override(self, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + UserString -- Result fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? ``` Arguments: id_ -- int. Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + QueryResults[UserString | None] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + def delete_type_override(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Arguments: + id_ -- int. """ - return self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_, )).rowcount + self._conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_sqlite3/msgspec/classes/queries_case.py b/test/driver_sqlite3/msgspec/classes/queries_case.py new file mode 100644 index 00000000..a503e89e --- /dev/null +++ b/test/driver_sqlite3/msgspec/classes/queries_case.py @@ -0,0 +1,161 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_case.sql +"""Module containing queries from file queries_case.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "GetCaseRowRow", + "QueriesCase", +) + +import datetime +import decimal +import msgspec +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _convert_decimal(val: bytes) -> decimal.Decimal: + return decimal.Decimal(val.decode()) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + +sqlite3.register_converter("decimal", _convert_decimal) +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +class GetCaseRowRow(msgspec.Struct): + """Model representing GetCaseRowRow. + + Attributes: + upper_dt -- datetime.datetime + prec_dec -- decimal.Decimal + """ + + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + + +INSERT_CASE_ROW: typing.Final[str] = """-- name: InsertCaseRow :exec +INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) +""" + +GET_CASE_ROW: typing.Final[str] = """-- name: GetCaseRow :one +SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? +""" + +INSERT_RESERVED_ARG: typing.Final[str] = """-- name: InsertReservedArg :exec +INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) +""" + +GET_RESERVED_ARG: typing.Final[str] = """-- name: GetReservedArg :one +SELECT id FROM test_reserved_args WHERE conn = ? +""" + + +class QueriesCase: + """Queries from file queries_case.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection. + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute queries. + """ + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns: + sqlite3.Connection -- Connection object used to make queries. + """ + return self._conn + + def insert_case_row(self, *, id_: int, upper_dt: datetime.datetime, prec_dec: decimal.Decimal) -> None: + """Execute SQL query with `name: InsertCaseRow :exec`. + + ```sql + INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) + ``` + + Arguments: + id_ -- int. + upper_dt -- datetime.datetime. + prec_dec -- decimal.Decimal. + """ + self._conn.execute(INSERT_CASE_ROW, (id_, upper_dt, prec_dec)) + + def get_case_row(self, *, id_: int) -> GetCaseRowRow | None: + """Fetch one from the db using the SQL query with `name: GetCaseRow :one`. + + ```sql + SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + GetCaseRowRow -- Result fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_CASE_ROW, (id_,)).fetchone() + if row is None: + return None + return GetCaseRowRow(upper_dt=row[0], prec_dec=row[1]) + + def insert_reserved_arg(self, *, id_: int, conn: str) -> None: + """Execute SQL query with `name: InsertReservedArg :exec`. + + ```sql + INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) + ``` + + Arguments: + id_ -- int. + conn -- str. + """ + self._conn.execute(INSERT_RESERVED_ARG, (id_, conn)) + + def get_reserved_arg(self, *, conn: str) -> int | None: + """Fetch one from the db using the SQL query with `name: GetReservedArg :one`. + + ```sql + SELECT id FROM test_reserved_args WHERE conn = ? + ``` + + Arguments: + conn -- str. + + Returns: + int -- Result fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_RESERVED_ARG, (conn,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/msgspec/classes/queries_override_adapter.py b/test/driver_sqlite3/msgspec/classes/queries_override_adapter.py new file mode 100644 index 00000000..e2ca5543 --- /dev/null +++ b/test/driver_sqlite3/msgspec/classes/queries_override_adapter.py @@ -0,0 +1,94 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_adapter.sql +"""Module containing queries from file queries_override_adapter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("QueriesOverrideAdapter",) + +import datetime +import decimal +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + + +INSERT_OVERRIDE_CONVERSION: typing.Final[str] = """-- name: InsertOverrideConversion :exec +INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) +""" + +GET_OVERRIDE_PRICE: typing.Final[str] = """-- name: GetOverridePrice :one +SELECT price FROM test_override_conversion WHERE id = ? +""" + + +class QueriesOverrideAdapter: + """Queries from file queries_override_adapter.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection. + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute queries. + """ + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns: + sqlite3.Connection -- Connection object used to make queries. + """ + return self._conn + + def insert_override_conversion(self, *, id_: int, price: float, happened_at: datetime.datetime) -> None: + """Execute SQL query with `name: InsertOverrideConversion :exec`. + + ```sql + INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) + ``` + + Arguments: + id_ -- int. + price -- float. + happened_at -- datetime.datetime. + """ + self._conn.execute(INSERT_OVERRIDE_CONVERSION, (id_, decimal.Decimal(price), happened_at)) + + def get_override_price(self, *, id_: int) -> float | None: + """Fetch one from the db using the SQL query with `name: GetOverridePrice :one`. + + ```sql + SELECT price FROM test_override_conversion WHERE id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + float -- Result fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_OVERRIDE_PRICE, (id_,)).fetchone() + if row is None: + return None + return float(row[0]) diff --git a/test/driver_sqlite3/msgspec/classes/queries_override_converter.py b/test/driver_sqlite3/msgspec/classes/queries_override_converter.py new file mode 100644 index 00000000..a6d0dc7a --- /dev/null +++ b/test/driver_sqlite3/msgspec/classes/queries_override_converter.py @@ -0,0 +1,71 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_converter.sql +"""Module containing queries from file queries_override_converter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("QueriesOverrideConverter",) + +import datetime +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +GET_OVERRIDE_HAPPENED_AT: typing.Final[str] = """-- name: GetOverrideHappenedAt :one +SELECT happened_at FROM test_override_conversion WHERE id = ? +""" + + +class QueriesOverrideConverter: + """Queries from file queries_override_converter.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection. + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute queries. + """ + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns: + sqlite3.Connection -- Connection object used to make queries. + """ + return self._conn + + def get_override_happened_at(self, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOverrideHappenedAt :one`. + + ```sql + SELECT happened_at FROM test_override_conversion WHERE id = ? + ``` + + Arguments: + id_ -- int. + + Returns: + datetime.datetime -- Result fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_OVERRIDE_HAPPENED_AT, (id_,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/msgspec/functions/__init__.py b/test/driver_sqlite3/msgspec/functions/__init__.py index ea6558f2..5c9110dc 100644 --- a/test/driver_sqlite3/msgspec/functions/__init__.py +++ b/test/driver_sqlite3/msgspec/functions/__init__.py @@ -1,5 +1,5 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_sqlite3/msgspec/functions/models.py b/test/driver_sqlite3/msgspec/functions/models.py index 0819a9c8..69e8f334 100644 --- a/test/driver_sqlite3/msgspec/functions/models.py +++ b/test/driver_sqlite3/msgspec/functions/models.py @@ -1,8 +1,9 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 """Module containing models.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -91,7 +92,7 @@ class TestSqliteType(msgspec.Struct): """Model representing TestSqliteType. Attributes: - id -- int + id_ -- int int_test -- int bigint_test -- int smallint_test -- int @@ -122,7 +123,7 @@ class TestSqliteType(msgspec.Struct): json_test -- str """ - id: int + id_: int int_test: int bigint_test: int smallint_test: int @@ -157,9 +158,9 @@ class TestTypeOverride(msgspec.Struct): """Model representing TestTypeOverride. Attributes: - id -- int + id_ -- int text_test -- UserString | None """ - id: int + id_: int text_test: UserString | None diff --git a/test/driver_sqlite3/msgspec/functions/queries.py b/test/driver_sqlite3/msgspec/functions/queries.py index 4d846e13..10fe777f 100644 --- a/test/driver_sqlite3/msgspec/functions/queries.py +++ b/test/driver_sqlite3/msgspec/functions/queries.py @@ -1,8 +1,10 @@ # Code generated by sqlc. DO NOT EDIT. # versions: # sqlc v1.30.0 -# sqlc-gen-better-python v0.4.4 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql """Module containing queries from file queries.sql.""" + from __future__ import annotations __all__: collections.abc.Sequence[str] = ( @@ -58,7 +60,7 @@ if typing.TYPE_CHECKING: import collections.abc - QueryResultsArgsType: typing.TypeAlias = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | None + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None from test.driver_sqlite3.msgspec.functions import models @@ -118,71 +120,74 @@ def _convert_memoryview(val: bytes) -> memoryview: sqlite3.register_converter("blob", _convert_memoryview) -CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows -CREATE TABLE test_create_rows_table -( - id int PRIMARY KEY NOT NULL, - test int NOT NULL -) -""" - -DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) """ -DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec -DELETE FROM test_inner_sqlite_types -WHERE test_inner_sqlite_types.table_id = ? +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ -DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? """ -DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows -DELETE -FROM test_sqlite_types -WHERE test_sqlite_types.id = ? +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec -DELETE -FROM test_type_override -WHERE test_type_override.id = ? +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ -GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many -SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? """ GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many @@ -193,67 +198,46 @@ def _convert_memoryview(val: bytes) -> memoryview: SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? """ -GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? """ -GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? """ GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? """ -GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many -SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? -""" - -GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one -SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? -""" - -GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? """ -GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? """ -GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one -SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? -""" - -GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one -SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? -""" - -GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? """ -GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one -SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? -""" - -GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one -SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? -""" - -GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one -SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? """ -GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one -SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one -SELECT id, text_test FROM test_type_override WHERE id = ? +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? """ -INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -268,37 +252,19 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec -INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? """ -INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec -INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test -) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? """ -INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -313,7 +279,27 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ -INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid INSERT INTO test_sqlite_types ( id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, @@ -328,35 +314,48 @@ def _convert_memoryview(val: bytes) -> memoryview: ) """ +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec INSERT INTO test_type_override ( id, text_test ) VALUES (? ,?) """ -UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? """ -UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? """ -UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows -UPDATE test_sqlite_types -SET int_test = 187 -WHERE test_sqlite_types.id = ? +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? """ +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" -T = typing.TypeVar("T") +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" -class QueryResults(typing.Generic[T]): +class QueryResults[T]: """Helper class that allows both iteration and normal fetching of data from the db.""" __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") @@ -423,150 +422,403 @@ def __next__(self) -> T: return self._decode_hook(record) -def create_rows_table(conn: sqlite3.Connection) -> int: - """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. +def insert_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. ```sql - CREATE TABLE test_create_rows_table - ( - id int PRIMARY KEY NOT NULL, - test int NOT NULL - ) - ``` - - Arguments: - conn -- Connection object of type `sqlite3.Connection` used to execute the query. - - Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. - """ - return conn.execute(CREATE_ROWS_TABLE).rowcount - - -def delete_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: - """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. - - ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. id_ -- int. - - Returns: - int | None -- The id of the last affected row. Will be `None` if no rows are affected. + int_test -- int. + bigint_test -- int. + smallint_test -- int. + tinyint_test -- int. + int2_test -- int. + int8_test -- int. + bigserial_test -- int. + blob_test -- memoryview. + real_test -- float. + double_test -- float. + double_precision_test -- float. + float_test -- float. + numeric_test -- float. + decimal_test -- decimal.Decimal. + boolean_test -- bool. + bool_test -- bool. + date_test -- datetime.date. + datetime_test -- datetime.datetime. + timestamp_test -- datetime.datetime. + character_test -- str. + varchar_test -- str. + varyingcharacter_test -- str. + nchar_test -- str. + nativecharacter_test -- str. + nvarchar_test -- str. + text_test -- str. + clob_test -- str. + json_test -- str. """ - return conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_, )).lastrowid - - -def delete_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> None: - """Execute SQL query with `name: DeleteOneSqliteType :exec`. + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) + + +def insert_one_inner_sqlite_type( + conn: sqlite3.Connection, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, +) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. - id_ -- int. + table_id -- int. + int_test -- int | None. + bigint_test -- int | None. + smallint_test -- int | None. + tinyint_test -- int | None. + int2_test -- int | None. + int8_test -- int | None. + bigserial_test -- int | None. + blob_test -- memoryview | None. + real_test -- float | None. + double_test -- float | None. + double_precision_test -- float | None. + float_test -- float | None. + numeric_test -- float | None. + decimal_test -- decimal.Decimal | None. + boolean_test -- bool | None. + bool_test -- bool | None. + date_test -- datetime.date | None. + datetime_test -- datetime.datetime | None. + timestamp_test -- datetime.datetime | None. + character_test -- str | None. + varchar_test -- str | None. + varyingcharacter_test -- str | None. + nchar_test -- str | None. + nativecharacter_test -- str | None. + nvarchar_test -- str | None. + text_test -- str | None. + clob_test -- str | None. + json_test -- str | None. """ - conn.execute(DELETE_ONE_SQLITE_TYPE, (id_, )) + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) -def delete_one_test_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> None: - """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. +def get_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. ```sql - DELETE FROM test_inner_sqlite_types - WHERE test_inner_sqlite_types.table_id = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. - table_id -- int. + id_ -- int. + + Returns: + models.TestSqliteType -- Result fetched from the db. Will be `None` if not found. """ - conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id, )) + row = conn.execute(GET_ONE_SQLITE_TYPE, (id_,)).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) -def delete_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. +def get_one_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. - id_ -- int. + table_id -- int. Returns: - sqlite3.Cursor -- The result returned when executing the query. + models.TestInnerSqliteType -- Result fetched from the db. Will be `None` if not found. """ - return conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_, )) + row = conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,)).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) -def delete_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: - """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. +def get_one_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. ```sql - DELETE - FROM test_sqlite_types - WHERE test_sqlite_types.id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. id_ -- int. + date_test -- datetime.date. Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + datetime.date -- Result fetched from the db. Will be `None` if not found. """ - return conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_, )).rowcount + row = conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() + if row is None: + return None + return row[0] -def delete_type_override(conn: sqlite3.Connection, *, id_: int) -> None: - """Execute SQL query with `name: DeleteTypeOverride :exec`. +def get_one_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. ```sql - DELETE - FROM test_type_override - WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. id_ -- int. + datetime_test -- datetime.datetime. + + Returns: + datetime.datetime -- Result fetched from the db. Will be `None` if not found. """ - conn.execute(DELETE_TYPE_OVERRIDE, (id_, )) + row = conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: - """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. +def get_one_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. id_ -- int. - blob_test -- memoryview. + timestamp_test -- datetime.datetime. Returns: - QueryResults[memoryview] -- Helper class that allows both iteration and normal fetching of data from the db. + datetime.datetime -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[memoryview](conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + row = conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBool :many`. +def get_one_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -578,13 +830,16 @@ def get_many_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> Que bool_test -- bool. Returns: - QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. + bool -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + row = conn.execute(GET_ONE_BOOL, (id_, bool_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: - """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. +def get_one_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -596,63 +851,105 @@ def get_many_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) boolean_test -- bool. Returns: - QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. + bool -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[bool](conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + row = conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: - """Fetch many from the db using the SQL query with `name: GetManyDate :many`. +def get_one_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. id_ -- int. - date_test -- datetime.date. + decimal_test -- decimal.Decimal. Returns: - QueryResults[datetime.date] -- Helper class that allows both iteration and normal fetching of data from the db. + decimal.Decimal -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.date](conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + row = conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: - """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. +def get_one_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. id_ -- int. - datetime_test -- datetime.datetime. + blob_test -- memoryview. Returns: - QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. + memoryview -- Result fetched from the db. Will be `None` if not found. """ - return QueryResults[datetime.datetime](conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) + row = conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() + if row is None: + return None + return row[0] -def get_many_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: - """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. +def get_many_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. ```sql - SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. id_ -- int. - decimal_test -- decimal.Decimal. Returns: - QueryResults[decimal.Decimal] -- Helper class that allows both iteration and normal fetching of data from the db. + QueryResults[models.TestSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. """ - return QueryResults[decimal.Decimal](conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) def get_many_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: @@ -669,9 +966,41 @@ def get_many_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> Qu Returns: QueryResults[models.TestInnerSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) def get_many_nullable_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: @@ -689,47 +1018,77 @@ def get_many_nullable_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: i Returns: QueryResults[models.TestInnerSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. """ + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestInnerSqliteType](conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) -def get_many_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: - """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. +def get_many_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. id_ -- int. + date_test -- datetime.date. Returns: - QueryResults[models.TestSqliteType] -- Helper class that allows both iteration and normal fetching of data from the db. + QueryResults[datetime.date] -- Helper class that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - return QueryResults[models.TestSqliteType](conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + return QueryResults(conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) -def get_many_text_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[UserString]: - """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. +def get_many_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. id_ -- int. + datetime_test -- datetime.datetime. Returns: - QueryResults[UserString] -- Helper class that allows both iteration and normal fetching of data from the db. + QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. """ - def _decode_hook(row: sqlite3.Row) -> UserString: - return UserString(row[0]) - return QueryResults[UserString](conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + return QueryResults(conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) def get_many_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: @@ -747,51 +1106,11 @@ def get_many_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: da Returns: QueryResults[datetime.datetime] -- Helper class that allows both iteration and normal fetching of data from the db. """ - return QueryResults[datetime.datetime](conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) - - -def get_many_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: - """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. - - ```sql - SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? - ``` - - Arguments: - conn -- Connection object of type `sqlite3.Connection` used to execute the query. - id_ -- int. - - Returns: - QueryResults[models.TestTypeOverride] -- Helper class that allows both iteration and normal fetching of data from the db. - """ - def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - return QueryResults[models.TestTypeOverride](conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) - - -def get_one_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: - """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. - - ```sql - SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? - ``` - - Arguments: - conn -- Connection object of type `sqlite3.Connection` used to execute the query. - id_ -- int. - blob_test -- memoryview. - - Returns: - memoryview -- Result fetched from the db. Will be `None` if not found. - """ - row = conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) -def get_one_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBool :one`. +def get_many_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. ```sql SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? @@ -803,16 +1122,13 @@ def get_one_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> bool bool_test -- bool. Returns: - bool -- Result fetched from the db. Will be `None` if not found. + QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_BOOL, (id_, bool_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) -def get_one_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> bool | None: - """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. +def get_many_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. ```sql SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? @@ -824,58 +1140,13 @@ def get_one_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) - boolean_test -- bool. Returns: - bool -- Result fetched from the db. Will be `None` if not found. - """ - row = conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test)).fetchone() - if row is None: - return None - return row[0] - - -def get_one_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: - """Fetch one from the db using the SQL query with `name: GetOneDate :one`. - - ```sql - SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? - ``` - - Arguments: - conn -- Connection object of type `sqlite3.Connection` used to execute the query. - id_ -- int. - date_test -- datetime.date. - - Returns: - datetime.date -- Result fetched from the db. Will be `None` if not found. - """ - row = conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() - if row is None: - return None - return row[0] - - -def get_one_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. - - ```sql - SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? - ``` - - Arguments: - conn -- Connection object of type `sqlite3.Connection` used to execute the query. - id_ -- int. - datetime_test -- datetime.datetime. - - Returns: - datetime.datetime -- Result fetched from the db. Will be `None` if not found. + QueryResults[bool] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) -def get_one_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: - """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. +def get_many_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. ```sql SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? @@ -887,226 +1158,94 @@ def get_one_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal decimal_test -- decimal.Decimal. Returns: - decimal.Decimal -- Result fetched from the db. Will be `None` if not found. - """ - row = conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() - if row is None: - return None - return row[0] - - -def get_one_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. - - ```sql - SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? - ``` - - Arguments: - conn -- Connection object of type `sqlite3.Connection` used to execute the query. - table_id -- int. - - Returns: - models.TestInnerSqliteType -- Result fetched from the db. Will be `None` if not found. - """ - row = conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id, )).fetchone() - if row is None: - return None - return models.TestInnerSqliteType(table_id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - - -def get_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> models.TestSqliteType | None: - """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. - - ```sql - SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? - ``` - - Arguments: - conn -- Connection object of type `sqlite3.Connection` used to execute the query. - id_ -- int. - - Returns: - models.TestSqliteType -- Result fetched from the db. Will be `None` if not found. - """ - row = conn.execute(GET_ONE_SQLITE_TYPE, (id_, )).fetchone() - if row is None: - return None - return models.TestSqliteType(id=row[0], int_test=row[1], bigint_test=row[2], smallint_test=row[3], tinyint_test=row[4], int2_test=row[5], int8_test=row[6], bigserial_test=row[7], blob_test=row[8], real_test=row[9], double_test=row[10], double_precision_test=row[11], float_test=row[12], numeric_test=row[13], decimal_test=row[14], boolean_test=row[15], bool_test=row[16], date_test=row[17], datetime_test=row[18], timestamp_test=row[19], character_test=row[20], varchar_test=row[21], varyingcharacter_test=row[22], nchar_test=row[23], nativecharacter_test=row[24], nvarchar_test=row[25], text_test=row[26], clob_test=row[27], json_test=row[28]) - - -def get_one_text_type_override(conn: sqlite3.Connection, *, id_: int) -> UserString | None: - """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. - - ```sql - SELECT text_test FROM test_type_override WHERE test_type_override.id = ? - ``` - - Arguments: - conn -- Connection object of type `sqlite3.Connection` used to execute the query. - id_ -- int. - - Returns: - UserString -- Result fetched from the db. Will be `None` if not found. - """ - row = conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_, )).fetchone() - if row is None: - return None - return UserString(row[0]) - - -def get_one_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: - """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. - - ```sql - SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? - ``` - - Arguments: - conn -- Connection object of type `sqlite3.Connection` used to execute the query. - id_ -- int. - timestamp_test -- datetime.datetime. - - Returns: - datetime.datetime -- Result fetched from the db. Will be `None` if not found. + QueryResults[decimal.Decimal] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() - if row is None: - return None - return row[0] + return QueryResults(conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) -def get_one_type_override(conn: sqlite3.Connection, *, id_: int) -> models.TestTypeOverride | None: - """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. +def get_many_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. ```sql - SELECT id, text_test FROM test_type_override WHERE id = ? + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. id_ -- int. + blob_test -- memoryview. Returns: - models.TestTypeOverride -- Result fetched from the db. Will be `None` if not found. + QueryResults[memoryview] -- Helper class that allows both iteration and normal fetching of data from the db. """ - row = conn.execute(GET_ONE_TYPE_OVERRIDE, (id_, )).fetchone() - if row is None: - return None - return models.TestTypeOverride(id=row[0], text_test=UserString(row[1])) - + return QueryResults(conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) -def insert_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int | None: - """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. - ```sql - INSERT INTO test_sqlite_types ( - id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) - ``` +def delete_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. - Arguments: - conn -- Connection object of type `sqlite3.Connection` used to execute the query. - id_ -- int. - int_test -- int. - bigint_test -- int. - smallint_test -- int. - tinyint_test -- int. - int2_test -- int. - int8_test -- int. - bigserial_test -- int. - blob_test -- memoryview. - real_test -- float. - double_test -- float. - double_precision_test -- float. - float_test -- float. - numeric_test -- float. - decimal_test -- decimal.Decimal. - boolean_test -- bool. - bool_test -- bool. - date_test -- datetime.date. - datetime_test -- datetime.datetime. - timestamp_test -- datetime.datetime. - character_test -- str. - varchar_test -- str. - varyingcharacter_test -- str. - nchar_test -- str. - nativecharacter_test -- str. - nvarchar_test -- str. - text_test -- str. - clob_test -- str. - json_test -- str. + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` - Returns: - int | None -- The id of the last affected row. Will be `None` if no rows are affected. + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. """ - return conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)).lastrowid + conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) -def insert_one_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int, int_test: int | None, bigint_test: int | None, smallint_test: int | None, tinyint_test: int | None, int2_test: int | None, int8_test: int | None, bigserial_test: int | None, blob_test: memoryview | None, real_test: float | None, double_test: float | None, double_precision_test: float | None, float_test: float | None, numeric_test: float | None, decimal_test: decimal.Decimal | None, boolean_test: bool | None, bool_test: bool | None, date_test: datetime.date | None, datetime_test: datetime.datetime | None, timestamp_test: datetime.datetime | None, character_test: str | None, varchar_test: str | None, varyingcharacter_test: str | None, nchar_test: str | None, nativecharacter_test: str | None, nvarchar_test: str | None, text_test: str | None, clob_test: str | None, json_test: str | None) -> None: - """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. +def delete_one_test_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. ```sql - INSERT INTO test_inner_sqlite_types ( - table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, - blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, - boolean_test, bool_test, date_test, datetime_test, timestamp_test, - character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, - nvarchar_test, text_test, clob_test, json_test - ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, - ?, ?, ?, ?, ?, ?, ?, ?, ? - ) + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? ``` Arguments: conn -- Connection object of type `sqlite3.Connection` used to execute the query. table_id -- int. - int_test -- int | None. - bigint_test -- int | None. - smallint_test -- int | None. - tinyint_test -- int | None. - int2_test -- int | None. - int8_test -- int | None. - bigserial_test -- int | None. - blob_test -- memoryview | None. - real_test -- float | None. - double_test -- float | None. - double_precision_test -- float | None. - float_test -- float | None. - numeric_test -- float | None. - decimal_test -- decimal.Decimal | None. - boolean_test -- bool | None. - bool_test -- bool | None. - date_test -- datetime.date | None. - datetime_test -- datetime.datetime | None. - timestamp_test -- datetime.datetime | None. - character_test -- str | None. - varchar_test -- str | None. - varyingcharacter_test -- str | None. - nchar_test -- str | None. - nativecharacter_test -- str | None. - nvarchar_test -- str | None. - text_test -- str | None. - clob_test -- str | None. - json_test -- str | None. """ - conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, (table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) - - -def insert_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> None: - """Execute SQL query with `name: InsertOneSqliteType :exec`. + conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) + + +def insert_result_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. ```sql INSERT INTO test_sqlite_types ( @@ -1154,12 +1293,116 @@ def insert_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, text_test -- str. clob_test -- str. json_test -- str. + + Returns: + sqlite3.Cursor -- The result returned when executing the query. """ - conn.execute(INSERT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) -def insert_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. +def update_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + + Returns: + sqlite3.Cursor -- The result returned when executing the query. + """ + return conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +def delete_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + + Returns: + sqlite3.Cursor -- The result returned when executing the query. + """ + return conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +def insert_rows_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. ```sql INSERT INTO test_sqlite_types ( @@ -1209,13 +1452,134 @@ def insert_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_tes json_test -- str. Returns: - sqlite3.Cursor -- The result returned when executing the query. + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. """ - return conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)) + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args).rowcount -def insert_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: int, bigint_test: int, smallint_test: int, tinyint_test: int, int2_test: int, int8_test: int, bigserial_test: int, blob_test: memoryview, real_test: float, double_test: float, double_precision_test: float, float_test: float, numeric_test: float, decimal_test: decimal.Decimal, boolean_test: bool, bool_test: bool, date_test: datetime.date, datetime_test: datetime.datetime, timestamp_test: datetime.datetime, character_test: str, varchar_test: str, varyingcharacter_test: str, nchar_test: str, nativecharacter_test: str, nvarchar_test: str, text_test: str, clob_test: str, json_test: str) -> int: - """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. +def update_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + + Returns: + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + +def delete_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + + Returns: + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + +def create_rows_table(conn: sqlite3.Connection) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + + Returns: + int -- The number of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return conn.execute(CREATE_ROWS_TABLE).rowcount + + +def insert_last_id_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. ```sql INSERT INTO test_sqlite_types ( @@ -1265,9 +1629,78 @@ def insert_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int, int_test: json_test -- str. Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + int -- The id of the last affected row. Will be `None` if no rows are affected. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args).lastrowid + + +def update_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + + Returns: + int -- The id of the last affected row. Will be `None` if no rows are affected. + """ + return conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid + + +def delete_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + + Returns: + int -- The id of the last affected row. Will be `None` if no rows are affected. """ - return conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, (id_, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test)).rowcount + return conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid def insert_type_override(conn: sqlite3.Connection, *, id_: int, text_test: UserString | None) -> None: @@ -1284,16 +1717,14 @@ def insert_type_override(conn: sqlite3.Connection, *, id_: int, text_test: UserS id_ -- int. text_test -- UserString | None. """ - conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test))) + conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) -def update_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: - """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. +def get_one_type_override(conn: sqlite3.Connection, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE id = ? ``` Arguments: @@ -1301,18 +1732,19 @@ def update_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int id_ -- int. Returns: - int | None -- The id of the last affected row. Will be `None` if no rows are affected. + models.TestTypeOverride -- Result fetched from the db. Will be `None` if not found. """ - return conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_, )).lastrowid + row = conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) -def update_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: - """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. +def get_many_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? ``` Arguments: @@ -1320,18 +1752,40 @@ def update_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqli id_ -- int. Returns: - sqlite3.Cursor -- The result returned when executing the query. + QueryResults[models.TestTypeOverride] -- Helper class that allows both iteration and normal fetching of data from the db. """ - return conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_, )) + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) -def update_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: - """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + +def get_one_text_type_override(conn: sqlite3.Connection, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. ```sql - UPDATE test_sqlite_types - SET int_test = 187 - WHERE test_sqlite_types.id = ? + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + + Returns: + UserString -- Result fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + +def get_many_text_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? ``` Arguments: @@ -1339,6 +1793,26 @@ def update_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: id_ -- int. Returns: - int -- The number of affected rows. This will be 0 for queries like `CREATE TABLE`. + QueryResults[UserString | None] -- Helper class that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + +def delete_type_override(conn: sqlite3.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. """ - return conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_, )).rowcount + conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_sqlite3/msgspec/functions/queries_case.py b/test/driver_sqlite3/msgspec/functions/queries_case.py new file mode 100644 index 00000000..fac3dc2e --- /dev/null +++ b/test/driver_sqlite3/msgspec/functions/queries_case.py @@ -0,0 +1,149 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_case.sql +"""Module containing queries from file queries_case.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "GetCaseRowRow", + "get_case_row", + "get_reserved_arg", + "insert_case_row", + "insert_reserved_arg", +) + +import datetime +import decimal +import msgspec +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _convert_decimal(val: bytes) -> decimal.Decimal: + return decimal.Decimal(val.decode()) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + +sqlite3.register_converter("decimal", _convert_decimal) +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +class GetCaseRowRow(msgspec.Struct): + """Model representing GetCaseRowRow. + + Attributes: + upper_dt -- datetime.datetime + prec_dec -- decimal.Decimal + """ + + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + + +INSERT_CASE_ROW: typing.Final[str] = """-- name: InsertCaseRow :exec +INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) +""" + +GET_CASE_ROW: typing.Final[str] = """-- name: GetCaseRow :one +SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? +""" + +INSERT_RESERVED_ARG: typing.Final[str] = """-- name: InsertReservedArg :exec +INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) +""" + +GET_RESERVED_ARG: typing.Final[str] = """-- name: GetReservedArg :one +SELECT id FROM test_reserved_args WHERE conn = ? +""" + + +def insert_case_row(conn: sqlite3.Connection, *, id_: int, upper_dt: datetime.datetime, prec_dec: decimal.Decimal) -> None: + """Execute SQL query with `name: InsertCaseRow :exec`. + + ```sql + INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + upper_dt -- datetime.datetime. + prec_dec -- decimal.Decimal. + """ + conn.execute(INSERT_CASE_ROW, (id_, upper_dt, prec_dec)) + + +def get_case_row(conn: sqlite3.Connection, *, id_: int) -> GetCaseRowRow | None: + """Fetch one from the db using the SQL query with `name: GetCaseRow :one`. + + ```sql + SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + + Returns: + GetCaseRowRow -- Result fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_CASE_ROW, (id_,)).fetchone() + if row is None: + return None + return GetCaseRowRow(upper_dt=row[0], prec_dec=row[1]) + + +def insert_reserved_arg(conn: sqlite3.Connection, *, id_: int, conn_2: str) -> None: + """Execute SQL query with `name: InsertReservedArg :exec`. + + ```sql + INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + conn_2 -- str. + """ + conn.execute(INSERT_RESERVED_ARG, (id_, conn_2)) + + +def get_reserved_arg(conn: sqlite3.Connection, *, conn_2: str) -> int | None: + """Fetch one from the db using the SQL query with `name: GetReservedArg :one`. + + ```sql + SELECT id FROM test_reserved_args WHERE conn = ? + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + conn_2 -- str. + + Returns: + int -- Result fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_RESERVED_ARG, (conn_2,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/msgspec/functions/queries_override_adapter.py b/test/driver_sqlite3/msgspec/functions/queries_override_adapter.py new file mode 100644 index 00000000..c2f1470e --- /dev/null +++ b/test/driver_sqlite3/msgspec/functions/queries_override_adapter.py @@ -0,0 +1,78 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_adapter.sql +"""Module containing queries from file queries_override_adapter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "get_override_price", + "insert_override_conversion", +) + +import datetime +import decimal +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + + +INSERT_OVERRIDE_CONVERSION: typing.Final[str] = """-- name: InsertOverrideConversion :exec +INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) +""" + +GET_OVERRIDE_PRICE: typing.Final[str] = """-- name: GetOverridePrice :one +SELECT price FROM test_override_conversion WHERE id = ? +""" + + +def insert_override_conversion(conn: sqlite3.Connection, *, id_: int, price: float, happened_at: datetime.datetime) -> None: + """Execute SQL query with `name: InsertOverrideConversion :exec`. + + ```sql + INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + price -- float. + happened_at -- datetime.datetime. + """ + conn.execute(INSERT_OVERRIDE_CONVERSION, (id_, decimal.Decimal(price), happened_at)) + + +def get_override_price(conn: sqlite3.Connection, *, id_: int) -> float | None: + """Fetch one from the db using the SQL query with `name: GetOverridePrice :one`. + + ```sql + SELECT price FROM test_override_conversion WHERE id = ? + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + + Returns: + float -- Result fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_OVERRIDE_PRICE, (id_,)).fetchone() + if row is None: + return None + return float(row[0]) diff --git a/test/driver_sqlite3/msgspec/functions/queries_override_converter.py b/test/driver_sqlite3/msgspec/functions/queries_override_converter.py new file mode 100644 index 00000000..f8fdabbb --- /dev/null +++ b/test/driver_sqlite3/msgspec/functions/queries_override_converter.py @@ -0,0 +1,50 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_converter.sql +"""Module containing queries from file queries_override_converter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("get_override_happened_at",) + +import datetime +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +GET_OVERRIDE_HAPPENED_AT: typing.Final[str] = """-- name: GetOverrideHappenedAt :one +SELECT happened_at FROM test_override_conversion WHERE id = ? +""" + + +def get_override_happened_at(conn: sqlite3.Connection, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOverrideHappenedAt :one`. + + ```sql + SELECT happened_at FROM test_override_conversion WHERE id = ? + ``` + + Arguments: + conn -- Connection object of type `sqlite3.Connection` used to execute the query. + id_ -- int. + + Returns: + datetime.datetime -- Result fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_OVERRIDE_HAPPENED_AT, (id_,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/msgspec/test_sqlite3_msgspec_classes.py b/test/driver_sqlite3/msgspec/test_sqlite3_msgspec_classes.py index ca4d214a..da9ac05a 100644 --- a/test/driver_sqlite3/msgspec/test_sqlite3_msgspec_classes.py +++ b/test/driver_sqlite3/msgspec/test_sqlite3_msgspec_classes.py @@ -36,12 +36,12 @@ class TestSqlite3MsgspecClasses: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestSqliteType: return models.TestSqliteType( - id=random.randint(1, 10000000), + id_=random.randint(1, 10000000), int_test=42, bigint_test=9_007_199_254_740_991, smallint_test=32_767, @@ -75,7 +75,7 @@ def model(self) -> models.TestSqliteType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: return models.TestInnerSqliteType( - table_id=model.id, + table_id=model.id_, int_test=None, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -120,7 +120,7 @@ def test_insert( model: models.TestSqliteType, ) -> None: queries_obj.insert_one_sqlite_type( - id_=model.id, + id_=model.id_, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -151,9 +151,7 @@ def test_insert( json_test=model.json_test, ) - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::inner_insert", depends=["Sqlite3TestMsgspecClasses::insert"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::inner_insert", depends=["Sqlite3TestMsgspecClasses::insert"]) def test_inner_insert( self, queries_obj: queries.Queries, @@ -191,15 +189,13 @@ def test_inner_insert( json_test=inner_model.json_test, ) - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_one", depends=["Sqlite3TestMsgspecClasses::inner_insert"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_one", depends=["Sqlite3TestMsgspecClasses::inner_insert"]) def test_get_one( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_sqlite_type(id_=model.id) + result = queries_obj.get_one_sqlite_type(id_=model.id_) assert result is not None @@ -207,9 +203,7 @@ def test_get_one( assert result == model - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_one_none", depends=["Sqlite3TestMsgspecClasses::get_one"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_one_none", depends=["Sqlite3TestMsgspecClasses::get_one"]) def test_get_one_none( self, queries_obj: queries.Queries, @@ -218,9 +212,7 @@ def test_get_one_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_one_inner", depends=["Sqlite3TestMsgspecClasses::get_one_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_one_inner", depends=["Sqlite3TestMsgspecClasses::get_one_none"]) def test_get_one_inner( self, queries_obj: queries.Queries, @@ -233,9 +225,7 @@ def test_get_one_inner( assert isinstance(result, models.TestInnerSqliteType) assert result == inner_model - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_one_inner_none", depends=["Sqlite3TestMsgspecClasses::get_one_inner"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_one_inner_none", depends=["Sqlite3TestMsgspecClasses::get_one_inner"]) def test_get_one_inner_none( self, queries_obj: queries.Queries, @@ -244,24 +234,20 @@ def test_get_one_inner_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_date", depends=["Sqlite3TestMsgspecClasses::get_one_inner_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_date", depends=["Sqlite3TestMsgspecClasses::get_one_inner_none"]) def test_get_date( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_date(id_=model.id, date_test=model.date_test) + result = queries_obj.get_one_date(id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, datetime.date) assert result == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_date_none", depends=["Sqlite3TestMsgspecClasses::get_date"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_date_none", depends=["Sqlite3TestMsgspecClasses::get_date"]) def test_get_date_none( self, queries_obj: queries.Queries, @@ -270,24 +256,20 @@ def test_get_date_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_datetime", depends=["Sqlite3TestMsgspecClasses::get_date_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_datetime", depends=["Sqlite3TestMsgspecClasses::get_date_none"]) def test_get_datetime( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_datetime(id_=model.id, datetime_test=model.datetime_test) + result = queries_obj.get_one_datetime(id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.datetime_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_datetime_none", depends=["Sqlite3TestMsgspecClasses::get_datetime"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_datetime_none", depends=["Sqlite3TestMsgspecClasses::get_datetime"]) def test_get_datetime_none( self, queries_obj: queries.Queries, @@ -296,24 +278,20 @@ def test_get_datetime_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_timestamp", depends=["Sqlite3TestMsgspecClasses::get_datetime_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_timestamp", depends=["Sqlite3TestMsgspecClasses::get_datetime_none"]) def test_get_timestamp( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_timestamp(id_=model.id, timestamp_test=model.timestamp_test) + result = queries_obj.get_one_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_timestamp_none", depends=["Sqlite3TestMsgspecClasses::get_timestamp"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_timestamp_none", depends=["Sqlite3TestMsgspecClasses::get_timestamp"]) def test_get_timestamp_none( self, queries_obj: queries.Queries, @@ -322,24 +300,20 @@ def test_get_timestamp_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_bool", depends=["Sqlite3TestMsgspecClasses::get_timestamp_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_bool", depends=["Sqlite3TestMsgspecClasses::get_timestamp_none"]) def test_get_bool( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_bool(id_=model.id, bool_test=model.bool_test) + result = queries_obj.get_one_bool(id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, bool) assert result == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_bool_none", depends=["Sqlite3TestMsgspecClasses::get_bool"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_bool_none", depends=["Sqlite3TestMsgspecClasses::get_bool"]) def test_get_bool_none( self, queries_obj: queries.Queries, @@ -348,24 +322,20 @@ def test_get_bool_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_boolean", depends=["Sqlite3TestMsgspecClasses::get_bool_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_boolean", depends=["Sqlite3TestMsgspecClasses::get_bool_none"]) def test_get_boolean( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_boolean(id_=model.id, boolean_test=model.boolean_test) + result = queries_obj.get_one_boolean(id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, bool) assert result == model.boolean_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_boolean_none", depends=["Sqlite3TestMsgspecClasses::get_boolean"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_boolean_none", depends=["Sqlite3TestMsgspecClasses::get_boolean"]) def test_get_boolean_none( self, queries_obj: queries.Queries, @@ -374,24 +344,20 @@ def test_get_boolean_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_decimal", depends=["Sqlite3TestMsgspecClasses::get_boolean_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_decimal", depends=["Sqlite3TestMsgspecClasses::get_boolean_none"]) def test_get_decimal( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_decimal(id_=model.id, decimal_test=model.decimal_test) + result = queries_obj.get_one_decimal(id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, decimal.Decimal) assert result == model.decimal_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_decimal_none", depends=["Sqlite3TestMsgspecClasses::get_decimal"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_decimal_none", depends=["Sqlite3TestMsgspecClasses::get_decimal"]) def test_get_decimal_none( self, queries_obj: queries.Queries, @@ -400,24 +366,20 @@ def test_get_decimal_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_blob", depends=["Sqlite3TestMsgspecClasses::get_decimal_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_blob", depends=["Sqlite3TestMsgspecClasses::get_decimal_none"]) def test_get_blob( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.get_one_blob(id_=model.id, blob_test=model.blob_test) + result = queries_obj.get_one_blob(id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_blob_none", depends=["Sqlite3TestMsgspecClasses::get_blob"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_blob_none", depends=["Sqlite3TestMsgspecClasses::get_blob"]) def test_get_blob_none( self, queries_obj: queries.Queries, @@ -426,11 +388,9 @@ def test_get_blob_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many", depends=["Sqlite3TestMsgspecClasses::get_blob_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many", depends=["Sqlite3TestMsgspecClasses::get_blob_none"]) def test_get_many(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_sqlite_type(id_=model.id) + result = queries_obj.get_many_sqlite_type(id_=model.id_) assert result is not None assert isinstance(result, queries.QueryResults) @@ -443,19 +403,15 @@ def test_get_many(self, queries_obj: queries.Queries, model: models.TestSqliteTy assert results[0] == model - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_iter", depends=["Sqlite3TestMsgspecClasses::get_many"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_iter", depends=["Sqlite3TestMsgspecClasses::get_many"]) def test_get_many_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_sqlite_type(id_=model.id): + for result in queries_obj.get_many_sqlite_type(id_=model.id_): assert result is not None assert isinstance(result, models.TestSqliteType) assert result == model - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_inner", depends=["Sqlite3TestMsgspecClasses::get_many_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_inner", depends=["Sqlite3TestMsgspecClasses::get_many_iter"]) def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: result = queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id) @@ -466,9 +422,7 @@ def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: models. assert results[0] == inner_model - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_inner_iter", depends=["Sqlite3TestMsgspecClasses::get_many_inner"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_inner_iter", depends=["Sqlite3TestMsgspecClasses::get_many_inner"]) def test_get_many_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: for result in queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id): assert result is not None @@ -481,12 +435,8 @@ def test_get_many_inner_iter(self, queries_obj: queries.Queries, inner_model: mo name="Sqlite3TestMsgspecClasses::get_many_nullable_inner", depends=["Sqlite3TestMsgspecClasses::get_many_inner_iter"], ) - async def test_get_many_nullable_inner( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: - result = queries_obj.get_many_nullable_inner_sqlite_type( - table_id=inner_model.table_id, int_test=inner_model.int_test - ) + async def test_get_many_nullable_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + result = queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -500,12 +450,8 @@ async def test_get_many_nullable_inner( name="Sqlite3TestMsgspecClasses::get_many_nullable_inner_iter", depends=["Sqlite3TestMsgspecClasses::get_many_nullable_inner"], ) - async def test_get_many_nullable_inner_iter( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: - for result in queries_obj.get_many_nullable_inner_sqlite_type( - table_id=inner_model.table_id, int_test=inner_model.int_test - ): + async def test_get_many_nullable_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + for result in queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -516,7 +462,7 @@ async def test_get_many_nullable_inner_iter( depends=["Sqlite3TestMsgspecClasses::get_many_nullable_inner_iter"], ) def test_get_many_date(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_date(id_=model.id, date_test=model.date_test) + result = queries_obj.get_many_date(id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -525,21 +471,17 @@ def test_get_many_date(self, queries_obj: queries.Queries, model: models.TestSql assert results[0] == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_date_iter", depends=["Sqlite3TestMsgspecClasses::get_many_date"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_date_iter", depends=["Sqlite3TestMsgspecClasses::get_many_date"]) def test_get_many_date_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_date(id_=model.id, date_test=model.date_test): + for result in queries_obj.get_many_date(id_=model.id_, date_test=model.date_test): assert result is not None assert isinstance(result, datetime.date) assert result == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_datetime", depends=["Sqlite3TestMsgspecClasses::get_many_date_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_datetime", depends=["Sqlite3TestMsgspecClasses::get_many_date_iter"]) def test_get_many_datetime(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_datetime(id_=model.id, datetime_test=model.datetime_test) + result = queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -553,7 +495,7 @@ def test_get_many_datetime(self, queries_obj: queries.Queries, model: models.Tes depends=["Sqlite3TestMsgspecClasses::get_many_datetime"], ) def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_datetime(id_=model.id, datetime_test=model.datetime_test): + for result in queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -564,7 +506,7 @@ def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: model depends=["Sqlite3TestMsgspecClasses::get_many_datetime_iter"], ) def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_timestamp(id_=model.id, timestamp_test=model.timestamp_test) + result = queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -578,17 +520,15 @@ def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.Te depends=["Sqlite3TestMsgspecClasses::get_many_timestamp"], ) def test_get_many_timestamp_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_timestamp(id_=model.id, timestamp_test=model.timestamp_test): + for result in queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test): assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_bool", depends=["Sqlite3TestMsgspecClasses::get_many_timestamp_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_bool", depends=["Sqlite3TestMsgspecClasses::get_many_timestamp_iter"]) def test_get_many_bool(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_bool(id_=model.id, bool_test=model.bool_test) + result = queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -597,21 +537,17 @@ def test_get_many_bool(self, queries_obj: queries.Queries, model: models.TestSql assert results[0] == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_bool_iter", depends=["Sqlite3TestMsgspecClasses::get_many_bool"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_bool_iter", depends=["Sqlite3TestMsgspecClasses::get_many_bool"]) def test_get_many_bool_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_bool(id_=model.id, bool_test=model.bool_test): + for result in queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test): assert result is not None assert isinstance(result, bool) assert result == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_boolean", depends=["Sqlite3TestMsgspecClasses::get_many_bool_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_boolean", depends=["Sqlite3TestMsgspecClasses::get_many_bool_iter"]) def test_get_many_boolean(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_boolean(id_=model.id, boolean_test=model.boolean_test) + result = queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -620,21 +556,17 @@ def test_get_many_boolean(self, queries_obj: queries.Queries, model: models.Test assert results[0] == model.boolean_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_boolean_iter", depends=["Sqlite3TestMsgspecClasses::get_many_boolean"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_boolean_iter", depends=["Sqlite3TestMsgspecClasses::get_many_boolean"]) def test_get_many_boolean_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_boolean(id_=model.id, boolean_test=model.boolean_test): + for result in queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test): assert result is not None assert isinstance(result, bool) assert result == model.boolean_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_decimal", depends=["Sqlite3TestMsgspecClasses::get_many_boolean_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_decimal", depends=["Sqlite3TestMsgspecClasses::get_many_boolean_iter"]) def test_get_many_decimal(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_decimal(id_=model.id, decimal_test=model.decimal_test) + result = queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -643,21 +575,17 @@ def test_get_many_decimal(self, queries_obj: queries.Queries, model: models.Test assert results[0] == model.decimal_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_decimal_iter", depends=["Sqlite3TestMsgspecClasses::get_many_decimal"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_decimal_iter", depends=["Sqlite3TestMsgspecClasses::get_many_decimal"]) def test_get_many_decimal_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_decimal(id_=model.id, decimal_test=model.decimal_test): + for result in queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test): assert result is not None assert isinstance(result, decimal.Decimal) assert result == model.decimal_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_blob", depends=["Sqlite3TestMsgspecClasses::get_many_decimal_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_blob", depends=["Sqlite3TestMsgspecClasses::get_many_decimal_iter"]) def test_get_many_blob(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - result = queries_obj.get_many_blob(id_=model.id, blob_test=model.blob_test) + result = queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -666,26 +594,22 @@ def test_get_many_blob(self, queries_obj: queries.Queries, model: models.TestSql assert results[0] == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::get_many_blob_iter", depends=["Sqlite3TestMsgspecClasses::get_many_blob"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::get_many_blob_iter", depends=["Sqlite3TestMsgspecClasses::get_many_blob"]) def test_get_many_blob_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - for result in queries_obj.get_many_blob(id_=model.id, blob_test=model.blob_test): + for result in queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test): assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::insert_result", depends=["Sqlite3TestMsgspecClasses::get_many_blob_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::insert_result", depends=["Sqlite3TestMsgspecClasses::get_many_blob_iter"]) def test_insert_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = queries_obj.insert_result_one_sqlite_type( - id_=model.id + 1, + id_=model.id_ + 1, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -717,38 +641,32 @@ def test_insert_result( ) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::update_result", depends=["Sqlite3TestMsgspecClasses::insert_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::update_result", depends=["Sqlite3TestMsgspecClasses::insert_result"]) def test_update_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.update_result_one_sqlite_type(id_=model.id + 1) + result = queries_obj.update_result_one_sqlite_type(id_=model.id_ + 1) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::delete_result", depends=["Sqlite3TestMsgspecClasses::update_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::delete_result", depends=["Sqlite3TestMsgspecClasses::update_result"]) def test_delete_result( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.delete_result_one_sqlite_type(id_=model.id + 1) + result = queries_obj.delete_result_one_sqlite_type(id_=model.id_ + 1) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::insert_rows", depends=["Sqlite3TestMsgspecClasses::delete_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::insert_rows", depends=["Sqlite3TestMsgspecClasses::delete_result"]) def test_insert_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = queries_obj.insert_rows_one_sqlite_type( - id_=model.id + 2, + id_=model.id_ + 2, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -781,33 +699,27 @@ def test_insert_rows( assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::update_rows", depends=["Sqlite3TestMsgspecClasses::insert_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::update_rows", depends=["Sqlite3TestMsgspecClasses::insert_rows"]) def test_update_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.update_rows_one_sqlite_type(id_=model.id + 2) + result = queries_obj.update_rows_one_sqlite_type(id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::delete_rows", depends=["Sqlite3TestMsgspecClasses::update_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::delete_rows", depends=["Sqlite3TestMsgspecClasses::update_rows"]) def test_delete_rows( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.delete_rows_one_sqlite_type(id_=model.id + 2) + result = queries_obj.delete_rows_one_sqlite_type(id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::create_table_rows", depends=["Sqlite3TestMsgspecClasses::delete_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::create_table_rows", depends=["Sqlite3TestMsgspecClasses::delete_rows"]) def test_create_table_rows( self, queries_obj: queries.Queries, @@ -819,16 +731,14 @@ def test_create_table_rows( sqlite3_conn.commit() assert result == -1 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::insert_last_id", depends=["Sqlite3TestMsgspecClasses::create_table_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::insert_last_id", depends=["Sqlite3TestMsgspecClasses::create_table_rows"]) def test_insert_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: result = queries_obj.insert_last_id_one_sqlite_type( - id_=model.id + 3, + id_=model.id_ + 3, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -859,59 +769,51 @@ def test_insert_last_id( json_test=model.json_test, ) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::update_last_id", depends=["Sqlite3TestMsgspecClasses::insert_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::update_last_id", depends=["Sqlite3TestMsgspecClasses::insert_last_id"]) def test_update_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.update_last_id_one_sqlite_type(id_=model.id + 3) + result = queries_obj.update_last_id_one_sqlite_type(id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::delete_last_id", depends=["Sqlite3TestMsgspecClasses::update_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::delete_last_id", depends=["Sqlite3TestMsgspecClasses::update_last_id"]) def test_delete_last_id( self, queries_obj: queries.Queries, model: models.TestSqliteType, ) -> None: - result = queries_obj.delete_last_id_one_sqlite_type(id_=model.id + 3) + result = queries_obj.delete_last_id_one_sqlite_type(id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecClasses::delete_sqlite_type", depends=["Sqlite3TestMsgspecClasses::delete_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecClasses::delete_sqlite_type", depends=["Sqlite3TestMsgspecClasses::delete_last_id"]) def test_delete_sqlite_type(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: - queries_obj.delete_one_sqlite_type(id_=model.id) + queries_obj.delete_one_sqlite_type(id_=model.id_) @pytest.mark.dependency( name="Sqlite3TestMsgspecClasses::delete_inner_sqlite_type", depends=["Sqlite3TestMsgspecClasses::delete_sqlite_type"], ) - def test_delete_inner_sqlite_type( - self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType - ) -> None: + def test_delete_inner_sqlite_type(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: queries_obj.delete_one_test_inner_sqlite_type(table_id=inner_model.table_id) @pytest.mark.dependency( name="Sqlite3TestMsgspecClasses::insert_type_override", ) def test_insert_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: - queries_obj.insert_type_override(id_=override_model.id, text_test=override_model.text_test) + queries_obj.insert_type_override(id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.dependency( name="Sqlite3TestMsgspecClasses::get_one_type_override", depends=["Sqlite3TestMsgspecClasses::insert_type_override"], ) def test_get_one_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: - result = queries_obj.get_one_type_override(id_=override_model.id) + result = queries_obj.get_one_type_override(id_=override_model.id_) assert result is not None assert result == override_model @@ -919,20 +821,16 @@ def test_get_one_type_override(self, queries_obj: queries.Queries, override_mode name="Sqlite3TestMsgspecClasses::get_one_type_override_none", depends=["Sqlite3TestMsgspecClasses::get_one_type_override"], ) - def test_get_one_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_one_type_override(id_=override_model.id - 1) + def test_get_one_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.dependency( name="Sqlite3TestMsgspecClasses::get_many_type_override", depends=["Sqlite3TestMsgspecClasses::get_one_type_override_none"], ) - def test_get_many_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_many_type_override(id_=override_model.id) + def test_get_many_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_many_type_override(id_=override_model.id_) assert result is not None assert isinstance(result, queries.QueryResults) results = list(result) @@ -944,10 +842,8 @@ def test_get_many_type_override( name="Sqlite3TestMsgspecClasses::get_one_text_type_override", depends=["Sqlite3TestMsgspecClasses::get_many_type_override"], ) - def test_get_one_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_one_text_type_override(id_=override_model.id) + def test_get_one_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_text_type_override(id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -955,20 +851,16 @@ def test_get_one_text_type_override( name="Sqlite3TestMsgspecClasses::get_one_text_type_override_none", depends=["Sqlite3TestMsgspecClasses::get_one_text_type_override"], ) - def test_get_one_text_type_override_none( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_one_text_type_override(id_=override_model.id - 1) + def test_get_one_text_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_text_type_override(id_=override_model.id_ - 1) assert result is None @pytest.mark.dependency( name="Sqlite3TestMsgspecClasses::get_many_text_type_override", depends=["Sqlite3TestMsgspecClasses::get_one_text_type_override_none"], ) - def test_get_many_text_type_override( - self, queries_obj: queries.Queries, override_model: models.TestTypeOverride - ) -> None: - result = queries_obj.get_many_text_type_override(id_=override_model.id) + def test_get_many_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_many_text_type_override(id_=override_model.id_) assert result is not None assert isinstance(result, queries.QueryResults) results = list(result) @@ -981,4 +873,4 @@ def test_get_many_text_type_override( depends=["Sqlite3TestMsgspecClasses::get_many_text_type_override"], ) def test_delete_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: - queries_obj.delete_type_override(id_=override_model.id) + queries_obj.delete_type_override(id_=override_model.id_) diff --git a/test/driver_sqlite3/msgspec/test_sqlite3_msgspec_functions.py b/test/driver_sqlite3/msgspec/test_sqlite3_msgspec_functions.py index 01c3d0b4..9b9c1bf7 100644 --- a/test/driver_sqlite3/msgspec/test_sqlite3_msgspec_functions.py +++ b/test/driver_sqlite3/msgspec/test_sqlite3_msgspec_functions.py @@ -36,12 +36,12 @@ class TestSqlite3MsgspecFunctions: @pytest.fixture(scope="session") def override_model(self) -> models.TestTypeOverride: - return models.TestTypeOverride(id=random.randint(1, 10000000), text_test=UserString("Test")) + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) @pytest.fixture(scope="session") def model(self) -> models.TestSqliteType: return models.TestSqliteType( - id=random.randint(1, 10000000), + id_=random.randint(1, 10000000), int_test=42, bigint_test=9_007_199_254_740_991, smallint_test=32_767, @@ -75,7 +75,7 @@ def model(self) -> models.TestSqliteType: @pytest.fixture(scope="session") def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: return models.TestInnerSqliteType( - table_id=model.id, + table_id=model.id_, int_test=None, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -114,7 +114,7 @@ def test_insert( ) -> None: queries.insert_one_sqlite_type( conn=sqlite3_conn, - id_=model.id, + id_=model.id_, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -145,9 +145,7 @@ def test_insert( json_test=model.json_test, ) - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::inner_insert", depends=["Sqlite3TestMsgspecFunctions::insert"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::inner_insert", depends=["Sqlite3TestMsgspecFunctions::insert"]) def test_inner_insert( self, sqlite3_conn: sqlite3.Connection, @@ -186,15 +184,13 @@ def test_inner_insert( json_test=inner_model.json_test, ) - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_one", depends=["Sqlite3TestMsgspecFunctions::inner_insert"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_one", depends=["Sqlite3TestMsgspecFunctions::inner_insert"]) def test_get_one( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_sqlite_type(conn=sqlite3_conn, id_=model.id) + result = queries.get_one_sqlite_type(conn=sqlite3_conn, id_=model.id_) assert result is not None @@ -202,9 +198,7 @@ def test_get_one( assert result == model - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_one_none", depends=["Sqlite3TestMsgspecFunctions::get_one"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_one_none", depends=["Sqlite3TestMsgspecFunctions::get_one"]) def test_get_one_none( self, sqlite3_conn: sqlite3.Connection, @@ -213,9 +207,7 @@ def test_get_one_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_one_inner", depends=["Sqlite3TestMsgspecFunctions::get_one_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_one_inner", depends=["Sqlite3TestMsgspecFunctions::get_one_none"]) def test_get_one_inner( self, sqlite3_conn: sqlite3.Connection, @@ -228,9 +220,7 @@ def test_get_one_inner( assert isinstance(result, models.TestInnerSqliteType) assert result == inner_model - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_one_inner_none", depends=["Sqlite3TestMsgspecFunctions::get_one_inner"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_one_inner_none", depends=["Sqlite3TestMsgspecFunctions::get_one_inner"]) def test_get_one_inner_none( self, sqlite3_conn: sqlite3.Connection, @@ -239,24 +229,20 @@ def test_get_one_inner_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_date", depends=["Sqlite3TestMsgspecFunctions::get_one_inner_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_date", depends=["Sqlite3TestMsgspecFunctions::get_one_inner_none"]) def test_get_date( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_date(conn=sqlite3_conn, id_=model.id, date_test=model.date_test) + result = queries.get_one_date(conn=sqlite3_conn, id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, datetime.date) assert result == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_date_none", depends=["Sqlite3TestMsgspecFunctions::get_date"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_date_none", depends=["Sqlite3TestMsgspecFunctions::get_date"]) def test_get_date_none( self, sqlite3_conn: sqlite3.Connection, @@ -265,24 +251,20 @@ def test_get_date_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_datetime", depends=["Sqlite3TestMsgspecFunctions::get_date_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_datetime", depends=["Sqlite3TestMsgspecFunctions::get_date_none"]) def test_get_datetime( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_datetime(conn=sqlite3_conn, id_=model.id, datetime_test=model.datetime_test) + result = queries.get_one_datetime(conn=sqlite3_conn, id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.datetime_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_datetime_none", depends=["Sqlite3TestMsgspecFunctions::get_datetime"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_datetime_none", depends=["Sqlite3TestMsgspecFunctions::get_datetime"]) def test_get_datetime_none( self, sqlite3_conn: sqlite3.Connection, @@ -291,24 +273,20 @@ def test_get_datetime_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_timestamp", depends=["Sqlite3TestMsgspecFunctions::get_datetime_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_timestamp", depends=["Sqlite3TestMsgspecFunctions::get_datetime_none"]) def test_get_timestamp( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_timestamp(conn=sqlite3_conn, id_=model.id, timestamp_test=model.timestamp_test) + result = queries.get_one_timestamp(conn=sqlite3_conn, id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, datetime.datetime) assert result == model.timestamp_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_timestamp_none", depends=["Sqlite3TestMsgspecFunctions::get_timestamp"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_timestamp_none", depends=["Sqlite3TestMsgspecFunctions::get_timestamp"]) def test_get_timestamp_none( self, sqlite3_conn: sqlite3.Connection, @@ -317,24 +295,20 @@ def test_get_timestamp_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_bool", depends=["Sqlite3TestMsgspecFunctions::get_timestamp_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_bool", depends=["Sqlite3TestMsgspecFunctions::get_timestamp_none"]) def test_get_bool( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_bool(conn=sqlite3_conn, id_=model.id, bool_test=model.bool_test) + result = queries.get_one_bool(conn=sqlite3_conn, id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, bool) assert result == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_bool_none", depends=["Sqlite3TestMsgspecFunctions::get_bool"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_bool_none", depends=["Sqlite3TestMsgspecFunctions::get_bool"]) def test_get_bool_none( self, sqlite3_conn: sqlite3.Connection, @@ -343,24 +317,20 @@ def test_get_bool_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_boolean", depends=["Sqlite3TestMsgspecFunctions::get_bool_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_boolean", depends=["Sqlite3TestMsgspecFunctions::get_bool_none"]) def test_get_boolean( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_boolean(conn=sqlite3_conn, id_=model.id, boolean_test=model.boolean_test) + result = queries.get_one_boolean(conn=sqlite3_conn, id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, bool) assert result == model.boolean_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_boolean_none", depends=["Sqlite3TestMsgspecFunctions::get_boolean"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_boolean_none", depends=["Sqlite3TestMsgspecFunctions::get_boolean"]) def test_get_boolean_none( self, sqlite3_conn: sqlite3.Connection, @@ -369,24 +339,20 @@ def test_get_boolean_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_decimal", depends=["Sqlite3TestMsgspecFunctions::get_boolean_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_decimal", depends=["Sqlite3TestMsgspecFunctions::get_boolean_none"]) def test_get_decimal( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_decimal(conn=sqlite3_conn, id_=model.id, decimal_test=model.decimal_test) + result = queries.get_one_decimal(conn=sqlite3_conn, id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, decimal.Decimal) assert result == model.decimal_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_decimal_none", depends=["Sqlite3TestMsgspecFunctions::get_decimal"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_decimal_none", depends=["Sqlite3TestMsgspecFunctions::get_decimal"]) def test_get_decimal_none( self, sqlite3_conn: sqlite3.Connection, @@ -395,24 +361,20 @@ def test_get_decimal_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_blob", depends=["Sqlite3TestMsgspecFunctions::get_decimal_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_blob", depends=["Sqlite3TestMsgspecFunctions::get_decimal_none"]) def test_get_blob( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.get_one_blob(conn=sqlite3_conn, id_=model.id, blob_test=model.blob_test) + result = queries.get_one_blob(conn=sqlite3_conn, id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_blob_none", depends=["Sqlite3TestMsgspecFunctions::get_blob"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_blob_none", depends=["Sqlite3TestMsgspecFunctions::get_blob"]) def test_get_blob_none( self, sqlite3_conn: sqlite3.Connection, @@ -421,11 +383,9 @@ def test_get_blob_none( assert result is None - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_many", depends=["Sqlite3TestMsgspecFunctions::get_blob_none"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_many", depends=["Sqlite3TestMsgspecFunctions::get_blob_none"]) def test_get_many(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id) + result = queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id_) assert result is not None assert isinstance(result, queries.QueryResults) @@ -438,19 +398,15 @@ def test_get_many(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqli assert results[0] == model - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_many_iter", depends=["Sqlite3TestMsgspecFunctions::get_many"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_many_iter", depends=["Sqlite3TestMsgspecFunctions::get_many"]) def test_get_many_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id): + for result in queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id_): assert result is not None assert isinstance(result, models.TestSqliteType) assert result == model - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_many_inner", depends=["Sqlite3TestMsgspecFunctions::get_many_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_many_inner", depends=["Sqlite3TestMsgspecFunctions::get_many_iter"]) def test_get_many_inner(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: result = queries.get_many_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id) @@ -461,12 +417,8 @@ def test_get_many_inner(self, sqlite3_conn: sqlite3.Connection, inner_model: mod assert results[0] == inner_model - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_many_inner_iter", depends=["Sqlite3TestMsgspecFunctions::get_many_inner"] - ) - def test_get_many_inner_iter( - self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_many_inner_iter", depends=["Sqlite3TestMsgspecFunctions::get_many_inner"]) + def test_get_many_inner_iter(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: for result in queries.get_many_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -478,12 +430,8 @@ def test_get_many_inner_iter( name="Sqlite3TestMsgspecFunctions::get_many_nullable_inner", depends=["Sqlite3TestMsgspecFunctions::get_many_inner_iter"], ) - async def test_get_many_nullable_inner( - self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType - ) -> None: - result = queries.get_many_nullable_inner_sqlite_type( - conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test - ) + async def test_get_many_nullable_inner(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: + result = queries.get_many_nullable_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -497,12 +445,8 @@ async def test_get_many_nullable_inner( name="Sqlite3TestMsgspecFunctions::get_many_nullable_inner_iter", depends=["Sqlite3TestMsgspecFunctions::get_many_nullable_inner"], ) - async def test_get_many_nullable_inner_iter( - self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType - ) -> None: - for result in queries.get_many_nullable_inner_sqlite_type( - conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test - ): + async def test_get_many_nullable_inner_iter(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: + for result in queries.get_many_nullable_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test): assert result is not None assert isinstance(result, models.TestInnerSqliteType) @@ -513,7 +457,7 @@ async def test_get_many_nullable_inner_iter( depends=["Sqlite3TestMsgspecFunctions::get_many_nullable_inner_iter"], ) def test_get_many_date(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_date(conn=sqlite3_conn, id_=model.id, date_test=model.date_test) + result = queries.get_many_date(conn=sqlite3_conn, id_=model.id_, date_test=model.date_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -522,11 +466,9 @@ def test_get_many_date(self, sqlite3_conn: sqlite3.Connection, model: models.Tes assert results[0] == model.date_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_many_date_iter", depends=["Sqlite3TestMsgspecFunctions::get_many_date"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_many_date_iter", depends=["Sqlite3TestMsgspecFunctions::get_many_date"]) def test_get_many_date_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_date(conn=sqlite3_conn, id_=model.id, date_test=model.date_test): + for result in queries.get_many_date(conn=sqlite3_conn, id_=model.id_, date_test=model.date_test): assert result is not None assert isinstance(result, datetime.date) @@ -537,7 +479,7 @@ def test_get_many_date_iter(self, sqlite3_conn: sqlite3.Connection, model: model depends=["Sqlite3TestMsgspecFunctions::get_many_date_iter"], ) def test_get_many_datetime(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_datetime(conn=sqlite3_conn, id_=model.id, datetime_test=model.datetime_test) + result = queries.get_many_datetime(conn=sqlite3_conn, id_=model.id_, datetime_test=model.datetime_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -551,7 +493,7 @@ def test_get_many_datetime(self, sqlite3_conn: sqlite3.Connection, model: models depends=["Sqlite3TestMsgspecFunctions::get_many_datetime"], ) def test_get_many_datetime_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_datetime(conn=sqlite3_conn, id_=model.id, datetime_test=model.datetime_test): + for result in queries.get_many_datetime(conn=sqlite3_conn, id_=model.id_, datetime_test=model.datetime_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -562,7 +504,7 @@ def test_get_many_datetime_iter(self, sqlite3_conn: sqlite3.Connection, model: m depends=["Sqlite3TestMsgspecFunctions::get_many_datetime_iter"], ) def test_get_many_timestamp(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id, timestamp_test=model.timestamp_test) + result = queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id_, timestamp_test=model.timestamp_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -576,7 +518,7 @@ def test_get_many_timestamp(self, sqlite3_conn: sqlite3.Connection, model: model depends=["Sqlite3TestMsgspecFunctions::get_many_timestamp"], ) def test_get_many_timestamp_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id, timestamp_test=model.timestamp_test): + for result in queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id_, timestamp_test=model.timestamp_test): assert result is not None assert isinstance(result, datetime.datetime) @@ -587,7 +529,7 @@ def test_get_many_timestamp_iter(self, sqlite3_conn: sqlite3.Connection, model: depends=["Sqlite3TestMsgspecFunctions::get_many_timestamp_iter"], ) def test_get_many_bool(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_bool(conn=sqlite3_conn, id_=model.id, bool_test=model.bool_test) + result = queries.get_many_bool(conn=sqlite3_conn, id_=model.id_, bool_test=model.bool_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -596,11 +538,9 @@ def test_get_many_bool(self, sqlite3_conn: sqlite3.Connection, model: models.Tes assert results[0] == model.bool_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_many_bool_iter", depends=["Sqlite3TestMsgspecFunctions::get_many_bool"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_many_bool_iter", depends=["Sqlite3TestMsgspecFunctions::get_many_bool"]) def test_get_many_bool_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_bool(conn=sqlite3_conn, id_=model.id, bool_test=model.bool_test): + for result in queries.get_many_bool(conn=sqlite3_conn, id_=model.id_, bool_test=model.bool_test): assert result is not None assert isinstance(result, bool) @@ -611,7 +551,7 @@ def test_get_many_bool_iter(self, sqlite3_conn: sqlite3.Connection, model: model depends=["Sqlite3TestMsgspecFunctions::get_many_bool_iter"], ) def test_get_many_boolean(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_boolean(conn=sqlite3_conn, id_=model.id, boolean_test=model.boolean_test) + result = queries.get_many_boolean(conn=sqlite3_conn, id_=model.id_, boolean_test=model.boolean_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -625,7 +565,7 @@ def test_get_many_boolean(self, sqlite3_conn: sqlite3.Connection, model: models. depends=["Sqlite3TestMsgspecFunctions::get_many_boolean"], ) def test_get_many_boolean_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_boolean(conn=sqlite3_conn, id_=model.id, boolean_test=model.boolean_test): + for result in queries.get_many_boolean(conn=sqlite3_conn, id_=model.id_, boolean_test=model.boolean_test): assert result is not None assert isinstance(result, bool) @@ -636,7 +576,7 @@ def test_get_many_boolean_iter(self, sqlite3_conn: sqlite3.Connection, model: mo depends=["Sqlite3TestMsgspecFunctions::get_many_boolean_iter"], ) def test_get_many_decimal(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_decimal(conn=sqlite3_conn, id_=model.id, decimal_test=model.decimal_test) + result = queries.get_many_decimal(conn=sqlite3_conn, id_=model.id_, decimal_test=model.decimal_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -650,7 +590,7 @@ def test_get_many_decimal(self, sqlite3_conn: sqlite3.Connection, model: models. depends=["Sqlite3TestMsgspecFunctions::get_many_decimal"], ) def test_get_many_decimal_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_decimal(conn=sqlite3_conn, id_=model.id, decimal_test=model.decimal_test): + for result in queries.get_many_decimal(conn=sqlite3_conn, id_=model.id_, decimal_test=model.decimal_test): assert result is not None assert isinstance(result, decimal.Decimal) @@ -661,7 +601,7 @@ def test_get_many_decimal_iter(self, sqlite3_conn: sqlite3.Connection, model: mo depends=["Sqlite3TestMsgspecFunctions::get_many_decimal_iter"], ) def test_get_many_blob(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - result = queries.get_many_blob(conn=sqlite3_conn, id_=model.id, blob_test=model.blob_test) + result = queries.get_many_blob(conn=sqlite3_conn, id_=model.id_, blob_test=model.blob_test) assert result is not None assert isinstance(result, queries.QueryResults) @@ -670,19 +610,15 @@ def test_get_many_blob(self, sqlite3_conn: sqlite3.Connection, model: models.Tes assert results[0] == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::get_many_blob_iter", depends=["Sqlite3TestMsgspecFunctions::get_many_blob"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::get_many_blob_iter", depends=["Sqlite3TestMsgspecFunctions::get_many_blob"]) def test_get_many_blob_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - for result in queries.get_many_blob(conn=sqlite3_conn, id_=model.id, blob_test=model.blob_test): + for result in queries.get_many_blob(conn=sqlite3_conn, id_=model.id_, blob_test=model.blob_test): assert result is not None assert isinstance(result, memoryview) assert result == model.blob_test - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::insert_result", depends=["Sqlite3TestMsgspecFunctions::get_many_blob_iter"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::insert_result", depends=["Sqlite3TestMsgspecFunctions::get_many_blob_iter"]) def test_insert_result( self, sqlite3_conn: sqlite3.Connection, @@ -690,7 +626,7 @@ def test_insert_result( ) -> None: result = queries.insert_result_one_sqlite_type( conn=sqlite3_conn, - id_=model.id + 1, + id_=model.id_ + 1, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -722,31 +658,25 @@ def test_insert_result( ) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::update_result", depends=["Sqlite3TestMsgspecFunctions::insert_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::update_result", depends=["Sqlite3TestMsgspecFunctions::insert_result"]) def test_update_result( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.update_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 1) + result = queries.update_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 1) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::delete_result", depends=["Sqlite3TestMsgspecFunctions::update_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::delete_result", depends=["Sqlite3TestMsgspecFunctions::update_result"]) def test_delete_result( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.delete_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 1) + result = queries.delete_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 1) assert isinstance(result, sqlite3.Cursor) - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::insert_rows", depends=["Sqlite3TestMsgspecFunctions::delete_result"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::insert_rows", depends=["Sqlite3TestMsgspecFunctions::delete_result"]) def test_insert_rows( self, sqlite3_conn: sqlite3.Connection, @@ -754,7 +684,7 @@ def test_insert_rows( ) -> None: result = queries.insert_rows_one_sqlite_type( conn=sqlite3_conn, - id_=model.id + 2, + id_=model.id_ + 2, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -787,33 +717,27 @@ def test_insert_rows( assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::update_rows", depends=["Sqlite3TestMsgspecFunctions::insert_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::update_rows", depends=["Sqlite3TestMsgspecFunctions::insert_rows"]) def test_update_rows( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.update_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 2) + result = queries.update_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::delete_rows", depends=["Sqlite3TestMsgspecFunctions::update_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::delete_rows", depends=["Sqlite3TestMsgspecFunctions::update_rows"]) def test_delete_rows( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.delete_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 2) + result = queries.delete_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 2) assert isinstance(result, int) assert result == 1 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::create_table_rows", depends=["Sqlite3TestMsgspecFunctions::delete_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::create_table_rows", depends=["Sqlite3TestMsgspecFunctions::delete_rows"]) def test_create_table_rows( self, sqlite3_conn: sqlite3.Connection, @@ -824,9 +748,7 @@ def test_create_table_rows( sqlite3_conn.commit() assert result == -1 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::insert_last_id", depends=["Sqlite3TestMsgspecFunctions::create_table_rows"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::insert_last_id", depends=["Sqlite3TestMsgspecFunctions::create_table_rows"]) def test_insert_last_id( self, sqlite3_conn: sqlite3.Connection, @@ -834,7 +756,7 @@ def test_insert_last_id( ) -> None: result = queries.insert_last_id_one_sqlite_type( conn=sqlite3_conn, - id_=model.id + 3, + id_=model.id_ + 3, int_test=model.int_test, bigint_test=model.bigint_test, smallint_test=model.smallint_test, @@ -865,63 +787,51 @@ def test_insert_last_id( json_test=model.json_test, ) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::update_last_id", depends=["Sqlite3TestMsgspecFunctions::insert_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::update_last_id", depends=["Sqlite3TestMsgspecFunctions::insert_last_id"]) def test_update_last_id( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.update_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 3) + result = queries.update_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::delete_last_id", depends=["Sqlite3TestMsgspecFunctions::update_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::delete_last_id", depends=["Sqlite3TestMsgspecFunctions::update_last_id"]) def test_delete_last_id( self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType, ) -> None: - result = queries.delete_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id + 3) + result = queries.delete_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 3) assert isinstance(result, int) - assert result == model.id + 3 + assert result == model.id_ + 3 - @pytest.mark.dependency( - name="Sqlite3TestMsgspecFunctions::delete_sqlite_type", depends=["Sqlite3TestMsgspecFunctions::delete_last_id"] - ) + @pytest.mark.dependency(name="Sqlite3TestMsgspecFunctions::delete_sqlite_type", depends=["Sqlite3TestMsgspecFunctions::delete_last_id"]) def test_delete_sqlite_type(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: - queries.delete_one_sqlite_type(conn=sqlite3_conn, id_=model.id) + queries.delete_one_sqlite_type(conn=sqlite3_conn, id_=model.id_) @pytest.mark.dependency( name="Sqlite3TestMsgspecFunctions::delete_inner_sqlite_type", depends=["Sqlite3TestMsgspecFunctions::delete_sqlite_type"], ) - def test_delete_inner_sqlite_type( - self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType - ) -> None: + def test_delete_inner_sqlite_type(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: queries.delete_one_test_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id) @pytest.mark.dependency( name="Sqlite3TestMsgspecFunctions::insert_type_override", ) - def test_insert_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - queries.insert_type_override(conn=sqlite3_conn, id_=override_model.id, text_test=override_model.text_test) + def test_insert_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + queries.insert_type_override(conn=sqlite3_conn, id_=override_model.id_, text_test=override_model.text_test) @pytest.mark.dependency( name="Sqlite3TestMsgspecFunctions::get_one_type_override", depends=["Sqlite3TestMsgspecFunctions::insert_type_override"], ) - def test_get_one_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_get_one_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id_) assert result is not None assert result == override_model @@ -929,20 +839,16 @@ def test_get_one_type_override( name="Sqlite3TestMsgspecFunctions::get_one_type_override_none", depends=["Sqlite3TestMsgspecFunctions::get_one_type_override"], ) - def test_get_one_type_override_none( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id - 1) + def test_get_one_type_override_none(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.dependency( name="Sqlite3TestMsgspecFunctions::get_many_type_override", depends=["Sqlite3TestMsgspecFunctions::get_one_type_override_none"], ) - def test_get_many_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_many_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_get_many_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_many_type_override(conn=sqlite3_conn, id_=override_model.id_) assert result is not None assert isinstance(result, queries.QueryResults) results = list(result) @@ -959,10 +865,8 @@ def test_get_many_type_override( name="Sqlite3TestMsgspecFunctions::get_one_text_type_override", depends=["Sqlite3TestMsgspecFunctions::get_many_type_override"], ) - def test_get_one_text_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_get_one_text_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id_) assert result is not None assert result == override_model.text_test @@ -970,20 +874,16 @@ def test_get_one_text_type_override( name="Sqlite3TestMsgspecFunctions::get_one_text_type_override_none", depends=["Sqlite3TestMsgspecFunctions::get_one_text_type_override"], ) - def test_get_one_text_type_override_none( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id - 1) + def test_get_one_text_type_override_none(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id_ - 1) assert result is None @pytest.mark.dependency( name="Sqlite3TestMsgspecFunctions::get_many_text_type_override", depends=["Sqlite3TestMsgspecFunctions::get_one_text_type_override_none"], ) - def test_get_many_text_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - result = queries.get_many_text_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_get_many_text_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_many_text_type_override(conn=sqlite3_conn, id_=override_model.id_) assert result is not None assert isinstance(result, queries.QueryResults) results = list(result) @@ -1000,7 +900,5 @@ def test_get_many_text_type_override( name="Sqlite3TestMsgspecFunctions::delete_type_override", depends=["Sqlite3TestMsgspecFunctions::get_many_text_type_override"], ) - def test_delete_type_override( - self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride - ) -> None: - queries.delete_type_override(conn=sqlite3_conn, id_=override_model.id) + def test_delete_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + queries.delete_type_override(conn=sqlite3_conn, id_=override_model.id_) diff --git a/test/driver_sqlite3/pydantic/__init__.py b/test/driver_sqlite3/pydantic/__init__.py new file mode 100644 index 00000000..cda025d6 --- /dev/null +++ b/test/driver_sqlite3/pydantic/__init__.py @@ -0,0 +1,20 @@ +# Copyright (c) 2025 Rayakame + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +"""Package to allow importing for sqlite3 tests.""" diff --git a/test/driver_sqlite3/pydantic/classes/__init__.py b/test/driver_sqlite3/pydantic/classes/__init__.py new file mode 100644 index 00000000..5c9110dc --- /dev/null +++ b/test/driver_sqlite3/pydantic/classes/__init__.py @@ -0,0 +1,5 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_sqlite3/pydantic/classes/models.py b/test/driver_sqlite3/pydantic/classes/models.py new file mode 100644 index 00000000..846ac2c1 --- /dev/null +++ b/test/driver_sqlite3/pydantic/classes/models.py @@ -0,0 +1,172 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing models.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "TestInnerSqliteType", + "TestSqliteType", + "TestTypeOverride", +) + +from collections import UserString +import datetime +import decimal +import pydantic +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +class TestInnerSqliteType(pydantic.BaseModel): + """Model representing TestInnerSqliteType. + + Attributes: + table_id: int + int_test: int | None + bigint_test: int | None + smallint_test: int | None + tinyint_test: int | None + int2_test: int | None + int8_test: int | None + bigserial_test: int | None + blob_test: memoryview | None + real_test: float | None + double_test: float | None + double_precision_test: float | None + float_test: float | None + numeric_test: float | None + decimal_test: decimal.Decimal | None + boolean_test: bool | None + bool_test: bool | None + date_test: datetime.date | None + datetime_test: datetime.datetime | None + timestamp_test: datetime.datetime | None + character_test: str | None + varchar_test: str | None + varyingcharacter_test: str | None + nchar_test: str | None + nativecharacter_test: str | None + nvarchar_test: str | None + text_test: str | None + clob_test: str | None + json_test: str | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + table_id: int + int_test: int | None + bigint_test: int | None + smallint_test: int | None + tinyint_test: int | None + int2_test: int | None + int8_test: int | None + bigserial_test: int | None + blob_test: memoryview | None + real_test: float | None + double_test: float | None + double_precision_test: float | None + float_test: float | None + numeric_test: float | None + decimal_test: decimal.Decimal | None + boolean_test: bool | None + bool_test: bool | None + date_test: datetime.date | None + datetime_test: datetime.datetime | None + timestamp_test: datetime.datetime | None + character_test: str | None + varchar_test: str | None + varyingcharacter_test: str | None + nchar_test: str | None + nativecharacter_test: str | None + nvarchar_test: str | None + text_test: str | None + clob_test: str | None + json_test: str | None + + +class TestSqliteType(pydantic.BaseModel): + """Model representing TestSqliteType. + + Attributes: + id_: int + int_test: int + bigint_test: int + smallint_test: int + tinyint_test: int + int2_test: int + int8_test: int + bigserial_test: int + blob_test: memoryview + real_test: float + double_test: float + double_precision_test: float + float_test: float + numeric_test: float + decimal_test: decimal.Decimal + boolean_test: bool + bool_test: bool + date_test: datetime.date + datetime_test: datetime.datetime + timestamp_test: datetime.datetime + character_test: str + varchar_test: str + varyingcharacter_test: str + nchar_test: str + nativecharacter_test: str + nvarchar_test: str + text_test: str + clob_test: str + json_test: str + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + int_test: int + bigint_test: int + smallint_test: int + tinyint_test: int + int2_test: int + int8_test: int + bigserial_test: int + blob_test: memoryview + real_test: float + double_test: float + double_precision_test: float + float_test: float + numeric_test: float + decimal_test: decimal.Decimal + boolean_test: bool + bool_test: bool + date_test: datetime.date + datetime_test: datetime.datetime + timestamp_test: datetime.datetime + character_test: str + varchar_test: str + varyingcharacter_test: str + nchar_test: str + nativecharacter_test: str + nvarchar_test: str + text_test: str + clob_test: str + json_test: str + + +class TestTypeOverride(pydantic.BaseModel): + """Model representing TestTypeOverride. + + Attributes: + id_: int + text_test: UserString | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + text_test: UserString | None diff --git a/test/driver_sqlite3/pydantic/classes/queries.py b/test/driver_sqlite3/pydantic/classes/queries.py new file mode 100644 index 00000000..6085846f --- /dev/null +++ b/test/driver_sqlite3/pydantic/classes/queries.py @@ -0,0 +1,1728 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql +"""Module containing queries from file queries.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "Queries", + "QueryResults", +) + +from collections import UserString +import datetime +import decimal +import operator +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None + +from test.driver_sqlite3.pydantic.classes import models + + +def _adapt_date(val: datetime.date) -> str: + return val.isoformat() + + +def _convert_date(val: bytes) -> datetime.date: + return datetime.date.fromisoformat(val.decode()) + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _convert_decimal(val: bytes) -> decimal.Decimal: + return decimal.Decimal(val.decode()) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +def _adapt_bool(val: bool) -> int: + return int(val) + + +def _convert_bool(val: bytes) -> bool: + return bool(int(val)) + + +def _adapt_memoryview(val: memoryview) -> bytes: + return val.tobytes() + + +def _convert_memoryview(val: bytes) -> memoryview: + return memoryview(val) + + +sqlite3.register_adapter(datetime.date, _adapt_date) +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) +sqlite3.register_adapter(bool, _adapt_bool) +sqlite3.register_adapter(memoryview, _adapt_memoryview) + +sqlite3.register_converter("date", _convert_date) +sqlite3.register_converter("decimal", _convert_decimal) +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) +sqlite3.register_converter("bool", _convert_bool) +sqlite3.register_converter("boolean", _convert_bool) +sqlite3.register_converter("blob", _convert_memoryview) + + +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +""" + +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? +""" + +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +""" + +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +""" + +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +""" + +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? +""" + +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? +""" + +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +""" + +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +""" + +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +""" + +GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? +""" + +GET_MANY_NULLABLE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyNullableInnerSqliteType :many +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? +""" + +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +""" + +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +""" + +GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +""" + +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? +""" + +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? +""" + +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +""" + +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +""" + +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? +""" + +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec +INSERT INTO test_type_override ( + id, text_test +) VALUES (? ,?) +""" + +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? +""" + +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? +""" + +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" + +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" + +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: sqlite3.Connection, + sql: str, + decode_hook: collections.abc.Callable[[sqlite3.Row], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Args: + conn: + The connection object of type `sqlite3.Connection` used to execute queries. + sql: + The SQL statement that will be executed when fetching/iterating. + decode_hook: + A callback that turns an `sqlite3.Row` object into `T` that will be returned. + *args: + Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: sqlite3.Cursor | None = None + self._iterator: collections.abc.Iterator[sqlite3.Row] | None = None + + def __iter__(self) -> QueryResults[T]: + """Initialize iteration support. + + Returns: + Self as an iterator. + """ + return self + + def __call__( + self, + ) -> collections.abc.Sequence[T]: + """Allow calling the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + result = self._conn.execute(self._sql, self._args).fetchall() + return [self._decode_hook(row) for row in result] + + def __next__(self) -> T: + """Yield the next item in the query result using a sqlite3 cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopIteration: When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor: sqlite3.Cursor | None = self._conn.execute(self._sql, self._args) + self._iterator = self._cursor.__iter__() + try: + record = self._iterator.__next__() + except StopIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +class Queries: + """Queries from file queries.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns: + Connection object of type `sqlite3.Connection` used to make queries. + """ + return self._conn + + def insert_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + self._conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) + + def insert_one_inner_sqlite_type( + self, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, + ) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. + + ```sql + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + table_id: int. + int_test: int | None. + bigint_test: int | None. + smallint_test: int | None. + tinyint_test: int | None. + int2_test: int | None. + int8_test: int | None. + bigserial_test: int | None. + blob_test: memoryview | None. + real_test: float | None. + double_test: float | None. + double_precision_test: float | None. + float_test: float | None. + numeric_test: float | None. + decimal_test: decimal.Decimal | None. + boolean_test: bool | None. + bool_test: bool | None. + date_test: datetime.date | None. + datetime_test: datetime.datetime | None. + timestamp_test: datetime.datetime | None. + character_test: str | None. + varchar_test: str | None. + varyingcharacter_test: str | None. + nchar_test: str | None. + nativecharacter_test: str | None. + nvarchar_test: str | None. + text_test: str | None. + clob_test: str | None. + json_test: str | None. + """ + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + self._conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) + + def get_one_sqlite_type(self, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. + + ```sql + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `models.TestSqliteType` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_SQLITE_TYPE, (id_,)).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + def get_one_inner_sqlite_type(self, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? + ``` + + Args: + table_id: int. + + Returns: + Result of type `models.TestInnerSqliteType` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,)).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + def get_one_date(self, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. + + ```sql + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + ``` + + Args: + id_: int. + date_test: datetime.date. + + Returns: + Result of type `datetime.date` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() + if row is None: + return None + return row[0] + + def get_one_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. + + ```sql + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + ``` + + Args: + id_: int. + datetime_test: datetime.datetime. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() + if row is None: + return None + return row[0] + + def get_one_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. + + ```sql + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + ``` + + Args: + id_: int. + timestamp_test: datetime.datetime. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() + if row is None: + return None + return row[0] + + def get_one_bool(self, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. + + ```sql + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? + ``` + + Args: + id_: int. + bool_test: bool. + + Returns: + Result of type `bool` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_BOOL, (id_, bool_test)).fetchone() + if row is None: + return None + return row[0] + + def get_one_boolean(self, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. + + ```sql + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? + ``` + + Args: + id_: int. + boolean_test: bool. + + Returns: + Result of type `bool` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test)).fetchone() + if row is None: + return None + return row[0] + + def get_one_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. + + ```sql + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + ``` + + Args: + id_: int. + decimal_test: decimal.Decimal. + + Returns: + Result of type `decimal.Decimal` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() + if row is None: + return None + return row[0] + + def get_one_blob(self, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. + + ```sql + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + ``` + + Args: + id_: int. + blob_test: memoryview. + + Returns: + Result of type `memoryview` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() + if row is None: + return None + return row[0] + + def get_many_sqlite_type(self, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. + + ```sql + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + + def get_many_inner_sqlite_type(self, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? + ``` + + Args: + table_id: int. + + Returns: + Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + + def get_many_nullable_inner_sqlite_type(self, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? + ``` + + Args: + table_id: int. + int_test: int | None. + + Returns: + Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(self._conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + + def get_many_date(self, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. + + ```sql + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + ``` + + Args: + id_: int. + date_test: datetime.date. + + Returns: + Helper class of type `QueryResults[datetime.date]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + + def get_many_datetime(self, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. + + ```sql + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + ``` + + Args: + id_: int. + datetime_test: datetime.datetime. + + Returns: + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) + + def get_many_timestamp(self, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. + + ```sql + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + ``` + + Args: + id_: int. + timestamp_test: datetime.datetime. + + Returns: + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) + + def get_many_bool(self, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. + + ```sql + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? + ``` + + Args: + id_: int. + bool_test: bool. + + Returns: + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + + def get_many_boolean(self, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. + + ```sql + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? + ``` + + Args: + id_: int. + boolean_test: bool. + + Returns: + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + + def get_many_decimal(self, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. + + ```sql + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + ``` + + Args: + id_: int. + decimal_test: decimal.Decimal. + + Returns: + Helper class of type `QueryResults[decimal.Decimal]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + def get_many_blob(self, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. + + ```sql + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + ``` + + Args: + id_: int. + blob_test: memoryview. + + Returns: + Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(self._conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + + def delete_one_sqlite_type(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + """ + self._conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) + + def delete_one_test_inner_sqlite_type(self, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + + ```sql + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? + ``` + + Args: + table_id: int. + """ + self._conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) + + def insert_result_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + + Returns: + The result of type `sqlite3.Cursor` returned when executing the query. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return self._conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) + + def update_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The result of type `sqlite3.Cursor` returned when executing the query. + """ + return self._conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + def delete_result_one_sqlite_type(self, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The result of type `sqlite3.Cursor` returned when executing the query. + """ + return self._conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + def insert_rows_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return self._conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args).rowcount + + def update_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return self._conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + def delete_rows_one_sqlite_type(self, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return self._conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + def create_rows_table(self) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return self._conn.execute(CREATE_ROWS_TABLE).rowcount + + def insert_last_id_one_sqlite_type( + self, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, + ) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return self._conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args).lastrowid + + def update_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + return self._conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid + + def delete_last_id_one_sqlite_type(self, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + return self._conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid + + def insert_type_override(self, *, id_: int, text_test: UserString | None) -> None: + """Execute SQL query with `name: InsertTypeOverride :exec`. + + ```sql + INSERT INTO test_type_override ( + id, text_test + ) VALUES (? ,?) + ``` + + Args: + id_: int. + text_test: UserString | None. + """ + self._conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) + + def get_one_type_override(self, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + + ```sql + SELECT id, text_test FROM test_type_override WHERE id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + def get_many_type_override(self, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. + + ```sql + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(self._conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + def get_one_text_type_override(self, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `UserString` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + def get_many_text_type_override(self, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + id_: int. + + Returns: + Helper class of type `QueryResults[UserString | None]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(self._conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + def delete_type_override(self, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Args: + id_: int. + """ + self._conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_sqlite3/pydantic/classes/queries_case.py b/test/driver_sqlite3/pydantic/classes/queries_case.py new file mode 100644 index 00000000..35ad32f2 --- /dev/null +++ b/test/driver_sqlite3/pydantic/classes/queries_case.py @@ -0,0 +1,164 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_case.sql +"""Module containing queries from file queries_case.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "GetCaseRowRow", + "QueriesCase", +) + +import datetime +import decimal +import pydantic +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _convert_decimal(val: bytes) -> decimal.Decimal: + return decimal.Decimal(val.decode()) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + +sqlite3.register_converter("decimal", _convert_decimal) +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +class GetCaseRowRow(pydantic.BaseModel): + """Model representing GetCaseRowRow. + + Attributes: + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + + +INSERT_CASE_ROW: typing.Final[str] = """-- name: InsertCaseRow :exec +INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) +""" + +GET_CASE_ROW: typing.Final[str] = """-- name: GetCaseRow :one +SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? +""" + +INSERT_RESERVED_ARG: typing.Final[str] = """-- name: InsertReservedArg :exec +INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) +""" + +GET_RESERVED_ARG: typing.Final[str] = """-- name: GetReservedArg :one +SELECT id FROM test_reserved_args WHERE conn = ? +""" + + +class QueriesCase: + """Queries from file queries_case.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns: + Connection object of type `sqlite3.Connection` used to make queries. + """ + return self._conn + + def insert_case_row(self, *, id_: int, upper_dt: datetime.datetime, prec_dec: decimal.Decimal) -> None: + """Execute SQL query with `name: InsertCaseRow :exec`. + + ```sql + INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) + ``` + + Args: + id_: int. + upper_dt: datetime.datetime. + prec_dec: decimal.Decimal. + """ + self._conn.execute(INSERT_CASE_ROW, (id_, upper_dt, prec_dec)) + + def get_case_row(self, *, id_: int) -> GetCaseRowRow | None: + """Fetch one from the db using the SQL query with `name: GetCaseRow :one`. + + ```sql + SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `GetCaseRowRow` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_CASE_ROW, (id_,)).fetchone() + if row is None: + return None + return GetCaseRowRow(upper_dt=row[0], prec_dec=row[1]) + + def insert_reserved_arg(self, *, id_: int, conn: str) -> None: + """Execute SQL query with `name: InsertReservedArg :exec`. + + ```sql + INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) + ``` + + Args: + id_: int. + conn: str. + """ + self._conn.execute(INSERT_RESERVED_ARG, (id_, conn)) + + def get_reserved_arg(self, *, conn: str) -> int | None: + """Fetch one from the db using the SQL query with `name: GetReservedArg :one`. + + ```sql + SELECT id FROM test_reserved_args WHERE conn = ? + ``` + + Args: + conn: str. + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_RESERVED_ARG, (conn,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/pydantic/classes/queries_override_adapter.py b/test/driver_sqlite3/pydantic/classes/queries_override_adapter.py new file mode 100644 index 00000000..cdbcccb6 --- /dev/null +++ b/test/driver_sqlite3/pydantic/classes/queries_override_adapter.py @@ -0,0 +1,95 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_adapter.sql +"""Module containing queries from file queries_override_adapter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("QueriesOverrideAdapter",) + +import datetime +import decimal +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + + +INSERT_OVERRIDE_CONVERSION: typing.Final[str] = """-- name: InsertOverrideConversion :exec +INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) +""" + +GET_OVERRIDE_PRICE: typing.Final[str] = """-- name: GetOverridePrice :one +SELECT price FROM test_override_conversion WHERE id = ? +""" + + +class QueriesOverrideAdapter: + """Queries from file queries_override_adapter.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns: + Connection object of type `sqlite3.Connection` used to make queries. + """ + return self._conn + + def insert_override_conversion(self, *, id_: int, price: float, happened_at: datetime.datetime) -> None: + """Execute SQL query with `name: InsertOverrideConversion :exec`. + + ```sql + INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) + ``` + + Args: + id_: int. + price: float. + happened_at: datetime.datetime. + """ + self._conn.execute(INSERT_OVERRIDE_CONVERSION, (id_, decimal.Decimal(price), happened_at)) + + def get_override_price(self, *, id_: int) -> float | None: + """Fetch one from the db using the SQL query with `name: GetOverridePrice :one`. + + ```sql + SELECT price FROM test_override_conversion WHERE id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `float` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_OVERRIDE_PRICE, (id_,)).fetchone() + if row is None: + return None + return float(row[0]) diff --git a/test/driver_sqlite3/pydantic/classes/queries_override_converter.py b/test/driver_sqlite3/pydantic/classes/queries_override_converter.py new file mode 100644 index 00000000..4e142b82 --- /dev/null +++ b/test/driver_sqlite3/pydantic/classes/queries_override_converter.py @@ -0,0 +1,72 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_converter.sql +"""Module containing queries from file queries_override_converter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("QueriesOverrideConverter",) + +import datetime +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +GET_OVERRIDE_HAPPENED_AT: typing.Final[str] = """-- name: GetOverrideHappenedAt :one +SELECT happened_at FROM test_override_conversion WHERE id = ? +""" + + +class QueriesOverrideConverter: + """Queries from file queries_override_converter.sql.""" + + __slots__ = ("_conn",) + + def __init__(self, conn: sqlite3.Connection) -> None: + """Initialize the instance using the connection. + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + """ + self._conn = conn + + @property + def conn(self) -> sqlite3.Connection: + """Connection object used to make queries. + + Returns: + Connection object of type `sqlite3.Connection` used to make queries. + """ + return self._conn + + def get_override_happened_at(self, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOverrideHappenedAt :one`. + + ```sql + SELECT happened_at FROM test_override_conversion WHERE id = ? + ``` + + Args: + id_: int. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = self._conn.execute(GET_OVERRIDE_HAPPENED_AT, (id_,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/pydantic/functions/__init__.py b/test/driver_sqlite3/pydantic/functions/__init__.py new file mode 100644 index 00000000..5c9110dc --- /dev/null +++ b/test/driver_sqlite3/pydantic/functions/__init__.py @@ -0,0 +1,5 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Package containing queries and models automatically generated using sqlc-gen-better-python.""" diff --git a/test/driver_sqlite3/pydantic/functions/models.py b/test/driver_sqlite3/pydantic/functions/models.py new file mode 100644 index 00000000..846ac2c1 --- /dev/null +++ b/test/driver_sqlite3/pydantic/functions/models.py @@ -0,0 +1,172 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +"""Module containing models.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "TestInnerSqliteType", + "TestSqliteType", + "TestTypeOverride", +) + +from collections import UserString +import datetime +import decimal +import pydantic +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +class TestInnerSqliteType(pydantic.BaseModel): + """Model representing TestInnerSqliteType. + + Attributes: + table_id: int + int_test: int | None + bigint_test: int | None + smallint_test: int | None + tinyint_test: int | None + int2_test: int | None + int8_test: int | None + bigserial_test: int | None + blob_test: memoryview | None + real_test: float | None + double_test: float | None + double_precision_test: float | None + float_test: float | None + numeric_test: float | None + decimal_test: decimal.Decimal | None + boolean_test: bool | None + bool_test: bool | None + date_test: datetime.date | None + datetime_test: datetime.datetime | None + timestamp_test: datetime.datetime | None + character_test: str | None + varchar_test: str | None + varyingcharacter_test: str | None + nchar_test: str | None + nativecharacter_test: str | None + nvarchar_test: str | None + text_test: str | None + clob_test: str | None + json_test: str | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + table_id: int + int_test: int | None + bigint_test: int | None + smallint_test: int | None + tinyint_test: int | None + int2_test: int | None + int8_test: int | None + bigserial_test: int | None + blob_test: memoryview | None + real_test: float | None + double_test: float | None + double_precision_test: float | None + float_test: float | None + numeric_test: float | None + decimal_test: decimal.Decimal | None + boolean_test: bool | None + bool_test: bool | None + date_test: datetime.date | None + datetime_test: datetime.datetime | None + timestamp_test: datetime.datetime | None + character_test: str | None + varchar_test: str | None + varyingcharacter_test: str | None + nchar_test: str | None + nativecharacter_test: str | None + nvarchar_test: str | None + text_test: str | None + clob_test: str | None + json_test: str | None + + +class TestSqliteType(pydantic.BaseModel): + """Model representing TestSqliteType. + + Attributes: + id_: int + int_test: int + bigint_test: int + smallint_test: int + tinyint_test: int + int2_test: int + int8_test: int + bigserial_test: int + blob_test: memoryview + real_test: float + double_test: float + double_precision_test: float + float_test: float + numeric_test: float + decimal_test: decimal.Decimal + boolean_test: bool + bool_test: bool + date_test: datetime.date + datetime_test: datetime.datetime + timestamp_test: datetime.datetime + character_test: str + varchar_test: str + varyingcharacter_test: str + nchar_test: str + nativecharacter_test: str + nvarchar_test: str + text_test: str + clob_test: str + json_test: str + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + int_test: int + bigint_test: int + smallint_test: int + tinyint_test: int + int2_test: int + int8_test: int + bigserial_test: int + blob_test: memoryview + real_test: float + double_test: float + double_precision_test: float + float_test: float + numeric_test: float + decimal_test: decimal.Decimal + boolean_test: bool + bool_test: bool + date_test: datetime.date + datetime_test: datetime.datetime + timestamp_test: datetime.datetime + character_test: str + varchar_test: str + varyingcharacter_test: str + nchar_test: str + nativecharacter_test: str + nvarchar_test: str + text_test: str + clob_test: str + json_test: str + + +class TestTypeOverride(pydantic.BaseModel): + """Model representing TestTypeOverride. + + Attributes: + id_: int + text_test: UserString | None + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + id_: int + text_test: UserString | None diff --git a/test/driver_sqlite3/pydantic/functions/queries.py b/test/driver_sqlite3/pydantic/functions/queries.py new file mode 100644 index 00000000..192de2fe --- /dev/null +++ b/test/driver_sqlite3/pydantic/functions/queries.py @@ -0,0 +1,1861 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries.sql +"""Module containing queries from file queries.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "QueryResults", + "create_rows_table", + "delete_last_id_one_sqlite_type", + "delete_one_sqlite_type", + "delete_one_test_inner_sqlite_type", + "delete_result_one_sqlite_type", + "delete_rows_one_sqlite_type", + "delete_type_override", + "get_many_blob", + "get_many_bool", + "get_many_boolean", + "get_many_date", + "get_many_datetime", + "get_many_decimal", + "get_many_inner_sqlite_type", + "get_many_nullable_inner_sqlite_type", + "get_many_sqlite_type", + "get_many_text_type_override", + "get_many_timestamp", + "get_many_type_override", + "get_one_blob", + "get_one_bool", + "get_one_boolean", + "get_one_date", + "get_one_datetime", + "get_one_decimal", + "get_one_inner_sqlite_type", + "get_one_sqlite_type", + "get_one_text_type_override", + "get_one_timestamp", + "get_one_type_override", + "insert_last_id_one_sqlite_type", + "insert_one_inner_sqlite_type", + "insert_one_sqlite_type", + "insert_result_one_sqlite_type", + "insert_rows_one_sqlite_type", + "insert_type_override", + "update_last_id_one_sqlite_type", + "update_result_one_sqlite_type", + "update_rows_one_sqlite_type", +) + +from collections import UserString +import datetime +import decimal +import operator +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + type QueryResultsArgsType = int | float | str | memoryview | decimal.Decimal | datetime.date | datetime.time | datetime.datetime | datetime.timedelta | collections.abc.Sequence[QueryResultsArgsType] | None + +from test.driver_sqlite3.pydantic.functions import models + + +def _adapt_date(val: datetime.date) -> str: + return val.isoformat() + + +def _convert_date(val: bytes) -> datetime.date: + return datetime.date.fromisoformat(val.decode()) + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _convert_decimal(val: bytes) -> decimal.Decimal: + return decimal.Decimal(val.decode()) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +def _adapt_bool(val: bool) -> int: + return int(val) + + +def _convert_bool(val: bytes) -> bool: + return bool(int(val)) + + +def _adapt_memoryview(val: memoryview) -> bytes: + return val.tobytes() + + +def _convert_memoryview(val: bytes) -> memoryview: + return memoryview(val) + + +sqlite3.register_adapter(datetime.date, _adapt_date) +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) +sqlite3.register_adapter(bool, _adapt_bool) +sqlite3.register_adapter(memoryview, _adapt_memoryview) + +sqlite3.register_converter("date", _convert_date) +sqlite3.register_converter("decimal", _convert_decimal) +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) +sqlite3.register_converter("bool", _convert_bool) +sqlite3.register_converter("boolean", _convert_bool) +sqlite3.register_converter("blob", _convert_memoryview) + + +INSERT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneSqliteType :exec +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +INSERT_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: InsertOneInnerSqliteType :exec +INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +GET_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneSqliteType :one +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +""" + +GET_ONE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetOneInnerSqliteType :one +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? +""" + +GET_ONE_DATE: typing.Final[str] = """-- name: GetOneDate :one +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +""" + +GET_ONE_DATETIME: typing.Final[str] = """-- name: GetOneDatetime :one +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +""" + +GET_ONE_TIMESTAMP: typing.Final[str] = """-- name: GetOneTimestamp :one +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +""" + +GET_ONE_BOOL: typing.Final[str] = """-- name: GetOneBool :one +SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? +""" + +GET_ONE_BOOLEAN: typing.Final[str] = """-- name: GetOneBoolean :one +SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? +""" + +GET_ONE_DECIMAL: typing.Final[str] = """-- name: GetOneDecimal :one +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +""" + +GET_ONE_BLOB: typing.Final[str] = """-- name: GetOneBlob :one +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +""" + +GET_MANY_SQLITE_TYPE: typing.Final[str] = """-- name: GetManySqliteType :many +SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? +""" + +GET_MANY_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyInnerSqliteType :many +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? +""" + +GET_MANY_NULLABLE_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: GetManyNullableInnerSqliteType :many +SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? +""" + +GET_MANY_DATE: typing.Final[str] = """-- name: GetManyDate :many +SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? +""" + +GET_MANY_DATETIME: typing.Final[str] = """-- name: GetManyDatetime :many +SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? +""" + +GET_MANY_TIMESTAMP: typing.Final[str] = """-- name: GetManyTimestamp :many +SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? +""" + +GET_MANY_BOOL: typing.Final[str] = """-- name: GetManyBool :many +SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? +""" + +GET_MANY_BOOLEAN: typing.Final[str] = """-- name: GetManyBoolean :many +SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? +""" + +GET_MANY_DECIMAL: typing.Final[str] = """-- name: GetManyDecimal :many +SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? +""" + +GET_MANY_BLOB: typing.Final[str] = """-- name: GetManyBlob :many +SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? +""" + +DELETE_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneSqliteType :exec +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +DELETE_ONE_TEST_INNER_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteOneTestInnerSqliteType :exec +DELETE FROM test_inner_sqlite_types +WHERE test_inner_sqlite_types.table_id = ? +""" + +INSERT_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertResultOneSqliteType :execresult +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +UPDATE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateResultOneSqliteType :execresult +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_RESULT_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteResultOneSqliteType :execresult +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +INSERT_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertRowsOneSqliteType :execrows +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +UPDATE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateRowsOneSqliteType :execrows +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_ROWS_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteRowsOneSqliteType :execrows +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +CREATE_ROWS_TABLE: typing.Final[str] = """-- name: CreateRowsTable :execrows +CREATE TABLE test_create_rows_table +( + id int PRIMARY KEY NOT NULL, + test int NOT NULL +) +""" + +INSERT_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: InsertLastIdOneSqliteType :execlastid +INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test +) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) +""" + +UPDATE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: UpdateLastIdOneSqliteType :execlastid +UPDATE test_sqlite_types +SET int_test = 187 +WHERE test_sqlite_types.id = ? +""" + +DELETE_LAST_ID_ONE_SQLITE_TYPE: typing.Final[str] = """-- name: DeleteLastIdOneSqliteType :execlastid +DELETE +FROM test_sqlite_types +WHERE test_sqlite_types.id = ? +""" + +INSERT_TYPE_OVERRIDE: typing.Final[str] = """-- name: InsertTypeOverride :exec +INSERT INTO test_type_override ( + id, text_test +) VALUES (? ,?) +""" + +GET_ONE_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTypeOverride :one +SELECT id, text_test FROM test_type_override WHERE id = ? +""" + +GET_MANY_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTypeOverride :many +SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? +""" + +GET_ONE_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetOneTextTypeOverride :one +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" + +GET_MANY_TEXT_TYPE_OVERRIDE: typing.Final[str] = """-- name: GetManyTextTypeOverride :many +SELECT text_test FROM test_type_override WHERE test_type_override.id = ? +""" + +DELETE_TYPE_OVERRIDE: typing.Final[str] = """-- name: DeleteTypeOverride :exec +DELETE +FROM test_type_override +WHERE test_type_override.id = ? +""" + + +class QueryResults[T]: + """Helper class that allows both iteration and normal fetching of data from the db.""" + + __slots__ = ("_args", "_conn", "_cursor", "_decode_hook", "_iterator", "_sql") + + def __init__( + self, + conn: sqlite3.Connection, + sql: str, + decode_hook: collections.abc.Callable[[sqlite3.Row], T], + *args: QueryResultsArgsType, + ) -> None: + """Initialize the QueryResults instance. + + Args: + conn: + The connection object of type `sqlite3.Connection` used to execute queries. + sql: + The SQL statement that will be executed when fetching/iterating. + decode_hook: + A callback that turns an `sqlite3.Row` object into `T` that will be returned. + *args: + Arguments that should be sent when executing the sql query. + """ + self._conn = conn + self._sql = sql + self._decode_hook = decode_hook + self._args = args + self._cursor: sqlite3.Cursor | None = None + self._iterator: collections.abc.Iterator[sqlite3.Row] | None = None + + def __iter__(self) -> QueryResults[T]: + """Initialize iteration support. + + Returns: + Self as an iterator. + """ + return self + + def __call__( + self, + ) -> collections.abc.Sequence[T]: + """Allow calling the object to return all rows as a fully decoded sequence. + + Returns: + A sequence of decoded objects of type `T`. + """ + result = self._conn.execute(self._sql, self._args).fetchall() + return [self._decode_hook(row) for row in result] + + def __next__(self) -> T: + """Yield the next item in the query result using a sqlite3 cursor. + + Returns: + The next decoded result of type `T`. + + Raises: + StopIteration: When no more records are available. + """ + if self._cursor is None or self._iterator is None: + self._cursor: sqlite3.Cursor | None = self._conn.execute(self._sql, self._args) + self._iterator = self._cursor.__iter__() + try: + record = self._iterator.__next__() + except StopIteration: + self._cursor = None + self._iterator = None + raise + return self._decode_hook(record) + + +def insert_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> None: + """Execute SQL query with `name: InsertOneSqliteType :exec`. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + conn.execute(INSERT_ONE_SQLITE_TYPE, sql_args) + + +def insert_one_inner_sqlite_type( + conn: sqlite3.Connection, + *, + table_id: int, + int_test: int | None, + bigint_test: int | None, + smallint_test: int | None, + tinyint_test: int | None, + int2_test: int | None, + int8_test: int | None, + bigserial_test: int | None, + blob_test: memoryview | None, + real_test: float | None, + double_test: float | None, + double_precision_test: float | None, + float_test: float | None, + numeric_test: float | None, + decimal_test: decimal.Decimal | None, + boolean_test: bool | None, + bool_test: bool | None, + date_test: datetime.date | None, + datetime_test: datetime.datetime | None, + timestamp_test: datetime.datetime | None, + character_test: str | None, + varchar_test: str | None, + varyingcharacter_test: str | None, + nchar_test: str | None, + nativecharacter_test: str | None, + nvarchar_test: str | None, + text_test: str | None, + clob_test: str | None, + json_test: str | None, +) -> None: + """Execute SQL query with `name: InsertOneInnerSqliteType :exec`. + + ```sql + INSERT INTO test_inner_sqlite_types ( + table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + table_id: int. + int_test: int | None. + bigint_test: int | None. + smallint_test: int | None. + tinyint_test: int | None. + int2_test: int | None. + int8_test: int | None. + bigserial_test: int | None. + blob_test: memoryview | None. + real_test: float | None. + double_test: float | None. + double_precision_test: float | None. + float_test: float | None. + numeric_test: float | None. + decimal_test: decimal.Decimal | None. + boolean_test: bool | None. + bool_test: bool | None. + date_test: datetime.date | None. + datetime_test: datetime.datetime | None. + timestamp_test: datetime.datetime | None. + character_test: str | None. + varchar_test: str | None. + varyingcharacter_test: str | None. + nchar_test: str | None. + nativecharacter_test: str | None. + nvarchar_test: str | None. + text_test: str | None. + clob_test: str | None. + json_test: str | None. + """ + sql_args = ( + table_id, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + conn.execute(INSERT_ONE_INNER_SQLITE_TYPE, sql_args) + + +def get_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> models.TestSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneSqliteType :one`. + + ```sql + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Result of type `models.TestSqliteType` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_SQLITE_TYPE, (id_,)).fetchone() + if row is None: + return None + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + +def get_one_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> models.TestInnerSqliteType | None: + """Fetch one from the db using the SQL query with `name: GetOneInnerSqliteType :one`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + table_id: int. + + Returns: + Result of type `models.TestInnerSqliteType` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_INNER_SQLITE_TYPE, (table_id,)).fetchone() + if row is None: + return None + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + +def get_one_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> datetime.date | None: + """Fetch one from the db using the SQL query with `name: GetOneDate :one`. + + ```sql + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + date_test: datetime.date. + + Returns: + Result of type `datetime.date` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_DATE, (id_, date_test)).fetchone() + if row is None: + return None + return row[0] + + +def get_one_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneDatetime :one`. + + ```sql + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + datetime_test: datetime.datetime. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_DATETIME, (id_, datetime_test)).fetchone() + if row is None: + return None + return row[0] + + +def get_one_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: datetime.datetime) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOneTimestamp :one`. + + ```sql + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + timestamp_test: datetime.datetime. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_TIMESTAMP, (id_, timestamp_test)).fetchone() + if row is None: + return None + return row[0] + + +def get_one_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBool :one`. + + ```sql + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + bool_test: bool. + + Returns: + Result of type `bool` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_BOOL, (id_, bool_test)).fetchone() + if row is None: + return None + return row[0] + + +def get_one_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> bool | None: + """Fetch one from the db using the SQL query with `name: GetOneBoolean :one`. + + ```sql + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + boolean_test: bool. + + Returns: + Result of type `bool` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_BOOLEAN, (id_, boolean_test)).fetchone() + if row is None: + return None + return row[0] + + +def get_one_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> decimal.Decimal | None: + """Fetch one from the db using the SQL query with `name: GetOneDecimal :one`. + + ```sql + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + decimal_test: decimal.Decimal. + + Returns: + Result of type `decimal.Decimal` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_DECIMAL, (id_, decimal_test)).fetchone() + if row is None: + return None + return row[0] + + +def get_one_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> memoryview | None: + """Fetch one from the db using the SQL query with `name: GetOneBlob :one`. + + ```sql + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + blob_test: memoryview. + + Returns: + Result of type `memoryview` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_BLOB, (id_, blob_test)).fetchone() + if row is None: + return None + return row[0] + + +def get_many_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManySqliteType :many`. + + ```sql + SELECT id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_sqlite_types WHERE id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestSqliteType: + return models.TestSqliteType( + id_=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_SQLITE_TYPE, _decode_hook, id_) + + +def get_many_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyInnerSqliteType :many`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + table_id: int. + + Returns: + Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_INNER_SQLITE_TYPE, _decode_hook, table_id) + + +def get_many_nullable_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int, int_test: int | None) -> QueryResults[models.TestInnerSqliteType]: + """Fetch many from the db using the SQL query with `name: GetManyNullableInnerSqliteType :many`. + + ```sql + SELECT table_id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, boolean_test, bool_test, date_test, datetime_test, timestamp_test, character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, nvarchar_test, text_test, clob_test, json_test FROM test_inner_sqlite_types WHERE table_id = ? AND int_test IS ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + table_id: int. + int_test: int | None. + + Returns: + Helper class of type `QueryResults[models.TestInnerSqliteType]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=row[0], + int_test=row[1], + bigint_test=row[2], + smallint_test=row[3], + tinyint_test=row[4], + int2_test=row[5], + int8_test=row[6], + bigserial_test=row[7], + blob_test=row[8], + real_test=row[9], + double_test=row[10], + double_precision_test=row[11], + float_test=row[12], + numeric_test=row[13], + decimal_test=row[14], + boolean_test=row[15], + bool_test=row[16], + date_test=row[17], + datetime_test=row[18], + timestamp_test=row[19], + character_test=row[20], + varchar_test=row[21], + varyingcharacter_test=row[22], + nchar_test=row[23], + nativecharacter_test=row[24], + nvarchar_test=row[25], + text_test=row[26], + clob_test=row[27], + json_test=row[28], + ) + + return QueryResults(conn, GET_MANY_NULLABLE_INNER_SQLITE_TYPE, _decode_hook, table_id, int_test) + + +def get_many_date(conn: sqlite3.Connection, *, id_: int, date_test: datetime.date) -> QueryResults[datetime.date]: + """Fetch many from the db using the SQL query with `name: GetManyDate :many`. + + ```sql + SELECT date_test FROM test_sqlite_types WHERE id = ? AND date_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + date_test: datetime.date. + + Returns: + Helper class of type `QueryResults[datetime.date]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_DATE, operator.itemgetter(0), id_, date_test) + + +def get_many_datetime(conn: sqlite3.Connection, *, id_: int, datetime_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyDatetime :many`. + + ```sql + SELECT datetime_test FROM test_sqlite_types WHERE id = ? AND datetime_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + datetime_test: datetime.datetime. + + Returns: + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_DATETIME, operator.itemgetter(0), id_, datetime_test) + + +def get_many_timestamp(conn: sqlite3.Connection, *, id_: int, timestamp_test: datetime.datetime) -> QueryResults[datetime.datetime]: + """Fetch many from the db using the SQL query with `name: GetManyTimestamp :many`. + + ```sql + SELECT timestamp_test FROM test_sqlite_types WHERE id = ? AND timestamp_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + timestamp_test: datetime.datetime. + + Returns: + Helper class of type `QueryResults[datetime.datetime]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_TIMESTAMP, operator.itemgetter(0), id_, timestamp_test) + + +def get_many_bool(conn: sqlite3.Connection, *, id_: int, bool_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBool :many`. + + ```sql + SELECT bool_test FROM test_sqlite_types WHERE id = ? AND bool_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + bool_test: bool. + + Returns: + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_BOOL, operator.itemgetter(0), id_, bool_test) + + +def get_many_boolean(conn: sqlite3.Connection, *, id_: int, boolean_test: bool) -> QueryResults[bool]: + """Fetch many from the db using the SQL query with `name: GetManyBoolean :many`. + + ```sql + SELECT boolean_test FROM test_sqlite_types WHERE id = ? AND boolean_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + boolean_test: bool. + + Returns: + Helper class of type `QueryResults[bool]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_BOOLEAN, operator.itemgetter(0), id_, boolean_test) + + +def get_many_decimal(conn: sqlite3.Connection, *, id_: int, decimal_test: decimal.Decimal) -> QueryResults[decimal.Decimal]: + """Fetch many from the db using the SQL query with `name: GetManyDecimal :many`. + + ```sql + SELECT decimal_test FROM test_sqlite_types WHERE id = ? AND decimal_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + decimal_test: decimal.Decimal. + + Returns: + Helper class of type `QueryResults[decimal.Decimal]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_DECIMAL, operator.itemgetter(0), id_, decimal_test) + + +def get_many_blob(conn: sqlite3.Connection, *, id_: int, blob_test: memoryview) -> QueryResults[memoryview]: + """Fetch many from the db using the SQL query with `name: GetManyBlob :many`. + + ```sql + SELECT blob_test FROM test_sqlite_types WHERE id = ? AND blob_test = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + blob_test: memoryview. + + Returns: + Helper class of type `QueryResults[memoryview]` that allows both iteration and normal fetching of data from the db. + """ + return QueryResults(conn, GET_MANY_BLOB, operator.itemgetter(0), id_, blob_test) + + +def delete_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteOneSqliteType :exec`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + """ + conn.execute(DELETE_ONE_SQLITE_TYPE, (id_,)) + + +def delete_one_test_inner_sqlite_type(conn: sqlite3.Connection, *, table_id: int) -> None: + """Execute SQL query with `name: DeleteOneTestInnerSqliteType :exec`. + + ```sql + DELETE FROM test_inner_sqlite_types + WHERE test_inner_sqlite_types.table_id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + table_id: int. + """ + conn.execute(DELETE_ONE_TEST_INNER_SQLITE_TYPE, (table_id,)) + + +def insert_result_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: InsertResultOneSqliteType :execresult`. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + + Returns: + The result of type `sqlite3.Cursor` returned when executing the query. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return conn.execute(INSERT_RESULT_ONE_SQLITE_TYPE, sql_args) + + +def update_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: UpdateResultOneSqliteType :execresult`. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + The result of type `sqlite3.Cursor` returned when executing the query. + """ + return conn.execute(UPDATE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +def delete_result_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> sqlite3.Cursor: + """Execute and return the result of SQL query with `name: DeleteResultOneSqliteType :execresult`. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + The result of type `sqlite3.Cursor` returned when executing the query. + """ + return conn.execute(DELETE_RESULT_ONE_SQLITE_TYPE, (id_,)) + + +def insert_rows_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int: + """Execute SQL query with `name: InsertRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return conn.execute(INSERT_ROWS_ONE_SQLITE_TYPE, sql_args).rowcount + + +def update_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: + """Execute SQL query with `name: UpdateRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return conn.execute(UPDATE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + +def delete_rows_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int: + """Execute SQL query with `name: DeleteRowsOneSqliteType :execrows` and return the number of affected rows. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return conn.execute(DELETE_ROWS_ONE_SQLITE_TYPE, (id_,)).rowcount + + +def create_rows_table(conn: sqlite3.Connection) -> int: + """Execute SQL query with `name: CreateRowsTable :execrows` and return the number of affected rows. + + ```sql + CREATE TABLE test_create_rows_table + ( + id int PRIMARY KEY NOT NULL, + test int NOT NULL + ) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + + Returns: + The number (`int`) of affected rows. This will be -1 for queries like `CREATE TABLE`. + """ + return conn.execute(CREATE_ROWS_TABLE).rowcount + + +def insert_last_id_one_sqlite_type( + conn: sqlite3.Connection, + *, + id_: int, + int_test: int, + bigint_test: int, + smallint_test: int, + tinyint_test: int, + int2_test: int, + int8_test: int, + bigserial_test: int, + blob_test: memoryview, + real_test: float, + double_test: float, + double_precision_test: float, + float_test: float, + numeric_test: float, + decimal_test: decimal.Decimal, + boolean_test: bool, + bool_test: bool, + date_test: datetime.date, + datetime_test: datetime.datetime, + timestamp_test: datetime.datetime, + character_test: str, + varchar_test: str, + varyingcharacter_test: str, + nchar_test: str, + nativecharacter_test: str, + nvarchar_test: str, + text_test: str, + clob_test: str, + json_test: str, +) -> int | None: + """Execute SQL query with `name: InsertLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + INSERT INTO test_sqlite_types ( + id, int_test, bigint_test, smallint_test, tinyint_test, int2_test, int8_test, bigserial_test, + blob_test, real_test, double_test, double_precision_test, float_test, numeric_test, decimal_test, + boolean_test, bool_test, date_test, datetime_test, timestamp_test, + character_test, varchar_test, varyingcharacter_test, nchar_test, nativecharacter_test, + nvarchar_test, text_test, clob_test, json_test + ) VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + int_test: int. + bigint_test: int. + smallint_test: int. + tinyint_test: int. + int2_test: int. + int8_test: int. + bigserial_test: int. + blob_test: memoryview. + real_test: float. + double_test: float. + double_precision_test: float. + float_test: float. + numeric_test: float. + decimal_test: decimal.Decimal. + boolean_test: bool. + bool_test: bool. + date_test: datetime.date. + datetime_test: datetime.datetime. + timestamp_test: datetime.datetime. + character_test: str. + varchar_test: str. + varyingcharacter_test: str. + nchar_test: str. + nativecharacter_test: str. + nvarchar_test: str. + text_test: str. + clob_test: str. + json_test: str. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + sql_args = ( + id_, + int_test, + bigint_test, + smallint_test, + tinyint_test, + int2_test, + int8_test, + bigserial_test, + blob_test, + real_test, + double_test, + double_precision_test, + float_test, + numeric_test, + decimal_test, + boolean_test, + bool_test, + date_test, + datetime_test, + timestamp_test, + character_test, + varchar_test, + varyingcharacter_test, + nchar_test, + nativecharacter_test, + nvarchar_test, + text_test, + clob_test, + json_test, + ) + return conn.execute(INSERT_LAST_ID_ONE_SQLITE_TYPE, sql_args).lastrowid + + +def update_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: UpdateLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + UPDATE test_sqlite_types + SET int_test = 187 + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + return conn.execute(UPDATE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid + + +def delete_last_id_one_sqlite_type(conn: sqlite3.Connection, *, id_: int) -> int | None: + """Execute SQL query with `name: DeleteLastIdOneSqliteType :execlastid` and return the id of the last affected row. + + ```sql + DELETE + FROM test_sqlite_types + WHERE test_sqlite_types.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + The id (`int`) of the last affected row. Will be `None` if no rows are affected. + """ + return conn.execute(DELETE_LAST_ID_ONE_SQLITE_TYPE, (id_,)).lastrowid + + +def insert_type_override(conn: sqlite3.Connection, *, id_: int, text_test: UserString | None) -> None: + """Execute SQL query with `name: InsertTypeOverride :exec`. + + ```sql + INSERT INTO test_type_override ( + id, text_test + ) VALUES (? ,?) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + text_test: UserString | None. + """ + conn.execute(INSERT_TYPE_OVERRIDE, (id_, str(text_test) if text_test is not None else None)) + + +def get_one_type_override(conn: sqlite3.Connection, *, id_: int) -> models.TestTypeOverride | None: + """Fetch one from the db using the SQL query with `name: GetOneTypeOverride :one`. + + ```sql + SELECT id, text_test FROM test_type_override WHERE id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Result of type `models.TestTypeOverride` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + +def get_many_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[models.TestTypeOverride]: + """Fetch many from the db using the SQL query with `name: GetManyTypeOverride :many`. + + ```sql + SELECT id, text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[models.TestTypeOverride]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=row[0], text_test=UserString(row[1]) if row[1] is not None else None) + + return QueryResults(conn, GET_MANY_TYPE_OVERRIDE, _decode_hook, id_) + + +def get_one_text_type_override(conn: sqlite3.Connection, *, id_: int) -> UserString | None: + """Fetch one from the db using the SQL query with `name: GetOneTextTypeOverride :one`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Result of type `UserString` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_ONE_TEXT_TYPE_OVERRIDE, (id_,)).fetchone() + if row is None: + return None + return UserString(row[0]) if row[0] is not None else None + + +def get_many_text_type_override(conn: sqlite3.Connection, *, id_: int) -> QueryResults[UserString | None]: + """Fetch many from the db using the SQL query with `name: GetManyTextTypeOverride :many`. + + ```sql + SELECT text_test FROM test_type_override WHERE test_type_override.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Helper class of type `QueryResults[UserString | None]` that allows both iteration and normal fetching of data from the db. + """ + + def _decode_hook(row: sqlite3.Row) -> UserString | None: + return UserString(row[0]) if row[0] is not None else None + + return QueryResults(conn, GET_MANY_TEXT_TYPE_OVERRIDE, _decode_hook, id_) + + +def delete_type_override(conn: sqlite3.Connection, *, id_: int) -> None: + """Execute SQL query with `name: DeleteTypeOverride :exec`. + + ```sql + DELETE + FROM test_type_override + WHERE test_type_override.id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + """ + conn.execute(DELETE_TYPE_OVERRIDE, (id_,)) diff --git a/test/driver_sqlite3/pydantic/functions/queries_case.py b/test/driver_sqlite3/pydantic/functions/queries_case.py new file mode 100644 index 00000000..dbe806cd --- /dev/null +++ b/test/driver_sqlite3/pydantic/functions/queries_case.py @@ -0,0 +1,155 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_case.sql +"""Module containing queries from file queries_case.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "GetCaseRowRow", + "get_case_row", + "get_reserved_arg", + "insert_case_row", + "insert_reserved_arg", +) + +import datetime +import decimal +import pydantic +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _convert_decimal(val: bytes) -> decimal.Decimal: + return decimal.Decimal(val.decode()) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + +sqlite3.register_converter("decimal", _convert_decimal) +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +class GetCaseRowRow(pydantic.BaseModel): + """Model representing GetCaseRowRow. + + Attributes: + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + """ + + model_config = pydantic.ConfigDict(arbitrary_types_allowed=True) + + upper_dt: datetime.datetime + prec_dec: decimal.Decimal + + +INSERT_CASE_ROW: typing.Final[str] = """-- name: InsertCaseRow :exec +INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) +""" + +GET_CASE_ROW: typing.Final[str] = """-- name: GetCaseRow :one +SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? +""" + +INSERT_RESERVED_ARG: typing.Final[str] = """-- name: InsertReservedArg :exec +INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) +""" + +GET_RESERVED_ARG: typing.Final[str] = """-- name: GetReservedArg :one +SELECT id FROM test_reserved_args WHERE conn = ? +""" + + +def insert_case_row(conn: sqlite3.Connection, *, id_: int, upper_dt: datetime.datetime, prec_dec: decimal.Decimal) -> None: + """Execute SQL query with `name: InsertCaseRow :exec`. + + ```sql + INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + upper_dt: datetime.datetime. + prec_dec: decimal.Decimal. + """ + conn.execute(INSERT_CASE_ROW, (id_, upper_dt, prec_dec)) + + +def get_case_row(conn: sqlite3.Connection, *, id_: int) -> GetCaseRowRow | None: + """Fetch one from the db using the SQL query with `name: GetCaseRow :one`. + + ```sql + SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Result of type `GetCaseRowRow` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_CASE_ROW, (id_,)).fetchone() + if row is None: + return None + return GetCaseRowRow(upper_dt=row[0], prec_dec=row[1]) + + +def insert_reserved_arg(conn: sqlite3.Connection, *, id_: int, conn_2: str) -> None: + """Execute SQL query with `name: InsertReservedArg :exec`. + + ```sql + INSERT INTO test_reserved_args (id, conn) VALUES (?, ?) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + conn_2: str. + """ + conn.execute(INSERT_RESERVED_ARG, (id_, conn_2)) + + +def get_reserved_arg(conn: sqlite3.Connection, *, conn_2: str) -> int | None: + """Fetch one from the db using the SQL query with `name: GetReservedArg :one`. + + ```sql + SELECT id FROM test_reserved_args WHERE conn = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + conn_2: str. + + Returns: + Result of type `int` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_RESERVED_ARG, (conn_2,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/pydantic/functions/queries_override_adapter.py b/test/driver_sqlite3/pydantic/functions/queries_override_adapter.py new file mode 100644 index 00000000..8e3390cc --- /dev/null +++ b/test/driver_sqlite3/pydantic/functions/queries_override_adapter.py @@ -0,0 +1,80 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_adapter.sql +"""Module containing queries from file queries_override_adapter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ( + "get_override_price", + "insert_override_conversion", +) + +import datetime +import decimal +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _adapt_decimal(val: decimal.Decimal) -> str: + return str(val) + + +def _adapt_datetime(val: datetime.datetime) -> str: + return val.isoformat() + + +sqlite3.register_adapter(decimal.Decimal, _adapt_decimal) +sqlite3.register_adapter(datetime.datetime, _adapt_datetime) + + +INSERT_OVERRIDE_CONVERSION: typing.Final[str] = """-- name: InsertOverrideConversion :exec +INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) +""" + +GET_OVERRIDE_PRICE: typing.Final[str] = """-- name: GetOverridePrice :one +SELECT price FROM test_override_conversion WHERE id = ? +""" + + +def insert_override_conversion(conn: sqlite3.Connection, *, id_: int, price: float, happened_at: datetime.datetime) -> None: + """Execute SQL query with `name: InsertOverrideConversion :exec`. + + ```sql + INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?) + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + price: float. + happened_at: datetime.datetime. + """ + conn.execute(INSERT_OVERRIDE_CONVERSION, (id_, decimal.Decimal(price), happened_at)) + + +def get_override_price(conn: sqlite3.Connection, *, id_: int) -> float | None: + """Fetch one from the db using the SQL query with `name: GetOverridePrice :one`. + + ```sql + SELECT price FROM test_override_conversion WHERE id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Result of type `float` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_OVERRIDE_PRICE, (id_,)).fetchone() + if row is None: + return None + return float(row[0]) diff --git a/test/driver_sqlite3/pydantic/functions/queries_override_converter.py b/test/driver_sqlite3/pydantic/functions/queries_override_converter.py new file mode 100644 index 00000000..42151a7d --- /dev/null +++ b/test/driver_sqlite3/pydantic/functions/queries_override_converter.py @@ -0,0 +1,51 @@ +# Code generated by sqlc. DO NOT EDIT. +# versions: +# sqlc v1.30.0 +# sqlc-gen-better-python v0.4.6 +# source file: queries_override_converter.sql +"""Module containing queries from file queries_override_converter.sql.""" + +from __future__ import annotations + +__all__: collections.abc.Sequence[str] = ("get_override_happened_at",) + +import datetime +import sqlite3 +import typing + +if typing.TYPE_CHECKING: + import collections.abc + + +def _convert_datetime(val: bytes) -> datetime.datetime: + return datetime.datetime.fromisoformat(val.decode()) + + +sqlite3.register_converter("datetime", _convert_datetime) +sqlite3.register_converter("timestamp", _convert_datetime) + + +GET_OVERRIDE_HAPPENED_AT: typing.Final[str] = """-- name: GetOverrideHappenedAt :one +SELECT happened_at FROM test_override_conversion WHERE id = ? +""" + + +def get_override_happened_at(conn: sqlite3.Connection, *, id_: int) -> datetime.datetime | None: + """Fetch one from the db using the SQL query with `name: GetOverrideHappenedAt :one`. + + ```sql + SELECT happened_at FROM test_override_conversion WHERE id = ? + ``` + + Args: + conn: + Connection object of type `sqlite3.Connection` used to execute the query. + id_: int. + + Returns: + Result of type `datetime.datetime` fetched from the db. Will be `None` if not found. + """ + row = conn.execute(GET_OVERRIDE_HAPPENED_AT, (id_,)).fetchone() + if row is None: + return None + return row[0] diff --git a/test/driver_sqlite3/pydantic/ruff.toml b/test/driver_sqlite3/pydantic/ruff.toml new file mode 100644 index 00000000..ded540a0 --- /dev/null +++ b/test/driver_sqlite3/pydantic/ruff.toml @@ -0,0 +1,9 @@ +extend="../../../ruff.toml" + + +[lint.flake8-type-checking] +runtime-evaluated-base-classes = ["pydantic.BaseModel"] + + +[lint.pydocstyle] +convention = "google" \ No newline at end of file diff --git a/test/driver_sqlite3/pydantic/test_sqlite3_pydantic_classes.py b/test/driver_sqlite3/pydantic/test_sqlite3_pydantic_classes.py new file mode 100644 index 00000000..3b5ea42a --- /dev/null +++ b/test/driver_sqlite3/pydantic/test_sqlite3_pydantic_classes.py @@ -0,0 +1,898 @@ +# Copyright (c) 2025 Rayakame + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +from __future__ import annotations + +import datetime +import decimal +import json +import math +import random +import sqlite3 +from collections import UserString + +import pytest + +from test.driver_sqlite3.pydantic.classes import models +from test.driver_sqlite3.pydantic.classes import queries + + +class TestSqlite3PydanticClasses: + @pytest.fixture(scope="session") + def override_model(self) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) + + @pytest.fixture(scope="session") + def model(self) -> models.TestSqliteType: + return models.TestSqliteType( + id_=random.randint(1, 10000000), + int_test=42, + bigint_test=9_007_199_254_740_991, + smallint_test=32_767, + tinyint_test=255, + int2_test=12_345, + int8_test=123_456_789, + bigserial_test=1, + blob_test=memoryview(b"\x00\x01\x02hello"), + real_test=math.pi, + double_test=math.e, + double_precision_test=1.41421, + float_test=9.81, + numeric_test=123.456, + decimal_test=decimal.Decimal("789.0123"), + bool_test=True, + boolean_test=False, + date_test=datetime.date(2025, 1, 1), + datetime_test=datetime.datetime(2025, 1, 1, 12), + timestamp_test=datetime.datetime.now(), + character_test="ABCDEFGHIJ", + varchar_test="Hello varchar", + varyingcharacter_test="VarChar variant", + nchar_test="ABCDEFGHIJ", + nativecharacter_test="NativeChar", + nvarchar_test="Olá mundo", + text_test="Some text", + clob_test="Some clob data", + json_test=json.dumps({"foo": "bar"}), + ) + + @pytest.fixture(scope="session") + def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=model.id_, + int_test=None, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=None, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=None, + bool_test=None, + boolean_test=None, + date_test=None, + datetime_test=None, + timestamp_test=None, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + + @pytest.fixture(scope="class") + def queries_obj(self, sqlite3_conn: sqlite3.Connection) -> queries.Queries: + return queries.Queries(conn=sqlite3_conn) + + def test_conn_attr(self, queries_obj: queries.Queries) -> None: + assert isinstance(queries_obj.conn, sqlite3.Connection) + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::insert") + def test_insert( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + queries_obj.insert_one_sqlite_type( + id_=model.id_, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::inner_insert", depends=["Sqlite3TestPydanticClasses::insert"]) + def test_inner_insert( + self, + queries_obj: queries.Queries, + inner_model: models.TestInnerSqliteType, + ) -> None: + queries_obj.insert_one_inner_sqlite_type( + table_id=inner_model.table_id, + int_test=inner_model.int_test, + bigint_test=inner_model.bigint_test, + smallint_test=inner_model.smallint_test, + tinyint_test=inner_model.tinyint_test, + int2_test=inner_model.int2_test, + int8_test=inner_model.int8_test, + bigserial_test=inner_model.bigserial_test, + blob_test=inner_model.blob_test, + real_test=inner_model.real_test, + double_test=inner_model.double_test, + double_precision_test=inner_model.double_precision_test, + float_test=inner_model.float_test, + numeric_test=inner_model.numeric_test, + decimal_test=inner_model.decimal_test, + bool_test=inner_model.bool_test, + boolean_test=inner_model.boolean_test, + date_test=inner_model.date_test, + datetime_test=inner_model.datetime_test, + timestamp_test=inner_model.timestamp_test, + character_test=inner_model.character_test, + varchar_test=inner_model.varchar_test, + varyingcharacter_test=inner_model.varyingcharacter_test, + nchar_test=inner_model.nchar_test, + nativecharacter_test=inner_model.nativecharacter_test, + nvarchar_test=inner_model.nvarchar_test, + text_test=inner_model.text_test, + clob_test=inner_model.clob_test, + json_test=inner_model.json_test, + ) + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_one", depends=["Sqlite3TestPydanticClasses::inner_insert"]) + def test_get_one( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.get_one_sqlite_type(id_=model.id_) + + assert result is not None + + assert isinstance(result, models.TestSqliteType) + + assert result == model + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_one_none", depends=["Sqlite3TestPydanticClasses::get_one"]) + def test_get_one_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = queries_obj.get_one_sqlite_type(id_=0) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_one_inner", depends=["Sqlite3TestPydanticClasses::get_one_none"]) + def test_get_one_inner( + self, + queries_obj: queries.Queries, + inner_model: models.TestInnerSqliteType, + ) -> None: + result = queries_obj.get_one_inner_sqlite_type(table_id=inner_model.table_id) + + assert result is not None + + assert isinstance(result, models.TestInnerSqliteType) + assert result == inner_model + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_one_inner_none", depends=["Sqlite3TestPydanticClasses::get_one_inner"]) + def test_get_one_inner_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = queries_obj.get_one_inner_sqlite_type(table_id=0) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_date", depends=["Sqlite3TestPydanticClasses::get_one_inner_none"]) + def test_get_date( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.get_one_date(id_=model.id_, date_test=model.date_test) + + assert result is not None + + assert isinstance(result, datetime.date) + assert result == model.date_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_date_none", depends=["Sqlite3TestPydanticClasses::get_date"]) + def test_get_date_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = queries_obj.get_one_date(id_=0, date_test=datetime.date.today()) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_datetime", depends=["Sqlite3TestPydanticClasses::get_date_none"]) + def test_get_datetime( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.get_one_datetime(id_=model.id_, datetime_test=model.datetime_test) + + assert result is not None + + assert isinstance(result, datetime.datetime) + assert result == model.datetime_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_datetime_none", depends=["Sqlite3TestPydanticClasses::get_datetime"]) + def test_get_datetime_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = queries_obj.get_one_datetime(id_=0, datetime_test=datetime.datetime.now()) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_timestamp", depends=["Sqlite3TestPydanticClasses::get_datetime_none"]) + def test_get_timestamp( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.get_one_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) + + assert result is not None + + assert isinstance(result, datetime.datetime) + assert result == model.timestamp_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_timestamp_none", depends=["Sqlite3TestPydanticClasses::get_timestamp"]) + def test_get_timestamp_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = queries_obj.get_one_timestamp(id_=0, timestamp_test=datetime.datetime.now()) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_bool", depends=["Sqlite3TestPydanticClasses::get_timestamp_none"]) + def test_get_bool( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.get_one_bool(id_=model.id_, bool_test=model.bool_test) + + assert result is not None + + assert isinstance(result, bool) + assert result == model.bool_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_bool_none", depends=["Sqlite3TestPydanticClasses::get_bool"]) + def test_get_bool_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = queries_obj.get_one_bool(id_=0, bool_test=False) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_boolean", depends=["Sqlite3TestPydanticClasses::get_bool_none"]) + def test_get_boolean( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.get_one_boolean(id_=model.id_, boolean_test=model.boolean_test) + + assert result is not None + + assert isinstance(result, bool) + assert result == model.boolean_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_boolean_none", depends=["Sqlite3TestPydanticClasses::get_boolean"]) + def test_get_boolean_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = queries_obj.get_one_boolean(id_=0, boolean_test=True) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_decimal", depends=["Sqlite3TestPydanticClasses::get_boolean_none"]) + def test_get_decimal( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.get_one_decimal(id_=model.id_, decimal_test=model.decimal_test) + + assert result is not None + + assert isinstance(result, decimal.Decimal) + assert result == model.decimal_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_decimal_none", depends=["Sqlite3TestPydanticClasses::get_decimal"]) + def test_get_decimal_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = queries_obj.get_one_decimal(id_=0, decimal_test=decimal.Decimal("0.1")) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_blob", depends=["Sqlite3TestPydanticClasses::get_decimal_none"]) + def test_get_blob( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.get_one_blob(id_=model.id_, blob_test=model.blob_test) + + assert result is not None + + assert isinstance(result, memoryview) + assert result == model.blob_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_blob_none", depends=["Sqlite3TestPydanticClasses::get_blob"]) + def test_get_blob_none( + self, + queries_obj: queries.Queries, + ) -> None: + result = queries_obj.get_one_blob(id_=0, blob_test=memoryview(b"test")) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_many", depends=["Sqlite3TestPydanticClasses::get_blob_none"]) + def test_get_many(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = queries_obj.get_many_sqlite_type(id_=model.id_) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], models.TestSqliteType) + + assert results[0] == model + + results = result() + assert isinstance(results[0], models.TestSqliteType) + + assert results[0] == model + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_many_iter", depends=["Sqlite3TestPydanticClasses::get_many"]) + def test_get_many_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + for result in queries_obj.get_many_sqlite_type(id_=model.id_): + assert result is not None + assert isinstance(result, models.TestSqliteType) + + assert result == model + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_many_inner", depends=["Sqlite3TestPydanticClasses::get_many_iter"]) + def test_get_many_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + result = queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], models.TestInnerSqliteType) + + assert results[0] == inner_model + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_many_inner_iter", depends=["Sqlite3TestPydanticClasses::get_many_inner"]) + def test_get_many_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + for result in queries_obj.get_many_inner_sqlite_type(table_id=inner_model.table_id): + assert result is not None + assert isinstance(result, models.TestInnerSqliteType) + + assert result == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_nullable_inner", + depends=["Sqlite3TestPydanticClasses::get_many_inner_iter"], + ) + async def test_get_many_nullable_inner(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + result = queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = result() + assert isinstance(results[0], models.TestInnerSqliteType) + + assert results[0] == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_nullable_inner_iter", + depends=["Sqlite3TestPydanticClasses::get_many_nullable_inner"], + ) + async def test_get_many_nullable_inner_iter(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + for result in queries_obj.get_many_nullable_inner_sqlite_type(table_id=inner_model.table_id, int_test=inner_model.int_test): + assert result is not None + assert isinstance(result, models.TestInnerSqliteType) + + assert result == inner_model + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_date", + depends=["Sqlite3TestPydanticClasses::get_many_nullable_inner_iter"], + ) + def test_get_many_date(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = queries_obj.get_many_date(id_=model.id_, date_test=model.date_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], datetime.date) + + assert results[0] == model.date_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_many_date_iter", depends=["Sqlite3TestPydanticClasses::get_many_date"]) + def test_get_many_date_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + for result in queries_obj.get_many_date(id_=model.id_, date_test=model.date_test): + assert result is not None + assert isinstance(result, datetime.date) + + assert result == model.date_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_datetime", + depends=["Sqlite3TestPydanticClasses::get_many_date_iter"], + ) + def test_get_many_datetime(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], datetime.datetime) + + assert results[0] == model.datetime_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_datetime_iter", + depends=["Sqlite3TestPydanticClasses::get_many_datetime"], + ) + def test_get_many_datetime_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + for result in queries_obj.get_many_datetime(id_=model.id_, datetime_test=model.datetime_test): + assert result is not None + assert isinstance(result, datetime.datetime) + + assert result == model.datetime_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_timestamp", + depends=["Sqlite3TestPydanticClasses::get_many_datetime_iter"], + ) + def test_get_many_timestamp(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], datetime.datetime) + + assert results[0] == model.timestamp_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_timestamp_iter", + depends=["Sqlite3TestPydanticClasses::get_many_timestamp"], + ) + def test_get_many_timestamp_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + for result in queries_obj.get_many_timestamp(id_=model.id_, timestamp_test=model.timestamp_test): + assert result is not None + assert isinstance(result, datetime.datetime) + + assert result == model.timestamp_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_bool", + depends=["Sqlite3TestPydanticClasses::get_many_timestamp_iter"], + ) + def test_get_many_bool(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], bool) + + assert results[0] == model.bool_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_many_bool_iter", depends=["Sqlite3TestPydanticClasses::get_many_bool"]) + def test_get_many_bool_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + for result in queries_obj.get_many_bool(id_=model.id_, bool_test=model.bool_test): + assert result is not None + assert isinstance(result, bool) + + assert result == model.bool_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_boolean", + depends=["Sqlite3TestPydanticClasses::get_many_bool_iter"], + ) + def test_get_many_boolean(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], bool) + + assert results[0] == model.boolean_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_boolean_iter", + depends=["Sqlite3TestPydanticClasses::get_many_boolean"], + ) + def test_get_many_boolean_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + for result in queries_obj.get_many_boolean(id_=model.id_, boolean_test=model.boolean_test): + assert result is not None + assert isinstance(result, bool) + + assert result == model.boolean_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_decimal", + depends=["Sqlite3TestPydanticClasses::get_many_boolean_iter"], + ) + def test_get_many_decimal(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], decimal.Decimal) + + assert results[0] == model.decimal_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_decimal_iter", + depends=["Sqlite3TestPydanticClasses::get_many_decimal"], + ) + def test_get_many_decimal_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + for result in queries_obj.get_many_decimal(id_=model.id_, decimal_test=model.decimal_test): + assert result is not None + assert isinstance(result, decimal.Decimal) + + assert result == model.decimal_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_blob", + depends=["Sqlite3TestPydanticClasses::get_many_decimal_iter"], + ) + def test_get_many_blob(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + result = queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], memoryview) + + assert results[0] == model.blob_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::get_many_blob_iter", depends=["Sqlite3TestPydanticClasses::get_many_blob"]) + def test_get_many_blob_iter(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + for result in queries_obj.get_many_blob(id_=model.id_, blob_test=model.blob_test): + assert result is not None + assert isinstance(result, memoryview) + + assert result == model.blob_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::insert_result", depends=["Sqlite3TestPydanticClasses::get_many_blob_iter"]) + def test_insert_result( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.insert_result_one_sqlite_type( + id_=model.id_ + 1, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + assert isinstance(result, sqlite3.Cursor) + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::update_result", depends=["Sqlite3TestPydanticClasses::insert_result"]) + def test_update_result( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.update_result_one_sqlite_type(id_=model.id_ + 1) + assert isinstance(result, sqlite3.Cursor) + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::delete_result", depends=["Sqlite3TestPydanticClasses::update_result"]) + def test_delete_result( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.delete_result_one_sqlite_type(id_=model.id_ + 1) + assert isinstance(result, sqlite3.Cursor) + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::insert_rows", depends=["Sqlite3TestPydanticClasses::delete_result"]) + def test_insert_rows( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.insert_rows_one_sqlite_type( + id_=model.id_ + 2, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + assert isinstance(result, int) + assert result == 1 + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::update_rows", depends=["Sqlite3TestPydanticClasses::insert_rows"]) + def test_update_rows( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.update_rows_one_sqlite_type(id_=model.id_ + 2) + assert isinstance(result, int) + assert result == 1 + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::delete_rows", depends=["Sqlite3TestPydanticClasses::update_rows"]) + def test_delete_rows( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.delete_rows_one_sqlite_type(id_=model.id_ + 2) + assert isinstance(result, int) + assert result == 1 + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::create_table_rows", depends=["Sqlite3TestPydanticClasses::delete_rows"]) + def test_create_table_rows( + self, + queries_obj: queries.Queries, + sqlite3_conn: sqlite3.Connection, + ) -> None: + result = queries_obj.create_rows_table() + assert isinstance(result, int) + sqlite3_conn.execute("DROP TABLE test_create_rows_table;") + sqlite3_conn.commit() + assert result == -1 + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::insert_last_id", depends=["Sqlite3TestPydanticClasses::create_table_rows"]) + def test_insert_last_id( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.insert_last_id_one_sqlite_type( + id_=model.id_ + 3, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + assert isinstance(result, int) + assert result == model.id_ + 3 + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::update_last_id", depends=["Sqlite3TestPydanticClasses::insert_last_id"]) + def test_update_last_id( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.update_last_id_one_sqlite_type(id_=model.id_ + 3) + assert isinstance(result, int) + assert result == model.id_ + 3 + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::delete_last_id", depends=["Sqlite3TestPydanticClasses::update_last_id"]) + def test_delete_last_id( + self, + queries_obj: queries.Queries, + model: models.TestSqliteType, + ) -> None: + result = queries_obj.delete_last_id_one_sqlite_type(id_=model.id_ + 3) + assert isinstance(result, int) + assert result == model.id_ + 3 + + @pytest.mark.dependency(name="Sqlite3TestPydanticClasses::delete_sqlite_type", depends=["Sqlite3TestPydanticClasses::delete_last_id"]) + def test_delete_sqlite_type(self, queries_obj: queries.Queries, model: models.TestSqliteType) -> None: + queries_obj.delete_one_sqlite_type(id_=model.id_) + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::delete_inner_sqlite_type", + depends=["Sqlite3TestPydanticClasses::delete_sqlite_type"], + ) + def test_delete_inner_sqlite_type(self, queries_obj: queries.Queries, inner_model: models.TestInnerSqliteType) -> None: + queries_obj.delete_one_test_inner_sqlite_type(table_id=inner_model.table_id) + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::insert_type_override", + ) + def test_insert_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + queries_obj.insert_type_override(id_=override_model.id_, text_test=override_model.text_test) + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_one_type_override", + depends=["Sqlite3TestPydanticClasses::insert_type_override"], + ) + def test_get_one_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_type_override(id_=override_model.id_) + assert result is not None + assert result == override_model + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_one_type_override_none", + depends=["Sqlite3TestPydanticClasses::get_one_type_override"], + ) + def test_get_one_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_type_override(id_=override_model.id_ - 1) + assert result is None + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_type_override", + depends=["Sqlite3TestPydanticClasses::get_one_type_override_none"], + ) + def test_get_many_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_many_type_override(id_=override_model.id_) + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], models.TestTypeOverride) + + assert results[0] == override_model + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_one_text_type_override", + depends=["Sqlite3TestPydanticClasses::get_many_type_override"], + ) + def test_get_one_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_text_type_override(id_=override_model.id_) + assert result is not None + assert result == override_model.text_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_one_text_type_override_none", + depends=["Sqlite3TestPydanticClasses::get_one_text_type_override"], + ) + def test_get_one_text_type_override_none(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_one_text_type_override(id_=override_model.id_ - 1) + assert result is None + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::get_many_text_type_override", + depends=["Sqlite3TestPydanticClasses::get_one_text_type_override_none"], + ) + def test_get_many_text_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + result = queries_obj.get_many_text_type_override(id_=override_model.id_) + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], UserString) + + assert results[0] == override_model.text_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticClasses::delete_type_override", + depends=["Sqlite3TestPydanticClasses::get_many_text_type_override"], + ) + def test_delete_type_override(self, queries_obj: queries.Queries, override_model: models.TestTypeOverride) -> None: + queries_obj.delete_type_override(id_=override_model.id_) diff --git a/test/driver_sqlite3/pydantic/test_sqlite3_pydantic_functions.py b/test/driver_sqlite3/pydantic/test_sqlite3_pydantic_functions.py new file mode 100644 index 00000000..74f7371d --- /dev/null +++ b/test/driver_sqlite3/pydantic/test_sqlite3_pydantic_functions.py @@ -0,0 +1,934 @@ +# Copyright (c) 2025 Rayakame + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +from __future__ import annotations + +import datetime +import decimal +import json +import math +import random +import sqlite3 +from collections import UserString + +import pytest + +from test.driver_sqlite3.pydantic.functions import models +from test.driver_sqlite3.pydantic.functions import queries + + +class TestSqlite3PydanticFunctions: + @pytest.fixture(scope="session") + def override_model(self) -> models.TestTypeOverride: + return models.TestTypeOverride(id_=random.randint(1, 10000000), text_test=UserString("Test")) + + @pytest.fixture(scope="session") + def model(self) -> models.TestSqliteType: + return models.TestSqliteType( + id_=random.randint(1, 10000000), + int_test=42, + bigint_test=9_007_199_254_740_991, + smallint_test=32_767, + tinyint_test=255, + int2_test=12_345, + int8_test=123_456_789, + bigserial_test=1, + blob_test=memoryview(b"\x00\x01\x02hello"), + real_test=math.pi, + double_test=math.e, + double_precision_test=1.41421, + float_test=9.81, + numeric_test=123.456, + decimal_test=decimal.Decimal("789.0123"), + bool_test=True, + boolean_test=False, + date_test=datetime.date(2025, 1, 1), + datetime_test=datetime.datetime(2025, 1, 1, 12), + timestamp_test=datetime.datetime.now(), + character_test="ABCDEFGHIJ", + varchar_test="Hello varchar", + varyingcharacter_test="VarChar variant", + nchar_test="ABCDEFGHIJ", + nativecharacter_test="NativeChar", + nvarchar_test="Olá mundo", + text_test="Some text", + clob_test="Some clob data", + json_test=json.dumps({"foo": "bar"}), + ) + + @pytest.fixture(scope="session") + def inner_model(self, model: models.TestSqliteType) -> models.TestInnerSqliteType: + return models.TestInnerSqliteType( + table_id=model.id_, + int_test=None, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=None, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=None, + bool_test=None, + boolean_test=None, + date_test=None, + datetime_test=None, + timestamp_test=None, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::insert") + def test_insert( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + queries.insert_one_sqlite_type( + conn=sqlite3_conn, + id_=model.id_, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::inner_insert", depends=["Sqlite3TestPydanticFunctions::insert"]) + def test_inner_insert( + self, + sqlite3_conn: sqlite3.Connection, + inner_model: models.TestInnerSqliteType, + ) -> None: + queries.insert_one_inner_sqlite_type( + conn=sqlite3_conn, + table_id=inner_model.table_id, + int_test=inner_model.int_test, + bigint_test=inner_model.bigint_test, + smallint_test=inner_model.smallint_test, + tinyint_test=inner_model.tinyint_test, + int2_test=inner_model.int2_test, + int8_test=inner_model.int8_test, + bigserial_test=inner_model.bigserial_test, + blob_test=inner_model.blob_test, + real_test=inner_model.real_test, + double_test=inner_model.double_test, + double_precision_test=inner_model.double_precision_test, + float_test=inner_model.float_test, + numeric_test=inner_model.numeric_test, + decimal_test=inner_model.decimal_test, + bool_test=inner_model.bool_test, + boolean_test=inner_model.boolean_test, + date_test=inner_model.date_test, + datetime_test=inner_model.datetime_test, + timestamp_test=inner_model.timestamp_test, + character_test=inner_model.character_test, + varchar_test=inner_model.varchar_test, + varyingcharacter_test=inner_model.varyingcharacter_test, + nchar_test=inner_model.nchar_test, + nativecharacter_test=inner_model.nativecharacter_test, + nvarchar_test=inner_model.nvarchar_test, + text_test=inner_model.text_test, + clob_test=inner_model.clob_test, + json_test=inner_model.json_test, + ) + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_one", depends=["Sqlite3TestPydanticFunctions::inner_insert"]) + def test_get_one( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.get_one_sqlite_type(conn=sqlite3_conn, id_=model.id_) + + assert result is not None + + assert isinstance(result, models.TestSqliteType) + + assert result == model + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_one_none", depends=["Sqlite3TestPydanticFunctions::get_one"]) + def test_get_one_none( + self, + sqlite3_conn: sqlite3.Connection, + ) -> None: + result = queries.get_one_sqlite_type(conn=sqlite3_conn, id_=0) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_one_inner", depends=["Sqlite3TestPydanticFunctions::get_one_none"]) + def test_get_one_inner( + self, + sqlite3_conn: sqlite3.Connection, + inner_model: models.TestInnerSqliteType, + ) -> None: + result = queries.get_one_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id) + + assert result is not None + + assert isinstance(result, models.TestInnerSqliteType) + assert result == inner_model + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_one_inner_none", + depends=["Sqlite3TestPydanticFunctions::get_one_inner"], + ) + def test_get_one_inner_none( + self, + sqlite3_conn: sqlite3.Connection, + ) -> None: + result = queries.get_one_inner_sqlite_type(conn=sqlite3_conn, table_id=0) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_date", depends=["Sqlite3TestPydanticFunctions::get_one_inner_none"]) + def test_get_date( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.get_one_date(conn=sqlite3_conn, id_=model.id_, date_test=model.date_test) + + assert result is not None + + assert isinstance(result, datetime.date) + assert result == model.date_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_date_none", depends=["Sqlite3TestPydanticFunctions::get_date"]) + def test_get_date_none( + self, + sqlite3_conn: sqlite3.Connection, + ) -> None: + result = queries.get_one_date(conn=sqlite3_conn, id_=0, date_test=datetime.date.today()) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_datetime", depends=["Sqlite3TestPydanticFunctions::get_date_none"]) + def test_get_datetime( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.get_one_datetime(conn=sqlite3_conn, id_=model.id_, datetime_test=model.datetime_test) + + assert result is not None + + assert isinstance(result, datetime.datetime) + assert result == model.datetime_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_datetime_none", depends=["Sqlite3TestPydanticFunctions::get_datetime"]) + def test_get_datetime_none( + self, + sqlite3_conn: sqlite3.Connection, + ) -> None: + result = queries.get_one_datetime(conn=sqlite3_conn, id_=0, datetime_test=datetime.datetime.now()) + + assert result is None + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_timestamp", + depends=["Sqlite3TestPydanticFunctions::get_datetime_none"], + ) + def test_get_timestamp( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.get_one_timestamp(conn=sqlite3_conn, id_=model.id_, timestamp_test=model.timestamp_test) + + assert result is not None + + assert isinstance(result, datetime.datetime) + assert result == model.timestamp_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_timestamp_none", + depends=["Sqlite3TestPydanticFunctions::get_timestamp"], + ) + def test_get_timestamp_none( + self, + sqlite3_conn: sqlite3.Connection, + ) -> None: + result = queries.get_one_timestamp(conn=sqlite3_conn, id_=0, timestamp_test=datetime.datetime.now()) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_bool", depends=["Sqlite3TestPydanticFunctions::get_timestamp_none"]) + def test_get_bool( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.get_one_bool(conn=sqlite3_conn, id_=model.id_, bool_test=model.bool_test) + + assert result is not None + + assert isinstance(result, bool) + assert result == model.bool_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_bool_none", depends=["Sqlite3TestPydanticFunctions::get_bool"]) + def test_get_bool_none( + self, + sqlite3_conn: sqlite3.Connection, + ) -> None: + result = queries.get_one_bool(conn=sqlite3_conn, id_=0, bool_test=False) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_boolean", depends=["Sqlite3TestPydanticFunctions::get_bool_none"]) + def test_get_boolean( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.get_one_boolean(conn=sqlite3_conn, id_=model.id_, boolean_test=model.boolean_test) + + assert result is not None + + assert isinstance(result, bool) + assert result == model.boolean_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_boolean_none", depends=["Sqlite3TestPydanticFunctions::get_boolean"]) + def test_get_boolean_none( + self, + sqlite3_conn: sqlite3.Connection, + ) -> None: + result = queries.get_one_boolean(conn=sqlite3_conn, id_=0, boolean_test=True) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_decimal", depends=["Sqlite3TestPydanticFunctions::get_boolean_none"]) + def test_get_decimal( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.get_one_decimal(conn=sqlite3_conn, id_=model.id_, decimal_test=model.decimal_test) + + assert result is not None + + assert isinstance(result, decimal.Decimal) + assert result == model.decimal_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_decimal_none", depends=["Sqlite3TestPydanticFunctions::get_decimal"]) + def test_get_decimal_none( + self, + sqlite3_conn: sqlite3.Connection, + ) -> None: + result = queries.get_one_decimal(conn=sqlite3_conn, id_=0, decimal_test=decimal.Decimal("0.1")) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_blob", depends=["Sqlite3TestPydanticFunctions::get_decimal_none"]) + def test_get_blob( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.get_one_blob(conn=sqlite3_conn, id_=model.id_, blob_test=model.blob_test) + + assert result is not None + + assert isinstance(result, memoryview) + assert result == model.blob_test + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_blob_none", depends=["Sqlite3TestPydanticFunctions::get_blob"]) + def test_get_blob_none( + self, + sqlite3_conn: sqlite3.Connection, + ) -> None: + result = queries.get_one_blob(conn=sqlite3_conn, id_=0, blob_test=memoryview(b"test")) + + assert result is None + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_many", depends=["Sqlite3TestPydanticFunctions::get_blob_none"]) + def test_get_many(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + result = queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id_) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], models.TestSqliteType) + + assert results[0] == model + results = result() + assert isinstance(results[0], models.TestSqliteType) + + assert results[0] == model + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_many_iter", depends=["Sqlite3TestPydanticFunctions::get_many"]) + def test_get_many_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + for result in queries.get_many_sqlite_type(conn=sqlite3_conn, id_=model.id_): + assert result is not None + assert isinstance(result, models.TestSqliteType) + + assert result == model + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::get_many_inner", depends=["Sqlite3TestPydanticFunctions::get_many_iter"]) + def test_get_many_inner(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: + result = queries.get_many_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], models.TestInnerSqliteType) + + assert results[0] == inner_model + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_inner_iter", + depends=["Sqlite3TestPydanticFunctions::get_many_inner"], + ) + def test_get_many_inner_iter(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: + for result in queries.get_many_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id): + assert result is not None + assert isinstance(result, models.TestInnerSqliteType) + + assert result == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_nullable_inner", + depends=["Sqlite3TestPydanticFunctions::get_many_inner_iter"], + ) + async def test_get_many_nullable_inner(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: + result = queries.get_many_nullable_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], models.TestInnerSqliteType) + + assert results[0] == inner_model + + @pytest.mark.asyncio(loop_scope="session") + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_nullable_inner_iter", + depends=["Sqlite3TestPydanticFunctions::get_many_nullable_inner"], + ) + async def test_get_many_nullable_inner_iter(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: + for result in queries.get_many_nullable_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id, int_test=inner_model.int_test): + assert result is not None + assert isinstance(result, models.TestInnerSqliteType) + + assert result == inner_model + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_date", + depends=["Sqlite3TestPydanticFunctions::get_many_nullable_inner_iter"], + ) + def test_get_many_date(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + result = queries.get_many_date(conn=sqlite3_conn, id_=model.id_, date_test=model.date_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], datetime.date) + + assert results[0] == model.date_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_date_iter", + depends=["Sqlite3TestPydanticFunctions::get_many_date"], + ) + def test_get_many_date_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + for result in queries.get_many_date(conn=sqlite3_conn, id_=model.id_, date_test=model.date_test): + assert result is not None + assert isinstance(result, datetime.date) + + assert result == model.date_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_datetime", + depends=["Sqlite3TestPydanticFunctions::get_many_date_iter"], + ) + def test_get_many_datetime(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + result = queries.get_many_datetime(conn=sqlite3_conn, id_=model.id_, datetime_test=model.datetime_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], datetime.datetime) + + assert results[0] == model.datetime_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_datetime_iter", + depends=["Sqlite3TestPydanticFunctions::get_many_datetime"], + ) + def test_get_many_datetime_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + for result in queries.get_many_datetime(conn=sqlite3_conn, id_=model.id_, datetime_test=model.datetime_test): + assert result is not None + assert isinstance(result, datetime.datetime) + + assert result == model.datetime_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_timestamp", + depends=["Sqlite3TestPydanticFunctions::get_many_datetime_iter"], + ) + def test_get_many_timestamp(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + result = queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id_, timestamp_test=model.timestamp_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], datetime.datetime) + + assert results[0] == model.timestamp_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_timestamp_iter", + depends=["Sqlite3TestPydanticFunctions::get_many_timestamp"], + ) + def test_get_many_timestamp_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + for result in queries.get_many_timestamp(conn=sqlite3_conn, id_=model.id_, timestamp_test=model.timestamp_test): + assert result is not None + assert isinstance(result, datetime.datetime) + + assert result == model.timestamp_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_bool", + depends=["Sqlite3TestPydanticFunctions::get_many_timestamp_iter"], + ) + def test_get_many_bool(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + result = queries.get_many_bool(conn=sqlite3_conn, id_=model.id_, bool_test=model.bool_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], bool) + + assert results[0] == model.bool_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_bool_iter", + depends=["Sqlite3TestPydanticFunctions::get_many_bool"], + ) + def test_get_many_bool_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + for result in queries.get_many_bool(conn=sqlite3_conn, id_=model.id_, bool_test=model.bool_test): + assert result is not None + assert isinstance(result, bool) + + assert result == model.bool_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_boolean", + depends=["Sqlite3TestPydanticFunctions::get_many_bool_iter"], + ) + def test_get_many_boolean(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + result = queries.get_many_boolean(conn=sqlite3_conn, id_=model.id_, boolean_test=model.boolean_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], bool) + + assert results[0] == model.boolean_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_boolean_iter", + depends=["Sqlite3TestPydanticFunctions::get_many_boolean"], + ) + def test_get_many_boolean_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + for result in queries.get_many_boolean(conn=sqlite3_conn, id_=model.id_, boolean_test=model.boolean_test): + assert result is not None + assert isinstance(result, bool) + + assert result == model.boolean_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_decimal", + depends=["Sqlite3TestPydanticFunctions::get_many_boolean_iter"], + ) + def test_get_many_decimal(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + result = queries.get_many_decimal(conn=sqlite3_conn, id_=model.id_, decimal_test=model.decimal_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], decimal.Decimal) + + assert results[0] == model.decimal_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_decimal_iter", + depends=["Sqlite3TestPydanticFunctions::get_many_decimal"], + ) + def test_get_many_decimal_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + for result in queries.get_many_decimal(conn=sqlite3_conn, id_=model.id_, decimal_test=model.decimal_test): + assert result is not None + assert isinstance(result, decimal.Decimal) + + assert result == model.decimal_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_blob", + depends=["Sqlite3TestPydanticFunctions::get_many_decimal_iter"], + ) + def test_get_many_blob(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + result = queries.get_many_blob(conn=sqlite3_conn, id_=model.id_, blob_test=model.blob_test) + + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], memoryview) + + assert results[0] == model.blob_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_blob_iter", + depends=["Sqlite3TestPydanticFunctions::get_many_blob"], + ) + def test_get_many_blob_iter(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + for result in queries.get_many_blob(conn=sqlite3_conn, id_=model.id_, blob_test=model.blob_test): + assert result is not None + assert isinstance(result, memoryview) + + assert result == model.blob_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::insert_result", + depends=["Sqlite3TestPydanticFunctions::get_many_blob_iter"], + ) + def test_insert_result( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.insert_result_one_sqlite_type( + conn=sqlite3_conn, + id_=model.id_ + 1, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + assert isinstance(result, sqlite3.Cursor) + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::update_result", depends=["Sqlite3TestPydanticFunctions::insert_result"]) + def test_update_result( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.update_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 1) + assert isinstance(result, sqlite3.Cursor) + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::delete_result", depends=["Sqlite3TestPydanticFunctions::update_result"]) + def test_delete_result( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.delete_result_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 1) + assert isinstance(result, sqlite3.Cursor) + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::insert_rows", depends=["Sqlite3TestPydanticFunctions::delete_result"]) + def test_insert_rows( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.insert_rows_one_sqlite_type( + conn=sqlite3_conn, + id_=model.id_ + 2, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + assert isinstance(result, int) + assert result == 1 + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::update_rows", depends=["Sqlite3TestPydanticFunctions::insert_rows"]) + def test_update_rows( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.update_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 2) + assert isinstance(result, int) + assert result == 1 + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::delete_rows", depends=["Sqlite3TestPydanticFunctions::update_rows"]) + def test_delete_rows( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.delete_rows_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 2) + assert isinstance(result, int) + assert result == 1 + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::create_table_rows", depends=["Sqlite3TestPydanticFunctions::delete_rows"]) + def test_create_table_rows( + self, + sqlite3_conn: sqlite3.Connection, + ) -> None: + result = queries.create_rows_table(conn=sqlite3_conn) + assert isinstance(result, int) + sqlite3_conn.execute("DROP TABLE test_create_rows_table;") + sqlite3_conn.commit() + assert result == -1 + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::insert_last_id", + depends=["Sqlite3TestPydanticFunctions::create_table_rows"], + ) + def test_insert_last_id( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.insert_last_id_one_sqlite_type( + conn=sqlite3_conn, + id_=model.id_ + 3, + int_test=model.int_test, + bigint_test=model.bigint_test, + smallint_test=model.smallint_test, + tinyint_test=model.tinyint_test, + int2_test=model.int2_test, + int8_test=model.int8_test, + bigserial_test=model.bigserial_test, + blob_test=model.blob_test, + real_test=model.real_test, + double_test=model.double_test, + double_precision_test=model.double_precision_test, + float_test=model.float_test, + numeric_test=model.numeric_test, + decimal_test=model.decimal_test, + bool_test=model.bool_test, + boolean_test=model.boolean_test, + date_test=model.date_test, + datetime_test=model.datetime_test, + timestamp_test=model.timestamp_test, + character_test=model.character_test, + varchar_test=model.varchar_test, + varyingcharacter_test=model.varyingcharacter_test, + nchar_test=model.nchar_test, + nativecharacter_test=model.nativecharacter_test, + nvarchar_test=model.nvarchar_test, + text_test=model.text_test, + clob_test=model.clob_test, + json_test=model.json_test, + ) + assert isinstance(result, int) + assert result == model.id_ + 3 + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::update_last_id", depends=["Sqlite3TestPydanticFunctions::insert_last_id"]) + def test_update_last_id( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.update_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 3) + assert isinstance(result, int) + assert result == model.id_ + 3 + + @pytest.mark.dependency(name="Sqlite3TestPydanticFunctions::delete_last_id", depends=["Sqlite3TestPydanticFunctions::update_last_id"]) + def test_delete_last_id( + self, + sqlite3_conn: sqlite3.Connection, + model: models.TestSqliteType, + ) -> None: + result = queries.delete_last_id_one_sqlite_type(conn=sqlite3_conn, id_=model.id_ + 3) + assert isinstance(result, int) + assert result == model.id_ + 3 + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::delete_sqlite_type", + depends=["Sqlite3TestPydanticFunctions::delete_last_id"], + ) + def test_delete_sqlite_type(self, sqlite3_conn: sqlite3.Connection, model: models.TestSqliteType) -> None: + queries.delete_one_sqlite_type(conn=sqlite3_conn, id_=model.id_) + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::delete_inner_sqlite_type", + depends=["Sqlite3TestPydanticFunctions::delete_sqlite_type"], + ) + def test_delete_inner_sqlite_type(self, sqlite3_conn: sqlite3.Connection, inner_model: models.TestInnerSqliteType) -> None: + queries.delete_one_test_inner_sqlite_type(conn=sqlite3_conn, table_id=inner_model.table_id) + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::insert_type_override", + ) + def test_insert_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + queries.insert_type_override(conn=sqlite3_conn, id_=override_model.id_, text_test=override_model.text_test) + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_one_type_override", + depends=["Sqlite3TestPydanticFunctions::insert_type_override"], + ) + def test_get_one_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id_) + assert result is not None + assert result == override_model + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_one_type_override_none", + depends=["Sqlite3TestPydanticFunctions::get_one_type_override"], + ) + def test_get_one_type_override_none(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_type_override(conn=sqlite3_conn, id_=override_model.id_ - 1) + assert result is None + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_type_override", + depends=["Sqlite3TestPydanticFunctions::get_one_type_override_none"], + ) + def test_get_many_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_many_type_override(conn=sqlite3_conn, id_=override_model.id_) + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], models.TestTypeOverride) + + assert results[0] == override_model + + results = result() + assert isinstance(results[0], models.TestTypeOverride) + + assert results[0] == override_model + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_one_text_type_override", + depends=["Sqlite3TestPydanticFunctions::get_many_type_override"], + ) + def test_get_one_text_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id_) + assert result is not None + assert result == override_model.text_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_one_text_type_override_none", + depends=["Sqlite3TestPydanticFunctions::get_one_text_type_override"], + ) + def test_get_one_text_type_override_none(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_one_text_type_override(conn=sqlite3_conn, id_=override_model.id_ - 1) + assert result is None + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::get_many_text_type_override", + depends=["Sqlite3TestPydanticFunctions::get_one_text_type_override_none"], + ) + def test_get_many_text_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + result = queries.get_many_text_type_override(conn=sqlite3_conn, id_=override_model.id_) + assert result is not None + assert isinstance(result, queries.QueryResults) + results = list(result) + assert isinstance(results[0], UserString) + + assert results[0] == override_model.text_test + + results = result() + assert isinstance(results[0], UserString) + + assert results[0] == override_model.text_test + + @pytest.mark.dependency( + name="Sqlite3TestPydanticFunctions::delete_type_override", + depends=["Sqlite3TestPydanticFunctions::get_many_text_type_override"], + ) + def test_delete_type_override(self, sqlite3_conn: sqlite3.Connection, override_model: models.TestTypeOverride) -> None: + queries.delete_type_override(conn=sqlite3_conn, id_=override_model.id_) diff --git a/test/driver_sqlite3/queries_case.sql b/test/driver_sqlite3/queries_case.sql new file mode 100644 index 00000000..b49399db --- /dev/null +++ b/test/driver_sqlite3/queries_case.sql @@ -0,0 +1,11 @@ +-- name: InsertCaseRow :exec +INSERT INTO test_case_sensitivity (id, upper_dt, prec_dec) VALUES (?, ?, ?); + +-- name: GetCaseRow :one +SELECT upper_dt, prec_dec FROM test_case_sensitivity WHERE id = ?; + +-- name: InsertReservedArg :exec +INSERT INTO test_reserved_args (id, conn) VALUES (?, ?); + +-- name: GetReservedArg :one +SELECT id FROM test_reserved_args WHERE conn = ?; diff --git a/test/driver_sqlite3/queries_override_adapter.sql b/test/driver_sqlite3/queries_override_adapter.sql new file mode 100644 index 00000000..201e540b --- /dev/null +++ b/test/driver_sqlite3/queries_override_adapter.sql @@ -0,0 +1,5 @@ +-- name: InsertOverrideConversion :exec +INSERT INTO test_override_conversion (id, price, happened_at) VALUES (?, ?, ?); + +-- name: GetOverridePrice :one +SELECT price FROM test_override_conversion WHERE id = ?; diff --git a/test/driver_sqlite3/queries_override_converter.sql b/test/driver_sqlite3/queries_override_converter.sql new file mode 100644 index 00000000..dd081a56 --- /dev/null +++ b/test/driver_sqlite3/queries_override_converter.sql @@ -0,0 +1,2 @@ +-- name: GetOverrideHappenedAt :one +SELECT happened_at FROM test_override_conversion WHERE id = ?; diff --git a/test/driver_sqlite3/schema.sql b/test/driver_sqlite3/schema.sql index bf423e35..37bc71ec 100644 --- a/test/driver_sqlite3/schema.sql +++ b/test/driver_sqlite3/schema.sql @@ -1,32 +1,32 @@ CREATE TABLE IF NOT EXISTS test_sqlite_types ( - /* ───────────── Integer family ───────────── */ + /* ------------- Integer family ------------- */ id integer PRIMARY KEY NOT NULL, - int_test int NOT NULL, -- covers integer / mediumint … - bigint_test bigint NOT NULL, -- covers unsignedbigint … + int_test int NOT NULL, -- covers integer / mediumint ... + bigint_test bigint NOT NULL, -- covers unsignedbigint ... smallint_test smallint NOT NULL, tinyint_test tinyint NOT NULL, int2_test int2 NOT NULL, int8_test int8 NOT NULL, bigserial_test bigserial NOT NULL, - /* ───────────── Binary (blob) ───────────── */ + /* ------------- Binary (blob) ------------- */ blob_test blob NOT NULL, - /* ───────────── Floating-point / numeric ───────────── */ + /* ------------- Floating-point / numeric ------------- */ real_test real NOT NULL, double_test double NOT NULL, double_precision_test double precision NOT NULL, float_test float NOT NULL, numeric_test numeric NOT NULL, - /* ───────────── Exact numeric (decimal) ───────────── */ + /* ------------- Exact numeric (decimal) ------------- */ decimal_test decimal NOT NULL, - /* ───────────── Boolean ───────────── */ + /* ------------- Boolean ------------- */ boolean_test boolean NOT NULL, bool_test bool NOT NULL, - /* ───────────── Date & time ───────────── */ + /* ------------- Date & time ------------- */ date_test date NOT NULL, datetime_test datetime NOT NULL, timestamp_test timestamp NOT NULL, - /* ───────────── Character / text ───────────── */ + /* ------------- Character / text ------------- */ character_test character(10) NOT NULL, varchar_test varchar(255) NOT NULL, varyingcharacter_test varyingcharacter (255) NOT NULL, @@ -40,33 +40,33 @@ CREATE TABLE IF NOT EXISTS test_sqlite_types -- split CREATE TABLE IF NOT EXISTS test_inner_sqlite_types ( - /* ───────────── Integer family ───────────── */ + /* ------------- Integer family ------------- */ table_id integer PRIMARY KEY NOT NULL, - int_test int , -- covers integer / mediumint … - bigint_test bigint , -- covers unsignedbigint … + int_test int , -- covers integer / mediumint ... + bigint_test bigint , -- covers unsignedbigint ... smallint_test smallint , tinyint_test tinyint , int2_test int2 , int8_test int8 , bigserial_test bigserial , - /* ───────────── Binary (blob) ───────────── */ + /* ------------- Binary (blob) ------------- */ blob_test blob , - /* ───────────── Floating-point / numeric ───────────── */ + /* ------------- Floating-point / numeric ------------- */ real_test real , double_test double , double_precision_test double precision , float_test float , numeric_test numeric , - /* ───────────── Exact numeric (decimal) ───────────── */ + /* ------------- Exact numeric (decimal) ------------- */ decimal_test decimal , - /* ───────────── Boolean ───────────── */ + /* ------------- Boolean ------------- */ boolean_test boolean , bool_test bool , - /* ───────────── Date & time ───────────── */ + /* ------------- Date & time ------------- */ date_test date , datetime_test datetime , timestamp_test timestamp , - /* ───────────── Character / text ───────────── */ + /* ------------- Character / text ------------- */ character_test character(10) , varchar_test varchar(255) , varyingcharacter_test varyingcharacter (255) , @@ -82,4 +82,27 @@ CREATE TABLE IF NOT EXISTS test_type_override ( id integer PRIMARY KEY NOT NULL, text_test text +); + +CREATE TABLE IF NOT EXISTS test_override_conversion +( + id integer PRIMARY KEY NOT NULL, + price decimal NOT NULL, + happened_at datetime NOT NULL +); + +-- Uppercase type names and precision variants exercise the SQL-type +-- normalization: annotation and conversion registration must agree. +CREATE TABLE IF NOT EXISTS test_case_sensitivity +( + id integer PRIMARY KEY NOT NULL, + upper_dt DATETIME NOT NULL, + prec_dec decimal(10,2) NOT NULL +); + +-- A column named like the implicit first argument of generated functions. +CREATE TABLE IF NOT EXISTS test_reserved_args +( + id integer PRIMARY KEY NOT NULL, + conn text NOT NULL ); \ No newline at end of file diff --git a/test/driver_sqlite3/sqlc-gen-better-python.wasm b/test/driver_sqlite3/sqlc-gen-better-python.wasm index 56caaa4b..a0a8faab 100644 Binary files a/test/driver_sqlite3/sqlc-gen-better-python.wasm and b/test/driver_sqlite3/sqlc-gen-better-python.wasm differ diff --git a/test/driver_sqlite3/sqlc.yaml b/test/driver_sqlite3/sqlc.yaml index 25560b7b..cc7d119e 100644 --- a/test/driver_sqlite3/sqlc.yaml +++ b/test/driver_sqlite3/sqlc.yaml @@ -3,10 +3,14 @@ plugins: - name: python wasm: url: file://sqlc-gen-better-python.wasm - sha256: ee7bd0c07b784b80ea8c5853d9a6a04c51a7abbfd2663f470e9a5d2f623b967e + sha256: 0d564b87865b4733c9a41bd318277973c130fc02c32b5bfdb2a0b662f36148da sql: - schema: schema.sql - queries: queries.sql + queries: + - queries.sql + - queries_override_adapter.sql + - queries_override_converter.sql + - queries_case.sql engine: sqlite codegen: - out: /attrs/classes @@ -26,8 +30,15 @@ sql: import: collections package: UserString type: UserString + - column: test_override_conversion.price + py_type: + type: float - schema: schema.sql - queries: queries.sql + queries: + - queries.sql + - queries_override_adapter.sql + - queries_override_converter.sql + - queries_case.sql engine: sqlite codegen: - out: /attrs/functions @@ -46,8 +57,15 @@ sql: import: collections package: UserString type: UserString + - column: test_override_conversion.price + py_type: + type: float - schema: schema.sql - queries: queries.sql + queries: + - queries.sql + - queries_override_adapter.sql + - queries_override_converter.sql + - queries_case.sql engine: sqlite codegen: - out: /dataclass/classes @@ -66,8 +84,15 @@ sql: import: collections package: UserString type: UserString + - column: test_override_conversion.price + py_type: + type: float - schema: schema.sql - queries: queries.sql + queries: + - queries.sql + - queries_override_adapter.sql + - queries_override_converter.sql + - queries_case.sql engine: sqlite codegen: - out: /dataclass/functions @@ -86,8 +111,15 @@ sql: import: collections package: UserString type: UserString + - column: test_override_conversion.price + py_type: + type: float - schema: schema.sql - queries: queries.sql + queries: + - queries.sql + - queries_override_adapter.sql + - queries_override_converter.sql + - queries_case.sql engine: sqlite codegen: - out: /msgspec/classes @@ -106,8 +138,15 @@ sql: import: collections package: UserString type: UserString + - column: test_override_conversion.price + py_type: + type: float - schema: schema.sql - queries: queries.sql + queries: + - queries.sql + - queries_override_adapter.sql + - queries_override_converter.sql + - queries_case.sql engine: sqlite codegen: - out: /msgspec/functions @@ -126,4 +165,62 @@ sql: import: collections package: UserString type: UserString + - column: test_override_conversion.price + py_type: + type: float + + - schema: schema.sql + queries: + - queries.sql + - queries_override_adapter.sql + - queries_override_converter.sql + - queries_case.sql + engine: sqlite + codegen: + - out: /pydantic/classes + plugin: python + options: + package: test.driver_sqlite3.pydantic.classes + sql_driver: sqlite3 + model_type: pydantic + emit_classes: true + omit_unused_models: true + emit_init_file: true + docstrings: google + overrides: + - column: test_type_override.text_test + py_type: + import: collections + package: UserString + type: UserString + - column: test_override_conversion.price + py_type: + type: float + - schema: schema.sql + queries: + - queries.sql + - queries_override_adapter.sql + - queries_override_converter.sql + - queries_case.sql + engine: sqlite + codegen: + - out: /pydantic/functions + plugin: python + options: + package: test.driver_sqlite3.pydantic.functions + sql_driver: sqlite3 + model_type: pydantic + emit_classes: false + omit_unused_models: true + emit_init_file: true + docstrings: google + overrides: + - column: test_type_override.text_test + py_type: + import: collections + package: UserString + type: UserString + - column: test_override_conversion.price + py_type: + type: float diff --git a/test/queries.sql b/test/queries.sql index edfe618d..a62ae3e8 100644 --- a/test/queries.sql +++ b/test/queries.sql @@ -1,40 +1,102 @@ --- name: GetEmbeddedTestPostgresType1 :one -SELECT *, sqlc.embed(test_inner_postgres_types) -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id LIMIT 1; - - --- name: TestThatIsReallyImportant :many -SELECT timestamp_test FROM test_postgres_types WHERE id = $1; - --- name: GetEmbeddedTestPostgresType2 :one -SELECT test_postgres_types.*, sqlc.embed(test_inner_postgres_types), test_inner_postgres_types.bool_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id LIMIT 1; - --- name: GetEmbeddedTestPostgresType3 :one -SELECT test_postgres_types.id, - test_postgres_types.serial_test, - sqlc.embed(test_inner_postgres_types), - test_inner_postgres_types.bool_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id LIMIT 1; - --- name: GetEmbeddedTestPostgresType4 :one -SELECT sqlc.embed(test_postgres_types), - sqlc.embed(test_inner_postgres_types), - test_inner_postgres_types.bool_test -FROM test_postgres_types - JOIN test_inner_postgres_types ON test_inner_postgres_types.table_id = test_postgres_types.id LIMIT 1; - - --- name: TestExecute :exec -INSERT INTO test_postgres_types (id, serial_test, timestamp_test) -VALUES ($1, $2, $3); +-- --- :exec / :execresult / :execrows / :copyfrom ------------------------ + +-- name: InsertAuthor :exec +INSERT INTO authors (id, name, bio, mood, tags, avatar, rating, created) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8); + +-- name: UpdateAuthorName :execresult +UPDATE authors SET name = $2 WHERE id = $1; + +-- name: DeleteAuthorsByMood :execrows +DELETE FROM authors WHERE mood = $1; + +-- name: CopyAuthors :copyfrom +INSERT INTO authors (id, name, mood, tags, rating, created) +VALUES ($1, $2, $3, $4, $5, $6); + + +-- --- :one returning a tracked table (should reference models.X) --------- + +-- name: GetAuthor :one +SELECT * FROM authors WHERE id = $1; + +-- name: GetBook :one +SELECT * FROM books WHERE id = $1; + +-- name: GetReview :one +SELECT * FROM custom.reviews WHERE id = $1; + + +-- --- :one returning a scalar -------------------------------------------- + +-- name: GetAuthorName :one +SELECT name FROM authors WHERE id = $1; + +-- name: GetAuthorBio :one +SELECT bio FROM authors WHERE id = $1; + +-- name: GetAuthorMood :one +SELECT mood FROM authors WHERE id = $1; + +-- name: GetAuthorTags :one +SELECT tags FROM authors WHERE id = $1; + +-- name: GetAuthorAvatar :one +SELECT avatar FROM authors WHERE id = $1; + --- name: GetAll :many -SELECT * FROM test_postgres_types; +-- --- :one returning an inline-defined struct (no table match) ----------- + +-- name: GetAuthorIdAndName :one +SELECT id, name FROM authors WHERE id = $1; + +-- name: GetBookWithAuthorName :one +SELECT b.id, b.title, a.name AS author_name +FROM books b + JOIN authors a ON a.id = b.author_id +WHERE b.id = $1; + + +-- --- sqlc.embed() ------------------------------------------------------- + +-- name: GetBookWithAuthor :one +SELECT sqlc.embed(books), sqlc.embed(authors) +FROM books + JOIN authors ON authors.id = books.author_id +WHERE books.id = $1; + +-- name: ListBooksWithAuthor :many +SELECT sqlc.embed(books), sqlc.embed(authors) +FROM books + JOIN authors ON authors.id = books.author_id; + + +-- --- :many -------------------------------------------------------------- + +-- name: ListAuthors :many +SELECT * FROM authors; + +-- name: ListAuthorIds :many +SELECT id FROM authors; + +-- name: ListAuthorsByMood :many +SELECT * FROM authors WHERE mood = $1; + +-- name: ListBookTitlesByAuthor :many +SELECT b.title, a.name AS author_name +FROM books b + JOIN authors a ON a.id = b.author_id +WHERE a.id = $1; + +-- name: ListReviewsForBook :many +SELECT * FROM custom.reviews WHERE book_id = $1; + + +-- --- Misc --------------------------------------------------------------- + +-- name: InsertReview :exec +INSERT INTO custom.reviews (id, book_id, mood) +VALUES ($1, $2, $3); --- name: TTTT :one -SELECT serial_test -FROM test_postgres_types LIMIT 1; +-- name: CountAuthors :one +SELECT COUNT(*) FROM authors; diff --git a/test/schema.sql b/test/schema.sql index b249f21a..1f0d6c35 100644 --- a/test/schema.sql +++ b/test/schema.sql @@ -1,15 +1,36 @@ -CREATE TABLE test_postgres_types +-- Public-schema enum +CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy'); + +-- Primary table - exercises non-null, nullable, enum, array, and the +-- three types that need runtime conversion (bytea, numeric, timestamptz). +CREATE TABLE authors +( + id int PRIMARY KEY NOT NULL, + name text NOT NULL, + bio text, + mood mood NOT NULL, + tags text[] NOT NULL, + avatar bytea, + rating numeric(3, 2) NOT NULL, + created timestamptz NOT NULL +); + +-- Secondary table - gives us something to JOIN / sqlc.embed against. +CREATE TABLE books ( - /* ───────────── Integer family ───────────── */ - id int PRIMARY KEY NOT NULL, - serial_test serial NOT NULL, - timestamp_test timestamp NOT NULL + id int PRIMARY KEY NOT NULL, + author_id int NOT NULL, + title text NOT NULL ); -CREATE TABLE test_inner_postgres_types +-- Custom schema - same enum name in a different schema (tests +-- schema-qualified naming and that the generator doesn't collide). +CREATE SCHEMA IF NOT EXISTS custom; +CREATE TYPE custom.mood AS ENUM ('sad', 'ok', 'happy'); + +CREATE TABLE custom.reviews ( - /* ───────────── Integer family ───────────── */ - table_id int NOT NULL, - /* ───────────── Boolean ───────────── */ - bool_test boolean NOT NULL -); \ No newline at end of file + id int PRIMARY KEY NOT NULL, + book_id int NOT NULL, + mood custom.mood NOT NULL +); diff --git a/uv.lock b/uv.lock index d18c3a68..6da8dba4 100644 --- a/uv.lock +++ b/uv.lock @@ -1,6 +1,6 @@ version = 1 revision = 3 -requires-python = ">=3.10.0, <3.14.0" +requires-python = ">=3.12.0, <3.14.0" [[package]] name = "aiosqlite" @@ -15,48 +15,29 @@ wheels = [ ] [[package]] -name = "argcomplete" -version = "3.6.2" +name = "annotated-types" +version = "0.7.0" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/16/0f/861e168fc813c56a78b35f3c30d91c6757d1fd185af1110f1aec784b35d0/argcomplete-3.6.2.tar.gz", hash = "sha256:d0519b1bc867f5f4f4713c41ad0aba73a4a5f007449716b16f385f2166dc6adf", size = 73403, upload-time = "2025-04-03T04:57:03.52Z" } +sdist = { url = "https://files.pythonhosted.org/packages/ee/67/531ea369ba64dcff5ec9c3402f9f51bf748cec26dde048a2f973a4eea7f5/annotated_types-0.7.0.tar.gz", hash = "sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89", size = 16081, upload-time = "2024-05-20T21:33:25.928Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/31/da/e42d7a9d8dd33fa775f467e4028a47936da2f01e4b0e561f9ba0d74cb0ca/argcomplete-3.6.2-py3-none-any.whl", hash = "sha256:65b3133a29ad53fb42c48cf5114752c7ab66c1c38544fdf6460f450c09b42591", size = 43708, upload-time = "2025-04-03T04:57:01.591Z" }, + { url = "https://files.pythonhosted.org/packages/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8/annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53", size = 13643, upload-time = "2024-05-20T21:33:24.1Z" }, ] [[package]] -name = "async-timeout" -version = "5.0.1" +name = "argcomplete" +version = "3.6.2" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/a5/ae/136395dfbfe00dfc94da3f3e136d0b13f394cba8f4841120e34226265780/async_timeout-5.0.1.tar.gz", hash = "sha256:d9321a7a3d5a6a5e187e824d2fa0793ce379a202935782d555d6e9d2735677d3", size = 9274, upload-time = "2024-11-06T16:41:39.6Z" } +sdist = { url = "https://files.pythonhosted.org/packages/16/0f/861e168fc813c56a78b35f3c30d91c6757d1fd185af1110f1aec784b35d0/argcomplete-3.6.2.tar.gz", hash = "sha256:d0519b1bc867f5f4f4713c41ad0aba73a4a5f007449716b16f385f2166dc6adf", size = 73403, upload-time = "2025-04-03T04:57:03.52Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/fe/ba/e2081de779ca30d473f21f5b30e0e737c438205440784c7dfc81efc2b029/async_timeout-5.0.1-py3-none-any.whl", hash = "sha256:39e3809566ff85354557ec2398b55e096c8364bacac9405a7a1fa429e77fe76c", size = 6233, upload-time = "2024-11-06T16:41:37.9Z" }, + { url = "https://files.pythonhosted.org/packages/31/da/e42d7a9d8dd33fa775f467e4028a47936da2f01e4b0e561f9ba0d74cb0ca/argcomplete-3.6.2-py3-none-any.whl", hash = "sha256:65b3133a29ad53fb42c48cf5114752c7ab66c1c38544fdf6460f450c09b42591", size = 43708, upload-time = "2025-04-03T04:57:01.591Z" }, ] [[package]] name = "asyncpg" version = "0.30.0" source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "async-timeout", marker = "python_full_version < '3.11'" }, -] sdist = { url = "https://files.pythonhosted.org/packages/2f/4c/7c991e080e106d854809030d8584e15b2e996e26f16aee6d757e387bc17d/asyncpg-0.30.0.tar.gz", hash = "sha256:c551e9928ab6707602f44811817f82ba3c446e018bfe1d3abecc8ba5f3eac851", size = 957746, upload-time = "2024-10-20T00:30:41.127Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/bb/07/1650a8c30e3a5c625478fa8aafd89a8dd7d85999bf7169b16f54973ebf2c/asyncpg-0.30.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:bfb4dd5ae0699bad2b233672c8fc5ccbd9ad24b89afded02341786887e37927e", size = 673143, upload-time = "2024-10-20T00:29:08.846Z" }, - { url = "https://files.pythonhosted.org/packages/a0/9a/568ff9b590d0954553c56806766914c149609b828c426c5118d4869111d3/asyncpg-0.30.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:dc1f62c792752a49f88b7e6f774c26077091b44caceb1983509edc18a2222ec0", size = 645035, upload-time = "2024-10-20T00:29:12.02Z" }, - { url = "https://files.pythonhosted.org/packages/de/11/6f2fa6c902f341ca10403743701ea952bca896fc5b07cc1f4705d2bb0593/asyncpg-0.30.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3152fef2e265c9c24eec4ee3d22b4f4d2703d30614b0b6753e9ed4115c8a146f", size = 2912384, upload-time = "2024-10-20T00:29:13.644Z" }, - { url = "https://files.pythonhosted.org/packages/83/83/44bd393919c504ffe4a82d0aed8ea0e55eb1571a1dea6a4922b723f0a03b/asyncpg-0.30.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c7255812ac85099a0e1ffb81b10dc477b9973345793776b128a23e60148dd1af", size = 2947526, upload-time = "2024-10-20T00:29:15.871Z" }, - { url = "https://files.pythonhosted.org/packages/08/85/e23dd3a2b55536eb0ded80c457b0693352262dc70426ef4d4a6fc994fa51/asyncpg-0.30.0-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:578445f09f45d1ad7abddbff2a3c7f7c291738fdae0abffbeb737d3fc3ab8b75", size = 2895390, upload-time = "2024-10-20T00:29:19.346Z" }, - { url = "https://files.pythonhosted.org/packages/9b/26/fa96c8f4877d47dc6c1864fef5500b446522365da3d3d0ee89a5cce71a3f/asyncpg-0.30.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:c42f6bb65a277ce4d93f3fba46b91a265631c8df7250592dd4f11f8b0152150f", size = 3015630, upload-time = "2024-10-20T00:29:21.186Z" }, - { url = "https://files.pythonhosted.org/packages/34/00/814514eb9287614188a5179a8b6e588a3611ca47d41937af0f3a844b1b4b/asyncpg-0.30.0-cp310-cp310-win32.whl", hash = "sha256:aa403147d3e07a267ada2ae34dfc9324e67ccc4cdca35261c8c22792ba2b10cf", size = 568760, upload-time = "2024-10-20T00:29:22.769Z" }, - { url = "https://files.pythonhosted.org/packages/f0/28/869a7a279400f8b06dd237266fdd7220bc5f7c975348fea5d1e6909588e9/asyncpg-0.30.0-cp310-cp310-win_amd64.whl", hash = "sha256:fb622c94db4e13137c4c7f98834185049cc50ee01d8f657ef898b6407c7b9c50", size = 625764, upload-time = "2024-10-20T00:29:25.882Z" }, - { url = "https://files.pythonhosted.org/packages/4c/0e/f5d708add0d0b97446c402db7e8dd4c4183c13edaabe8a8500b411e7b495/asyncpg-0.30.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:5e0511ad3dec5f6b4f7a9e063591d407eee66b88c14e2ea636f187da1dcfff6a", size = 674506, upload-time = "2024-10-20T00:29:27.988Z" }, - { url = "https://files.pythonhosted.org/packages/6a/a0/67ec9a75cb24a1d99f97b8437c8d56da40e6f6bd23b04e2f4ea5d5ad82ac/asyncpg-0.30.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:915aeb9f79316b43c3207363af12d0e6fd10776641a7de8a01212afd95bdf0ed", size = 645922, upload-time = "2024-10-20T00:29:29.391Z" }, - { url = "https://files.pythonhosted.org/packages/5c/d9/a7584f24174bd86ff1053b14bb841f9e714380c672f61c906eb01d8ec433/asyncpg-0.30.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1c198a00cce9506fcd0bf219a799f38ac7a237745e1d27f0e1f66d3707c84a5a", size = 3079565, upload-time = "2024-10-20T00:29:30.832Z" }, - { url = "https://files.pythonhosted.org/packages/a0/d7/a4c0f9660e333114bdb04d1a9ac70db690dd4ae003f34f691139a5cbdae3/asyncpg-0.30.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3326e6d7381799e9735ca2ec9fd7be4d5fef5dcbc3cb555d8a463d8460607956", size = 3109962, upload-time = "2024-10-20T00:29:33.114Z" }, - { url = "https://files.pythonhosted.org/packages/3c/21/199fd16b5a981b1575923cbb5d9cf916fdc936b377e0423099f209e7e73d/asyncpg-0.30.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:51da377487e249e35bd0859661f6ee2b81db11ad1f4fc036194bc9cb2ead5056", size = 3064791, upload-time = "2024-10-20T00:29:34.677Z" }, - { url = "https://files.pythonhosted.org/packages/77/52/0004809b3427534a0c9139c08c87b515f1c77a8376a50ae29f001e53962f/asyncpg-0.30.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:bc6d84136f9c4d24d358f3b02be4b6ba358abd09f80737d1ac7c444f36108454", size = 3188696, upload-time = "2024-10-20T00:29:36.389Z" }, - { url = "https://files.pythonhosted.org/packages/52/cb/fbad941cd466117be58b774a3f1cc9ecc659af625f028b163b1e646a55fe/asyncpg-0.30.0-cp311-cp311-win32.whl", hash = "sha256:574156480df14f64c2d76450a3f3aaaf26105869cad3865041156b38459e935d", size = 567358, upload-time = "2024-10-20T00:29:37.915Z" }, - { url = "https://files.pythonhosted.org/packages/3c/0a/0a32307cf166d50e1ad120d9b81a33a948a1a5463ebfa5a96cc5606c0863/asyncpg-0.30.0-cp311-cp311-win_amd64.whl", hash = "sha256:3356637f0bd830407b5597317b3cb3571387ae52ddc3bca6233682be88bbbc1f", size = 629375, upload-time = "2024-10-20T00:29:39.987Z" }, { url = "https://files.pythonhosted.org/packages/4b/64/9d3e887bb7b01535fdbc45fbd5f0a8447539833b97ee69ecdbb7a79d0cb4/asyncpg-0.30.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:c902a60b52e506d38d7e80e0dd5399f657220f24635fee368117b8b5fce1142e", size = 673162, upload-time = "2024-10-20T00:29:41.88Z" }, { url = "https://files.pythonhosted.org/packages/6e/eb/8b236663f06984f212a087b3e849731f917ab80f84450e943900e8ca4052/asyncpg-0.30.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:aca1548e43bbb9f0f627a04666fedaca23db0a31a84136ad1f868cb15deb6e3a", size = 637025, upload-time = "2024-10-20T00:29:43.352Z" }, { url = "https://files.pythonhosted.org/packages/cc/57/2dc240bb263d58786cfaa60920779af6e8d32da63ab9ffc09f8312bd7a14/asyncpg-0.30.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6c2a2ef565400234a633da0eafdce27e843836256d40705d83ab7ec42074efb3", size = 3496243, upload-time = "2024-10-20T00:29:44.922Z" }, @@ -103,22 +84,6 @@ version = "2.3.2" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/09/e9/d83711081c997540aee59ad2f49d81f01d33e8551d766b0ebde346f605af/ciso8601-2.3.2.tar.gz", hash = "sha256:ec1616969aa46c51310b196022e5d3926f8d3fa52b80ec17f6b4133623bd5434", size = 28214, upload-time = "2024-12-09T12:26:40.768Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/63/54/7522b0056ff0f59790d15cc043fdbf067d9af0fa313e4a8811b65c0b4ded/ciso8601-2.3.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:1bb2d4d20d7ed65fcc7137652d7d980c6eb2aa19c935579309170137d33064ce", size = 15724, upload-time = "2024-12-09T12:25:46.332Z" }, - { url = "https://files.pythonhosted.org/packages/a4/98/17f6e3bf01857cc2594f29ecc5316a4591d40e54c14d85cde433fc0d5cbb/ciso8601-2.3.2-cp310-cp310-macosx_11_0_universal2.whl", hash = "sha256:3039f11ced0bc971341ab63be222860eb2cc942d51a7aa101b1809b633ad2288", size = 23809, upload-time = "2024-12-09T12:25:48.043Z" }, - { url = "https://files.pythonhosted.org/packages/9d/48/6a396459dd24b3d7a05b3858b58c3dbc19a7d561cd9accaf77b6ddd2242c/ciso8601-2.3.2-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:d64634b02cfb194e54569d8de3ace89cec745644cab38157aea0b03d32031eda", size = 15586, upload-time = "2024-12-09T12:25:49.818Z" }, - { url = "https://files.pythonhosted.org/packages/59/64/4f9362e7f3817d9a408e17ae0a71cd3d16037e33e4dd0f3a301b4727c2e5/ciso8601-2.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b0dcb8dc5998bc50346cec9d3b8b5deda8ddabeda70a923c110efb5100cd9754", size = 39279, upload-time = "2024-12-09T12:25:50.91Z" }, - { url = "https://files.pythonhosted.org/packages/cd/f9/56a707dc73604472dfdab611f210c22741b73b5b7795b6dc6422d072bae6/ciso8601-2.3.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:13a3ca99eadbee4a9bb7dfb2bcf266a21828033853cd99803a9893d3473ac0e9", size = 39014, upload-time = "2024-12-09T12:25:52.477Z" }, - { url = "https://files.pythonhosted.org/packages/87/27/02dc32c3ff7ca18a0f595a13d5f5e749a1270a030ce8f50d6b78ae95a984/ciso8601-2.3.2-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:d61daee5e8daee87eba34151b9952ec8c3327ad9e54686b6247dcb9b2b135312", size = 39892, upload-time = "2024-12-09T12:25:54.182Z" }, - { url = "https://files.pythonhosted.org/packages/41/ba/57016baecaab3f9fae9399ee0ad25573eec82042c55560f86d004717381c/ciso8601-2.3.2-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:2f20654de6b0374eade96d8dcb0642196632067b6dd2e24068c563ac6b8551c6", size = 39650, upload-time = "2024-12-09T12:25:55.803Z" }, - { url = "https://files.pythonhosted.org/packages/8e/9b/b924dbd5aa378208c7a24bd867b174b13fd0377ba9293fab5c2f977895a6/ciso8601-2.3.2-cp310-cp310-win_amd64.whl", hash = "sha256:0283884c33dbe0555f9a24749ac947f93eac7b131fdfeeee110ad999947d1680", size = 17245, upload-time = "2024-12-09T12:25:56.837Z" }, - { url = "https://files.pythonhosted.org/packages/9a/00/489c0724d2a273384344b76c1420f21ede894d3f1d9ba240176f0d8595e6/ciso8601-2.3.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f0e856903cb6019ab26849af7270ef183b2314f87fd17686a8c98315eff794df", size = 15722, upload-time = "2024-12-09T12:25:57.851Z" }, - { url = "https://files.pythonhosted.org/packages/d1/5e/5c29a477ec5207f0e1604fbd15280401e4715163bf51f316b5ee907da1c4/ciso8601-2.3.2-cp311-cp311-macosx_11_0_universal2.whl", hash = "sha256:d99297a5925ef3c9ac316cab082c1b1623d976acdb5056fbb8cb12a854116351", size = 23815, upload-time = "2024-12-09T12:25:59.477Z" }, - { url = "https://files.pythonhosted.org/packages/bf/35/1000cebcd41863394ec3d4ba05656be9a20ae4a27de1646da12c6d336cdd/ciso8601-2.3.2-cp311-cp311-macosx_11_0_x86_64.whl", hash = "sha256:2e740d2dcac81b5adb0cff641706d5a9e54ff4f3bb7e24437cdacdab3937c0a3", size = 15585, upload-time = "2024-12-09T12:26:00.356Z" }, - { url = "https://files.pythonhosted.org/packages/93/3d/f763d2bfa22a50fb004d77106c18a58dbde3fa5d4c5cf7d096bb23af8dc5/ciso8601-2.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e883a08b294694313bd3a85c1a136f4326ca26050552742c489159c52e296060", size = 39534, upload-time = "2024-12-09T12:26:01.937Z" }, - { url = "https://files.pythonhosted.org/packages/bc/ba/012ac7082fd10c15c0cd347cb62ad88eaf135dc6e4b6190a9becf9acfeaa/ciso8601-2.3.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6994b393b1e1147dbc2f13d6d508f6e95b96d7f770299a4af70b7c1d380242c1", size = 39260, upload-time = "2024-12-09T12:26:02.975Z" }, - { url = "https://files.pythonhosted.org/packages/02/41/8310f8998c3e98c334f8dfaf905725c85771eee4ece9e5ee833070d483f2/ciso8601-2.3.2-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:2d31a04bea97f21b797fd414b465c00283b70d9523e8e51bc303bec04195a278", size = 40014, upload-time = "2024-12-09T12:26:04.012Z" }, - { url = "https://files.pythonhosted.org/packages/00/9f/28d592b034a8a8c1ddeac55812172d9b22942077e681c84c268173bfe4e1/ciso8601-2.3.2-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:ce014a3559592320a2a7a7205257e57dd1277580038a30f153627c5d30ed7a07", size = 39861, upload-time = "2024-12-09T12:26:05.082Z" }, - { url = "https://files.pythonhosted.org/packages/21/53/bb466b34c8853a2ca54009fa3bb3aa8ddc46f90fc504b9433471b9a40fa7/ciso8601-2.3.2-cp311-cp311-win_amd64.whl", hash = "sha256:b069800ea5613eea7d323716133a74bd0fba4a781286167a20639b6628a7e068", size = 17240, upload-time = "2024-12-09T12:26:06.254Z" }, { url = "https://files.pythonhosted.org/packages/d6/fc/e852e664bb90bf1112e17778512d6cbc5fa5f49b7c22969e4ee131f13d06/ciso8601-2.3.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:75870a1e496a17e9e8d2ac90125600e1bafe51679d2836b2f6cb66908fef7ad6", size = 15755, upload-time = "2024-12-09T12:26:07.259Z" }, { url = "https://files.pythonhosted.org/packages/22/da/c82e665c627836be4d7d0a8ed38518f9833124a6fd85735881cac72427b8/ciso8601-2.3.2-cp312-cp312-macosx_11_0_universal2.whl", hash = "sha256:c117c415c43aa3db68ee16a2446cb85c5e88459650421d773f6f6444ce5e5819", size = 24291, upload-time = "2024-12-09T12:26:08.23Z" }, { url = "https://files.pythonhosted.org/packages/3c/6a/822b178b6c473533e5023aab6447b05d1683f95c3210eda5680f9262c93c/ciso8601-2.3.2-cp312-cp312-macosx_11_0_x86_64.whl", hash = "sha256:ce5f76297b6138dc5c085d4c5a0a631afded99f250233fe583dc365f67fe8a8d", size = 15713, upload-time = "2024-12-09T12:26:09.191Z" }, @@ -127,8 +92,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/05/ae/de5f920ebf5cdb2ef28237bdb48ac9ea980d794e16f1fbedffc430064208/ciso8601-2.3.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:e825cb5ecd232775a94ef3c456ab19752ee8e66eaeb20562ea45472eaa8614ec", size = 40908, upload-time = "2024-12-09T12:26:12.092Z" }, { url = "https://files.pythonhosted.org/packages/b2/3c/cd79c9305480cc9bf8dce286bd7ec2035a3d140b3f3ae0b1232087a65240/ciso8601-2.3.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:7a8f96f91bdeabee7ebca2c6e48185bea45e195f406ff748c87a3c9ecefb25cc", size = 40881, upload-time = "2024-12-09T12:26:12.997Z" }, { url = "https://files.pythonhosted.org/packages/b1/f7/f1b64a6dac1ff824ad6eee9c2b540fbe411f288b40218a06644fa2e4f075/ciso8601-2.3.2-cp312-cp312-win_amd64.whl", hash = "sha256:3fe497819e50a245253a3b2d62ec4c68f8cf337d79dc18e2f3b0a74d24dc5e93", size = 17278, upload-time = "2024-12-09T12:26:14.027Z" }, - { url = "https://files.pythonhosted.org/packages/9f/8c/344f1db4606408ac00803692baf988fdd8d4c82abaf9911272286dc30785/ciso8601-2.3.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ecc2f7090e7b8427288b9528fa9571682426f2c7d45d39cf940321192d8796c8", size = 17483, upload-time = "2024-12-09T12:26:34.183Z" }, - { url = "https://files.pythonhosted.org/packages/99/76/572d904b3307d9ab01b4586a0935b0a62dded5e57565ac87cd13a55dd332/ciso8601-2.3.2-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c585a05d745c36f974030d1831ed899f8b00afd760f6eff6b8de7eef72cb1336", size = 16559, upload-time = "2024-12-09T12:26:35.051Z" }, ] [[package]] @@ -158,26 +121,6 @@ version = "7.8.0" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/19/4f/2251e65033ed2ce1e68f00f91a0294e0f80c80ae8c3ebbe2f12828c4cd53/coverage-7.8.0.tar.gz", hash = "sha256:7a3d62b3b03b4b6fd41a085f3574874cf946cb4604d2b4d3e8dca8cd570ca501", size = 811872, upload-time = "2025-03-30T20:36:45.376Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/78/01/1c5e6ee4ebaaa5e079db933a9a45f61172048c7efa06648445821a201084/coverage-7.8.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:2931f66991175369859b5fd58529cd4b73582461877ecfd859b6549869287ffe", size = 211379, upload-time = "2025-03-30T20:34:53.904Z" }, - { url = "https://files.pythonhosted.org/packages/e9/16/a463389f5ff916963471f7c13585e5f38c6814607306b3cb4d6b4cf13384/coverage-7.8.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:52a523153c568d2c0ef8826f6cc23031dc86cffb8c6aeab92c4ff776e7951b28", size = 211814, upload-time = "2025-03-30T20:34:56.959Z" }, - { url = "https://files.pythonhosted.org/packages/b8/b1/77062b0393f54d79064dfb72d2da402657d7c569cfbc724d56ac0f9c67ed/coverage-7.8.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5c8a5c139aae4c35cbd7cadca1df02ea8cf28a911534fc1b0456acb0b14234f3", size = 240937, upload-time = "2025-03-30T20:34:58.751Z" }, - { url = "https://files.pythonhosted.org/packages/d7/54/c7b00a23150083c124e908c352db03bcd33375494a4beb0c6d79b35448b9/coverage-7.8.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5a26c0c795c3e0b63ec7da6efded5f0bc856d7c0b24b2ac84b4d1d7bc578d676", size = 238849, upload-time = "2025-03-30T20:35:00.521Z" }, - { url = "https://files.pythonhosted.org/packages/f7/ec/a6b7cfebd34e7b49f844788fda94713035372b5200c23088e3bbafb30970/coverage-7.8.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:821f7bcbaa84318287115d54becb1915eece6918136c6f91045bb84e2f88739d", size = 239986, upload-time = "2025-03-30T20:35:02.307Z" }, - { url = "https://files.pythonhosted.org/packages/21/8c/c965ecef8af54e6d9b11bfbba85d4f6a319399f5f724798498387f3209eb/coverage-7.8.0-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:a321c61477ff8ee705b8a5fed370b5710c56b3a52d17b983d9215861e37b642a", size = 239896, upload-time = "2025-03-30T20:35:04.141Z" }, - { url = "https://files.pythonhosted.org/packages/40/83/070550273fb4c480efa8381735969cb403fa8fd1626d74865bfaf9e4d903/coverage-7.8.0-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:ed2144b8a78f9d94d9515963ed273d620e07846acd5d4b0a642d4849e8d91a0c", size = 238613, upload-time = "2025-03-30T20:35:05.889Z" }, - { url = "https://files.pythonhosted.org/packages/07/76/fbb2540495b01d996d38e9f8897b861afed356be01160ab4e25471f4fed1/coverage-7.8.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:042e7841a26498fff7a37d6fda770d17519982f5b7d8bf5278d140b67b61095f", size = 238909, upload-time = "2025-03-30T20:35:07.76Z" }, - { url = "https://files.pythonhosted.org/packages/a3/7e/76d604db640b7d4a86e5dd730b73e96e12a8185f22b5d0799025121f4dcb/coverage-7.8.0-cp310-cp310-win32.whl", hash = "sha256:f9983d01d7705b2d1f7a95e10bbe4091fabc03a46881a256c2787637b087003f", size = 213948, upload-time = "2025-03-30T20:35:09.144Z" }, - { url = "https://files.pythonhosted.org/packages/5c/a7/f8ce4aafb4a12ab475b56c76a71a40f427740cf496c14e943ade72e25023/coverage-7.8.0-cp310-cp310-win_amd64.whl", hash = "sha256:5a570cd9bd20b85d1a0d7b009aaf6c110b52b5755c17be6962f8ccd65d1dbd23", size = 214844, upload-time = "2025-03-30T20:35:10.734Z" }, - { url = "https://files.pythonhosted.org/packages/2b/77/074d201adb8383addae5784cb8e2dac60bb62bfdf28b2b10f3a3af2fda47/coverage-7.8.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:e7ac22a0bb2c7c49f441f7a6d46c9c80d96e56f5a8bc6972529ed43c8b694e27", size = 211493, upload-time = "2025-03-30T20:35:12.286Z" }, - { url = "https://files.pythonhosted.org/packages/a9/89/7a8efe585750fe59b48d09f871f0e0c028a7b10722b2172dfe021fa2fdd4/coverage-7.8.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:bf13d564d310c156d1c8e53877baf2993fb3073b2fc9f69790ca6a732eb4bfea", size = 211921, upload-time = "2025-03-30T20:35:14.18Z" }, - { url = "https://files.pythonhosted.org/packages/e9/ef/96a90c31d08a3f40c49dbe897df4f1fd51fb6583821a1a1c5ee30cc8f680/coverage-7.8.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a5761c70c017c1b0d21b0815a920ffb94a670c8d5d409d9b38857874c21f70d7", size = 244556, upload-time = "2025-03-30T20:35:15.616Z" }, - { url = "https://files.pythonhosted.org/packages/89/97/dcd5c2ce72cee9d7b0ee8c89162c24972fb987a111b92d1a3d1d19100c61/coverage-7.8.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e5ff52d790c7e1628241ffbcaeb33e07d14b007b6eb00a19320c7b8a7024c040", size = 242245, upload-time = "2025-03-30T20:35:18.648Z" }, - { url = "https://files.pythonhosted.org/packages/b2/7b/b63cbb44096141ed435843bbb251558c8e05cc835c8da31ca6ffb26d44c0/coverage-7.8.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d39fc4817fd67b3915256af5dda75fd4ee10621a3d484524487e33416c6f3543", size = 244032, upload-time = "2025-03-30T20:35:20.131Z" }, - { url = "https://files.pythonhosted.org/packages/97/e3/7fa8c2c00a1ef530c2a42fa5df25a6971391f92739d83d67a4ee6dcf7a02/coverage-7.8.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:b44674870709017e4b4036e3d0d6c17f06a0e6d4436422e0ad29b882c40697d2", size = 243679, upload-time = "2025-03-30T20:35:21.636Z" }, - { url = "https://files.pythonhosted.org/packages/4f/b3/e0a59d8df9150c8a0c0841d55d6568f0a9195692136c44f3d21f1842c8f6/coverage-7.8.0-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:8f99eb72bf27cbb167b636eb1726f590c00e1ad375002230607a844d9e9a2318", size = 241852, upload-time = "2025-03-30T20:35:23.525Z" }, - { url = "https://files.pythonhosted.org/packages/9b/82/db347ccd57bcef150c173df2ade97976a8367a3be7160e303e43dd0c795f/coverage-7.8.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:b571bf5341ba8c6bc02e0baeaf3b061ab993bf372d982ae509807e7f112554e9", size = 242389, upload-time = "2025-03-30T20:35:25.09Z" }, - { url = "https://files.pythonhosted.org/packages/21/f6/3f7d7879ceb03923195d9ff294456241ed05815281f5254bc16ef71d6a20/coverage-7.8.0-cp311-cp311-win32.whl", hash = "sha256:e75a2ad7b647fd8046d58c3132d7eaf31b12d8a53c0e4b21fa9c4d23d6ee6d3c", size = 213997, upload-time = "2025-03-30T20:35:26.914Z" }, - { url = "https://files.pythonhosted.org/packages/28/87/021189643e18ecf045dbe1e2071b2747901f229df302de01c998eeadf146/coverage-7.8.0-cp311-cp311-win_amd64.whl", hash = "sha256:3043ba1c88b2139126fc72cb48574b90e2e0546d4c78b5299317f61b7f718b78", size = 214911, upload-time = "2025-03-30T20:35:28.498Z" }, { url = "https://files.pythonhosted.org/packages/aa/12/4792669473297f7973518bec373a955e267deb4339286f882439b8535b39/coverage-7.8.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:bbb5cc845a0292e0c520656d19d7ce40e18d0e19b22cb3e0409135a575bf79fc", size = 211684, upload-time = "2025-03-30T20:35:29.959Z" }, { url = "https://files.pythonhosted.org/packages/be/e1/2a4ec273894000ebedd789e8f2fc3813fcaf486074f87fd1c5b2cb1c0a2b/coverage-7.8.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4dfd9a93db9e78666d178d4f08a5408aa3f2474ad4d0e0378ed5f2ef71640cb6", size = 211935, upload-time = "2025-03-30T20:35:31.912Z" }, { url = "https://files.pythonhosted.org/packages/f8/3a/7b14f6e4372786709a361729164125f6b7caf4024ce02e596c4a69bccb89/coverage-7.8.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f017a61399f13aa6d1039f75cd467be388d157cd81f1a119b9d9a68ba6f2830d", size = 245994, upload-time = "2025-03-30T20:35:33.455Z" }, @@ -208,22 +151,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/58/e9/8fb8e0ff6bef5e170ee19d59ca694f9001b2ec085dc99b4f65c128bb3f9a/coverage-7.8.0-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:f3c38e4e5ccbdc9198aecc766cedbb134b2d89bf64533973678dfcf07effd883", size = 255116, upload-time = "2025-03-30T20:36:18.033Z" }, { url = "https://files.pythonhosted.org/packages/56/b0/d968ecdbe6fe0a863de7169bbe9e8a476868959f3af24981f6a10d2b6924/coverage-7.8.0-cp313-cp313t-win32.whl", hash = "sha256:379fe315e206b14e21db5240f89dc0774bdd3e25c3c58c2c733c99eca96f1ada", size = 214909, upload-time = "2025-03-30T20:36:19.644Z" }, { url = "https://files.pythonhosted.org/packages/87/e9/d6b7ef9fecf42dfb418d93544af47c940aa83056c49e6021a564aafbc91f/coverage-7.8.0-cp313-cp313t-win_amd64.whl", hash = "sha256:2e4b6b87bb0c846a9315e3ab4be2d52fac905100565f4b92f02c445c8799e257", size = 216068, upload-time = "2025-03-30T20:36:21.282Z" }, - { url = "https://files.pythonhosted.org/packages/c4/f1/1da77bb4c920aa30e82fa9b6ea065da3467977c2e5e032e38e66f1c57ffd/coverage-7.8.0-pp39.pp310.pp311-none-any.whl", hash = "sha256:b8194fb8e50d556d5849753de991d390c5a1edeeba50f68e3a9253fbd8bf8ccd", size = 203443, upload-time = "2025-03-30T20:36:41.959Z" }, { url = "https://files.pythonhosted.org/packages/59/f1/4da7717f0063a222db253e7121bd6a56f6fb1ba439dcc36659088793347c/coverage-7.8.0-py3-none-any.whl", hash = "sha256:dbf364b4c5e7bae9250528167dfe40219b62e2d573c854d74be213e1e52069f7", size = 203435, upload-time = "2025-03-30T20:36:43.61Z" }, ] -[package.optional-dependencies] -toml = [ - { name = "tomli", marker = "python_full_version <= '3.11'" }, -] - [[package]] name = "dependency-groups" version = "1.3.1" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "packaging" }, - { name = "tomli", marker = "python_full_version < '3.11'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/62/55/f054de99871e7beb81935dea8a10b90cd5ce42122b1c3081d5282fdb3621/dependency_groups-1.3.1.tar.gz", hash = "sha256:78078301090517fd938c19f64a53ce98c32834dfe0dee6b88004a569a6adfefd", size = 10093, upload-time = "2025-05-02T00:34:29.452Z" } wheels = [ @@ -239,18 +175,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/91/a1/cf2472db20f7ce4a6be1253a81cfdf85ad9c7885ffbed7047fb72c24cf87/distlib-0.3.9-py2.py3-none-any.whl", hash = "sha256:47f8c22fd27c27e25a65601af709b38e4f0a45ea4fc2e710f65755fa8caaaf87", size = 468973, upload-time = "2024-10-09T18:35:44.272Z" }, ] -[[package]] -name = "exceptiongroup" -version = "1.3.0" -source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "typing-extensions", marker = "python_full_version < '3.13'" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/0b/9f/a65090624ecf468cdca03533906e7c69ed7588582240cfe7cc9e770b50eb/exceptiongroup-1.3.0.tar.gz", hash = "sha256:b241f5885f560bc56a59ee63ca4c6a8bfa46ae4ad651af316d4e81817bb9fd88", size = 29749, upload-time = "2025-05-10T17:42:51.123Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/36/f4/c6e662dade71f56cd2f3735141b265c3c79293c109549c1e6933b0651ffc/exceptiongroup-1.3.0-py3-none-any.whl", hash = "sha256:4d111e6e0c13d0644cad6ddaa7ed0261a0b36971f6d23e7ec9b4b9097da78a10", size = 16674, upload-time = "2025-05-10T17:42:49.33Z" }, -] - [[package]] name = "filelock" version = "3.20.3" @@ -275,20 +199,6 @@ version = "0.19.0" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/cf/9b/95d8ce458462b8b71b8a70fa94563b2498b89933689f3a7b8911edfae3d7/msgspec-0.19.0.tar.gz", hash = "sha256:604037e7cd475345848116e89c553aa9a233259733ab51986ac924ab1b976f8e", size = 216934, upload-time = "2024-12-27T17:40:28.597Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/13/40/817282b42f58399762267b30deb8ac011d8db373f8da0c212c85fbe62b8f/msgspec-0.19.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d8dd848ee7ca7c8153462557655570156c2be94e79acec3561cf379581343259", size = 190019, upload-time = "2024-12-27T17:39:13.803Z" }, - { url = "https://files.pythonhosted.org/packages/92/99/bd7ed738c00f223a8119928661167a89124140792af18af513e6519b0d54/msgspec-0.19.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:0553bbc77662e5708fe66aa75e7bd3e4b0f209709c48b299afd791d711a93c36", size = 183680, upload-time = "2024-12-27T17:39:17.847Z" }, - { url = "https://files.pythonhosted.org/packages/e5/27/322badde18eb234e36d4a14122b89edd4e2973cdbc3da61ca7edf40a1ccd/msgspec-0.19.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fe2c4bf29bf4e89790b3117470dea2c20b59932772483082c468b990d45fb947", size = 209334, upload-time = "2024-12-27T17:39:19.065Z" }, - { url = "https://files.pythonhosted.org/packages/c6/65/080509c5774a1592b2779d902a70b5fe008532759927e011f068145a16cb/msgspec-0.19.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:00e87ecfa9795ee5214861eab8326b0e75475c2e68a384002aa135ea2a27d909", size = 211551, upload-time = "2024-12-27T17:39:21.767Z" }, - { url = "https://files.pythonhosted.org/packages/6f/2e/1c23c6b4ca6f4285c30a39def1054e2bee281389e4b681b5e3711bd5a8c9/msgspec-0.19.0-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:3c4ec642689da44618f68c90855a10edbc6ac3ff7c1d94395446c65a776e712a", size = 215099, upload-time = "2024-12-27T17:39:24.71Z" }, - { url = "https://files.pythonhosted.org/packages/83/fe/95f9654518879f3359d1e76bc41189113aa9102452170ab7c9a9a4ee52f6/msgspec-0.19.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:2719647625320b60e2d8af06b35f5b12d4f4d281db30a15a1df22adb2295f633", size = 218211, upload-time = "2024-12-27T17:39:27.396Z" }, - { url = "https://files.pythonhosted.org/packages/79/f6/71ca7e87a1fb34dfe5efea8156c9ef59dd55613aeda2ca562f122cd22012/msgspec-0.19.0-cp310-cp310-win_amd64.whl", hash = "sha256:695b832d0091edd86eeb535cd39e45f3919f48d997685f7ac31acb15e0a2ed90", size = 186174, upload-time = "2024-12-27T17:39:29.647Z" }, - { url = "https://files.pythonhosted.org/packages/24/d4/2ec2567ac30dab072cce3e91fb17803c52f0a37aab6b0c24375d2b20a581/msgspec-0.19.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:aa77046904db764b0462036bc63ef71f02b75b8f72e9c9dd4c447d6da1ed8f8e", size = 187939, upload-time = "2024-12-27T17:39:32.347Z" }, - { url = "https://files.pythonhosted.org/packages/2b/c0/18226e4328897f4f19875cb62bb9259fe47e901eade9d9376ab5f251a929/msgspec-0.19.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:047cfa8675eb3bad68722cfe95c60e7afabf84d1bd8938979dd2b92e9e4a9551", size = 182202, upload-time = "2024-12-27T17:39:33.633Z" }, - { url = "https://files.pythonhosted.org/packages/81/25/3a4b24d468203d8af90d1d351b77ea3cffb96b29492855cf83078f16bfe4/msgspec-0.19.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e78f46ff39a427e10b4a61614a2777ad69559cc8d603a7c05681f5a595ea98f7", size = 209029, upload-time = "2024-12-27T17:39:35.023Z" }, - { url = "https://files.pythonhosted.org/packages/85/2e/db7e189b57901955239f7689b5dcd6ae9458637a9c66747326726c650523/msgspec-0.19.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c7adf191e4bd3be0e9231c3b6dc20cf1199ada2af523885efc2ed218eafd011", size = 210682, upload-time = "2024-12-27T17:39:36.384Z" }, - { url = "https://files.pythonhosted.org/packages/03/97/7c8895c9074a97052d7e4a1cc1230b7b6e2ca2486714eb12c3f08bb9d284/msgspec-0.19.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:f04cad4385e20be7c7176bb8ae3dca54a08e9756cfc97bcdb4f18560c3042063", size = 214003, upload-time = "2024-12-27T17:39:39.097Z" }, - { url = "https://files.pythonhosted.org/packages/61/61/e892997bcaa289559b4d5869f066a8021b79f4bf8e955f831b095f47a4cd/msgspec-0.19.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:45c8fb410670b3b7eb884d44a75589377c341ec1392b778311acdbfa55187716", size = 216833, upload-time = "2024-12-27T17:39:41.203Z" }, - { url = "https://files.pythonhosted.org/packages/ce/3d/71b2dffd3a1c743ffe13296ff701ee503feaebc3f04d0e75613b6563c374/msgspec-0.19.0-cp311-cp311-win_amd64.whl", hash = "sha256:70eaef4934b87193a27d802534dc466778ad8d536e296ae2f9334e182ac27b6c", size = 186184, upload-time = "2024-12-27T17:39:43.702Z" }, { url = "https://files.pythonhosted.org/packages/b2/5f/a70c24f075e3e7af2fae5414c7048b0e11389685b7f717bb55ba282a34a7/msgspec-0.19.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:f98bd8962ad549c27d63845b50af3f53ec468b6318400c9f1adfe8b092d7b62f", size = 190485, upload-time = "2024-12-27T17:39:44.974Z" }, { url = "https://files.pythonhosted.org/packages/89/b0/1b9763938cfae12acf14b682fcf05c92855974d921a5a985ecc197d1c672/msgspec-0.19.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:43bbb237feab761b815ed9df43b266114203f53596f9b6e6f00ebd79d178cdf2", size = 183910, upload-time = "2024-12-27T17:39:46.401Z" }, { url = "https://files.pythonhosted.org/packages/87/81/0c8c93f0b92c97e326b279795f9c5b956c5a97af28ca0fbb9fd86c83737a/msgspec-0.19.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4cfc033c02c3e0aec52b71710d7f84cb3ca5eb407ab2ad23d75631153fdb1f12", size = 210633, upload-time = "2024-12-27T17:39:49.099Z" }, @@ -324,7 +234,6 @@ dependencies = [ { name = "colorlog" }, { name = "dependency-groups" }, { name = "packaging" }, - { name = "tomli", marker = "python_full_version < '3.11'" }, { name = "virtualenv" }, ] sdist = { url = "https://files.pythonhosted.org/packages/b4/80/47712208c410defec169992e57c179f0f4d92f5dd17ba8daca50a8077e23/nox-2025.5.1.tar.gz", hash = "sha256:2a571dfa7a58acc726521ac3cd8184455ebcdcbf26401c7b737b5bc6701427b2", size = 4023334, upload-time = "2025-05-01T16:35:48.056Z" } @@ -359,6 +268,66 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/88/5f/e351af9a41f866ac3f1fac4ca0613908d9a41741cfcf2228f4ad853b697d/pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669", size = 20556, upload-time = "2024-04-20T21:34:40.434Z" }, ] +[[package]] +name = "pydantic" +version = "2.13.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "annotated-types" }, + { name = "pydantic-core" }, + { name = "typing-extensions" }, + { name = "typing-inspection" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/18/a5/b60d21ac674192f8ab0ba4e9fd860690f9b4a6e51ca5df118733b487d8d6/pydantic-2.13.4.tar.gz", hash = "sha256:c40756b57adaa8b1efeeced5c196f3f3b7c435f90e84ea7f443901bec8099ef6", size = 844775, upload-time = "2026-05-06T13:43:05.343Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/fd/7b/122376b1fd3c62c1ed9dc80c931ace4844b3c55407b6fb2d199377c9736f/pydantic-2.13.4-py3-none-any.whl", hash = "sha256:45a282cde31d808236fd7ea9d919b128653c8b38b393d1c4ab335c62924d9aba", size = 472262, upload-time = "2026-05-06T13:43:02.641Z" }, +] + +[[package]] +name = "pydantic-core" +version = "2.46.4" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9d/56/921726b776ace8d8f5db44c4ef961006580d91dc52b803c489fafd1aa249/pydantic_core-2.46.4.tar.gz", hash = "sha256:62f875393d7f270851f20523dd2e29f082bcc82292d66db2b64ea71f64b6e1c1", size = 471464, upload-time = "2026-05-06T13:37:06.98Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ce/8c/af022f0af448d7747c5154288d46b5f2bc5f17366eaa0e23e9aa04d59f3b/pydantic_core-2.46.4-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:3245406455a5d98187ec35530fd772b1d799b26667980872c8d4614991e2c4a2", size = 2106158, upload-time = "2026-05-06T13:38:57.215Z" }, + { url = "https://files.pythonhosted.org/packages/19/95/6195171e385007300f0f5574592e467c568becce2d937a0b6804f218bc49/pydantic_core-2.46.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:962ccbab7b642487b1d8b7df90ef677e03134cf1fd8880bf698649b22a69371f", size = 1951724, upload-time = "2026-05-06T13:37:02.697Z" }, + { url = "https://files.pythonhosted.org/packages/8e/bc/f47d1ff9cbb1620e1b5b697eef06010035735f07820180e74178226b27b3/pydantic_core-2.46.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8233f2947cf85404441fd7e0085f53b10c93e0ee78611099b5c7237e36aacbf7", size = 1975742, upload-time = "2026-05-06T13:37:09.448Z" }, + { url = "https://files.pythonhosted.org/packages/5b/11/9b9a5b0306345664a2da6410877af6e8082481b5884b3ddd78d47c6013ce/pydantic_core-2.46.4-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:3a233125ac121aa3ffba9a2b59edfc4a985a76092dc8279586ab4b71390875e7", size = 2052418, upload-time = "2026-05-06T13:37:38.234Z" }, + { url = "https://files.pythonhosted.org/packages/f1/b7/a65fec226f5d78fc39f4a13c4cc0c768c22b113438f60c14adc9d2865038/pydantic_core-2.46.4-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5b712b53160b79a5850310b912a5ef8e57e56947c8ad690c227f5c9d7e561712", size = 2232274, upload-time = "2026-05-06T13:38:27.753Z" }, + { url = "https://files.pythonhosted.org/packages/68/f0/92039db98b907ef49269a8271f67db9cb78ae2fc68062ef7e4e77adb5f61/pydantic_core-2.46.4-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9401557acd873c3a7f3eb9383edef8ac4968f9510e340f4808d427e75667e7b4", size = 2309940, upload-time = "2026-05-06T13:38:05.353Z" }, + { url = "https://files.pythonhosted.org/packages/5f/97/2aab507d3d00ca626e8e57c1eac6a79e4e5fbcc63eb99733ff55d1717f65/pydantic_core-2.46.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:926c9541b14b12b1681dca8a0b75feb510b06c6341b70a8e500c2fdcff837cce", size = 2094516, upload-time = "2026-05-06T13:39:10.577Z" }, + { url = "https://files.pythonhosted.org/packages/22/37/a8aca44d40d737dde2bc05b3c6c07dff0de07ce6f82e9f3167aeaf4d5dea/pydantic_core-2.46.4-cp312-cp312-manylinux_2_31_riscv64.whl", hash = "sha256:56cb4851bcaf3d117eddcef4fe66afd750a50274b0da8e22be256d10e5611987", size = 2136854, upload-time = "2026-05-06T13:40:22.59Z" }, + { url = "https://files.pythonhosted.org/packages/24/99/fcef1b79238c06a8cbec70819ac722ba76e02bc8ada9b0fd66eba40da01b/pydantic_core-2.46.4-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:c68fcd102d71ea85c5b2dfac3f4f8476eff42a9e078fd5faefff6d145063536b", size = 2180306, upload-time = "2026-05-06T13:40:10.666Z" }, + { url = "https://files.pythonhosted.org/packages/ae/6c/fc44000918855b42779d007ae63b0532794739027b2f417321cddbc44f6a/pydantic_core-2.46.4-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:b2f69dec1725e79a012d920df1707de5caf7ed5e08f3be4435e25803efc47458", size = 2190044, upload-time = "2026-05-06T13:40:43.231Z" }, + { url = "https://files.pythonhosted.org/packages/6b/65/d9cadc9f1920d7a127ad2edba16c1db7916e59719285cd6c94600b0080ba/pydantic_core-2.46.4-cp312-cp312-musllinux_1_1_armv7l.whl", hash = "sha256:8d0820e8192167f80d88d64038e609c31452eeca865b4e1d9950a27a4609b00b", size = 2329133, upload-time = "2026-05-06T13:39:57.365Z" }, + { url = "https://files.pythonhosted.org/packages/d0/cf/c873d91679f3a30bcf5e7ac280ce5573483e72295307685120d0d5ad3416/pydantic_core-2.46.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:fbdb89b3e1c94a30cc5edfce477c6e6a5dc4d8f84665b455c27582f211a1c72c", size = 2374464, upload-time = "2026-05-06T13:38:06.976Z" }, + { url = "https://files.pythonhosted.org/packages/47/bd/6f2fc8188f31bf10590f1e98e7b306336161fac930a8c514cd7bd828c7dc/pydantic_core-2.46.4-cp312-cp312-win32.whl", hash = "sha256:9aa768456404a8bf48a4406685ac2bec8e72b62c69313734fa3b73cf33b3a894", size = 1974823, upload-time = "2026-05-06T13:40:47.985Z" }, + { url = "https://files.pythonhosted.org/packages/40/8c/985c1d41ea1107c2534abd9870e4ed5c8e7669b5c308297835c001e7a1c4/pydantic_core-2.46.4-cp312-cp312-win_amd64.whl", hash = "sha256:e9c26f834c65f5752f3f06cb08cb86a913ceb7274d0db6e267808a708b46bc89", size = 2072919, upload-time = "2026-05-06T13:39:21.153Z" }, + { url = "https://files.pythonhosted.org/packages/c4/ba/f463d006e0c47373ca7ec5e1a261c59dc01ef4d62b2657af925fb0deee3a/pydantic_core-2.46.4-cp312-cp312-win_arm64.whl", hash = "sha256:4fc73cb559bdb54b1134a706a2802a4cddd27a0633f5abb7e53056268751ac6a", size = 2027604, upload-time = "2026-05-06T13:39:03.753Z" }, + { url = "https://files.pythonhosted.org/packages/51/a2/5d30b469c5267a17b39dec53208222f76a8d351dfac4af661888c5aee77d/pydantic_core-2.46.4-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:5d5902252db0d3cedf8d4a1bc68f70eeb430f7e4c7104c8c476753519b423008", size = 2106306, upload-time = "2026-05-06T13:37:48.029Z" }, + { url = "https://files.pythonhosted.org/packages/c1/81/4fa520eaffa8bd7d1525e644cd6d39e7d60b1592bc5b516693c7340b50f1/pydantic_core-2.46.4-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:c94f0688e7b8d0a67abf40e57a7eaaecd17cc9586706a31b76c031f63df052b4", size = 1951906, upload-time = "2026-05-06T13:37:17.012Z" }, + { url = "https://files.pythonhosted.org/packages/03/d5/fd02da45b659668b05923b17ba3a0100a0a3d5541e3bd8fcc4ecb711309e/pydantic_core-2.46.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f027324c56cd5406ca49c124b0db10e56c69064fec039acc571c29020cc87c76", size = 1976802, upload-time = "2026-05-06T13:37:35.113Z" }, + { url = "https://files.pythonhosted.org/packages/21/f2/95727e1368be3d3ed485eaab7adbd7dda408f33f7a36e8b48e0144002b91/pydantic_core-2.46.4-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:e739fee756ba1010f8bcccb534252e85a35fe45ae92c295a06059ce58b74ccd3", size = 2052446, upload-time = "2026-05-06T13:37:12.313Z" }, + { url = "https://files.pythonhosted.org/packages/9c/86/5d99feea3f77c7234b8718075b23db11532773c1a0dbd9b9490215dc2eeb/pydantic_core-2.46.4-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:9d56801be94b86a9da183e5f3766e6310752b99ff647e38b09a9500d88e46e76", size = 2232757, upload-time = "2026-05-06T13:39:01.149Z" }, + { url = "https://files.pythonhosted.org/packages/d2/3a/508ac615935ef7588cf6d9e9b91309fdc2da751af865e02a9098de88258c/pydantic_core-2.46.4-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2412e734dcb48da14d4e4006b82b46b74f2518b8a26ee7e58c6844a6cd6d03c4", size = 2309275, upload-time = "2026-05-06T13:37:41.406Z" }, + { url = "https://files.pythonhosted.org/packages/07/f8/41db9de19d7987d6b04715a02b3b40aea467000275d9d758ffaa31af7d50/pydantic_core-2.46.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9551187363ffc0de2a00b2e47c25aeaeb1020b69b668762966df15fc5659dd5a", size = 2094467, upload-time = "2026-05-06T13:39:18.847Z" }, + { url = "https://files.pythonhosted.org/packages/2c/e2/f35033184cb11d0052daf4416e8e10a502ea2ac006fc4f459aee872727d1/pydantic_core-2.46.4-cp313-cp313-manylinux_2_31_riscv64.whl", hash = "sha256:0186750b482eefa11d7f435892b09c5c606193ef3375bcf94aa00ae6bfb66262", size = 2134417, upload-time = "2026-05-06T13:40:17.944Z" }, + { url = "https://files.pythonhosted.org/packages/7e/7b/6ceeb1cc90e193862f444ebe373d8fdf613f0a82572dde03fb10734c6c71/pydantic_core-2.46.4-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:5855698a4856556d86e8e6cd8434bc3ac0314ee8e12089ae0e143f64c6256e4e", size = 2179782, upload-time = "2026-05-06T13:40:32.618Z" }, + { url = "https://files.pythonhosted.org/packages/5a/f2/c8d7773ede6af08036423a00ae0ceffce266c3c52a096c435d68c896083f/pydantic_core-2.46.4-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:cbaf13819775b7f769bf4a1f066cb6df7a28d4480081a589828ef190226881cd", size = 2188782, upload-time = "2026-05-06T13:36:51.018Z" }, + { url = "https://files.pythonhosted.org/packages/59/31/0c864784e31f09f05cdd87606f08923b9c9e7f6e51dd27f20f62f975ce9f/pydantic_core-2.46.4-cp313-cp313-musllinux_1_1_armv7l.whl", hash = "sha256:633147d34cf4550417f12e2b1a0383973bdf5cdfde212cb09e9a581cf10820be", size = 2328334, upload-time = "2026-05-06T13:40:37.764Z" }, + { url = "https://files.pythonhosted.org/packages/c2/eb/4f6c8a41efa30baa755590f4141abf3a8c370fab610915733e74134a7270/pydantic_core-2.46.4-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:82cf5301172168103724d49a1444d3378cb20cdee30b116a1bd6031236298a5d", size = 2372986, upload-time = "2026-05-06T13:39:34.152Z" }, + { url = "https://files.pythonhosted.org/packages/5b/24/b375a480d53113860c299764bfe9f349a3dc9108b3adc0d7f0d786492ebf/pydantic_core-2.46.4-cp313-cp313-win32.whl", hash = "sha256:9fa8ae11da9e2b3126c6426f147e0fba88d96d65921799bb30c6abd1cb2c97fb", size = 1973693, upload-time = "2026-05-06T13:37:55.072Z" }, + { url = "https://files.pythonhosted.org/packages/7e/e8/cff247591966f2d22ec8c003cd7587e27b7ba7b81ab2fb888e3ab75dc285/pydantic_core-2.46.4-cp313-cp313-win_amd64.whl", hash = "sha256:6b3ace8194b0e5204818c92802dcdca7fc6d88aabbb799d7c795540d9cd6d292", size = 2071819, upload-time = "2026-05-06T13:38:49.139Z" }, + { url = "https://files.pythonhosted.org/packages/c6/1a/f4aee670d5670e9e148e0c82c7db98d780be566c6e6a97ee8035528ca0b3/pydantic_core-2.46.4-cp313-cp313-win_arm64.whl", hash = "sha256:184c081504d17f1c1066e430e117142b2c77d9448a97f7b65c6ac9fd9aee238d", size = 2027411, upload-time = "2026-05-06T13:40:45.796Z" }, + { url = "https://files.pythonhosted.org/packages/9d/1d/8987ad40f65ae1432753072f214fb5c74fe47ffbd0698bb9cbbb585664f8/pydantic_core-2.46.4-graalpy312-graalpy250_312_native-macosx_10_12_x86_64.whl", hash = "sha256:1d8ba486450b14f3b1d63bc521d410ec7565e52f887b9fb671791886436a42f7", size = 2095527, upload-time = "2026-05-06T13:39:52.283Z" }, + { url = "https://files.pythonhosted.org/packages/64/d3/84c282a7eee1d3ac4c0377546ef5a1ea436ce26840d9ac3b7ed54a377507/pydantic_core-2.46.4-graalpy312-graalpy250_312_native-macosx_11_0_arm64.whl", hash = "sha256:3009f12e4e90b7f88b4f9adb1b0c4a3d58fe7820f3238c190047209d148026df", size = 1936024, upload-time = "2026-05-06T13:40:15.671Z" }, + { url = "https://files.pythonhosted.org/packages/d7/ca/eac61596cdeb4d7e174d3dc0bd8a6238f14f75f97a24e7b7db4c7e7340a0/pydantic_core-2.46.4-graalpy312-graalpy250_312_native-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ad785e92e6dc634c21555edc8bd6b64957ab844541bcb96a1366c202951ae526", size = 1990696, upload-time = "2026-05-06T13:38:34.717Z" }, + { url = "https://files.pythonhosted.org/packages/fa/c3/7c8b240552251faf6b3a957db200fcfbbcec36763c050428b601e0c9b83b/pydantic_core-2.46.4-graalpy312-graalpy250_312_native-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:00c603d540afdd6b80eb39f078f33ebd46211f02f33e34a32d9f053bba711de0", size = 2147590, upload-time = "2026-05-06T13:39:29.883Z" }, +] + [[package]] name = "pyright" version = "1.1.400" @@ -378,11 +347,9 @@ version = "8.3.5" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "colorama", marker = "sys_platform == 'win32'" }, - { name = "exceptiongroup", marker = "python_full_version < '3.11'" }, { name = "iniconfig" }, { name = "packaging" }, { name = "pluggy" }, - { name = "tomli", marker = "python_full_version < '3.11'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/ae/3c/c9d525a414d506893f0cd8a8d0de7706446213181570cdbd766691164e40/pytest-8.3.5.tar.gz", hash = "sha256:f4efe70cc14e511565ac476b57c279e12a855b11f48f212af1080ef2263d3845", size = 1450891, upload-time = "2025-03-02T12:54:54.503Z" } wheels = [ @@ -406,7 +373,7 @@ name = "pytest-cov" version = "6.1.1" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "coverage", extra = ["toml"] }, + { name = "coverage" }, { name = "pytest" }, ] sdist = { url = "https://files.pythonhosted.org/packages/25/69/5f1e57f6c5a39f81411b550027bf72842c4567ff5fd572bed1edc9e4b5d9/pytest_cov-6.1.1.tar.gz", hash = "sha256:46935f7aaefba760e716c2ebfbe1c216240b9592966e7da99ea8292d4d3e2a0a", size = 66857, upload-time = "2025-04-05T14:07:51.592Z" } @@ -468,18 +435,19 @@ dependencies = [ { name = "attrs" }, { name = "ciso8601" }, { name = "msgspec" }, + { name = "pydantic" }, ] [package.dev-dependencies] coverage = [ - { name = "coverage", extra = ["toml"] }, + { name = "coverage" }, ] dev = [ { name = "nox" }, ] dev-complete = [ { name = "asyncpg-stubs" }, - { name = "coverage", extra = ["toml"] }, + { name = "coverage" }, { name = "nox" }, { name = "pyright" }, { name = "pytest" }, @@ -490,7 +458,7 @@ dev-complete = [ ] pyright = [ { name = "asyncpg-stubs" }, - { name = "coverage", extra = ["toml"] }, + { name = "coverage" }, { name = "pyright" }, { name = "pytest" }, { name = "pytest-asyncio" }, @@ -498,7 +466,7 @@ pyright = [ { name = "pytest-dependency" }, ] pytest = [ - { name = "coverage", extra = ["toml"] }, + { name = "coverage" }, { name = "pytest" }, { name = "pytest-asyncio" }, { name = "pytest-cov" }, @@ -515,6 +483,7 @@ requires-dist = [ { name = "attrs", specifier = ">=25.3.0" }, { name = "ciso8601", specifier = ">=2.3.2" }, { name = "msgspec", specifier = ">=0.19.0" }, + { name = "pydantic", specifier = ">=2.9.0" }, ] [package.metadata.requires-dev] @@ -550,51 +519,24 @@ pytest = [ ruff = [{ name = "ruff", specifier = ">=0.11.9" }] [[package]] -name = "tomli" -version = "2.2.1" +name = "typing-extensions" +version = "4.16.0" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/18/87/302344fed471e44a87289cf4967697d07e532f2421fdaf868a303cbae4ff/tomli-2.2.1.tar.gz", hash = "sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff", size = 17175, upload-time = "2024-11-27T22:38:36.873Z" } +sdist = { url = "https://files.pythonhosted.org/packages/f6/cc/6253133b5bb138fc3306cebfbda2c520f545d36b5be2c7255cc528bb45d6/typing_extensions-4.16.0.tar.gz", hash = "sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5", size = 113555, upload-time = "2026-07-02T08:40:05.92Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/43/ca/75707e6efa2b37c77dadb324ae7d9571cb424e61ea73fad7c56c2d14527f/tomli-2.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249", size = 131077, upload-time = "2024-11-27T22:37:54.956Z" }, - { url = "https://files.pythonhosted.org/packages/c7/16/51ae563a8615d472fdbffc43a3f3d46588c264ac4f024f63f01283becfbb/tomli-2.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:023aa114dd824ade0100497eb2318602af309e5a55595f76b626d6d9f3b7b0a6", size = 123429, upload-time = "2024-11-27T22:37:56.698Z" }, - { url = "https://files.pythonhosted.org/packages/f1/dd/4f6cd1e7b160041db83c694abc78e100473c15d54620083dbd5aae7b990e/tomli-2.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ece47d672db52ac607a3d9599a9d48dcb2f2f735c6c2d1f34130085bb12b112a", size = 226067, upload-time = "2024-11-27T22:37:57.63Z" }, - { url = "https://files.pythonhosted.org/packages/a9/6b/c54ede5dc70d648cc6361eaf429304b02f2871a345bbdd51e993d6cdf550/tomli-2.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6972ca9c9cc9f0acaa56a8ca1ff51e7af152a9f87fb64623e31d5c83700080ee", size = 236030, upload-time = "2024-11-27T22:37:59.344Z" }, - { url = "https://files.pythonhosted.org/packages/1f/47/999514fa49cfaf7a92c805a86c3c43f4215621855d151b61c602abb38091/tomli-2.2.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c954d2250168d28797dd4e3ac5cf812a406cd5a92674ee4c8f123c889786aa8e", size = 240898, upload-time = "2024-11-27T22:38:00.429Z" }, - { url = "https://files.pythonhosted.org/packages/73/41/0a01279a7ae09ee1573b423318e7934674ce06eb33f50936655071d81a24/tomli-2.2.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:8dd28b3e155b80f4d54beb40a441d366adcfe740969820caf156c019fb5c7ec4", size = 229894, upload-time = "2024-11-27T22:38:02.094Z" }, - { url = "https://files.pythonhosted.org/packages/55/18/5d8bc5b0a0362311ce4d18830a5d28943667599a60d20118074ea1b01bb7/tomli-2.2.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:e59e304978767a54663af13c07b3d1af22ddee3bb2fb0618ca1593e4f593a106", size = 245319, upload-time = "2024-11-27T22:38:03.206Z" }, - { url = "https://files.pythonhosted.org/packages/92/a3/7ade0576d17f3cdf5ff44d61390d4b3febb8a9fc2b480c75c47ea048c646/tomli-2.2.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:33580bccab0338d00994d7f16f4c4ec25b776af3ffaac1ed74e0b3fc95e885a8", size = 238273, upload-time = "2024-11-27T22:38:04.217Z" }, - { url = "https://files.pythonhosted.org/packages/72/6f/fa64ef058ac1446a1e51110c375339b3ec6be245af9d14c87c4a6412dd32/tomli-2.2.1-cp311-cp311-win32.whl", hash = "sha256:465af0e0875402f1d226519c9904f37254b3045fc5084697cefb9bdde1ff99ff", size = 98310, upload-time = "2024-11-27T22:38:05.908Z" }, - { url = "https://files.pythonhosted.org/packages/6a/1c/4a2dcde4a51b81be3530565e92eda625d94dafb46dbeb15069df4caffc34/tomli-2.2.1-cp311-cp311-win_amd64.whl", hash = "sha256:2d0f2fdd22b02c6d81637a3c95f8cd77f995846af7414c5c4b8d0545afa1bc4b", size = 108309, upload-time = "2024-11-27T22:38:06.812Z" }, - { url = "https://files.pythonhosted.org/packages/52/e1/f8af4c2fcde17500422858155aeb0d7e93477a0d59a98e56cbfe75070fd0/tomli-2.2.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:4a8f6e44de52d5e6c657c9fe83b562f5f4256d8ebbfe4ff922c495620a7f6cea", size = 132762, upload-time = "2024-11-27T22:38:07.731Z" }, - { url = "https://files.pythonhosted.org/packages/03/b8/152c68bb84fc00396b83e7bbddd5ec0bd3dd409db4195e2a9b3e398ad2e3/tomli-2.2.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:8d57ca8095a641b8237d5b079147646153d22552f1c637fd3ba7f4b0b29167a8", size = 123453, upload-time = "2024-11-27T22:38:09.384Z" }, - { url = "https://files.pythonhosted.org/packages/c8/d6/fc9267af9166f79ac528ff7e8c55c8181ded34eb4b0e93daa767b8841573/tomli-2.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e340144ad7ae1533cb897d406382b4b6fede8890a03738ff1683af800d54192", size = 233486, upload-time = "2024-11-27T22:38:10.329Z" }, - { url = "https://files.pythonhosted.org/packages/5c/51/51c3f2884d7bab89af25f678447ea7d297b53b5a3b5730a7cb2ef6069f07/tomli-2.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:db2b95f9de79181805df90bedc5a5ab4c165e6ec3fe99f970d0e302f384ad222", size = 242349, upload-time = "2024-11-27T22:38:11.443Z" }, - { url = "https://files.pythonhosted.org/packages/ab/df/bfa89627d13a5cc22402e441e8a931ef2108403db390ff3345c05253935e/tomli-2.2.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:40741994320b232529c802f8bc86da4e1aa9f413db394617b9a256ae0f9a7f77", size = 252159, upload-time = "2024-11-27T22:38:13.099Z" }, - { url = "https://files.pythonhosted.org/packages/9e/6e/fa2b916dced65763a5168c6ccb91066f7639bdc88b48adda990db10c8c0b/tomli-2.2.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:400e720fe168c0f8521520190686ef8ef033fb19fc493da09779e592861b78c6", size = 237243, upload-time = "2024-11-27T22:38:14.766Z" }, - { url = "https://files.pythonhosted.org/packages/b4/04/885d3b1f650e1153cbb93a6a9782c58a972b94ea4483ae4ac5cedd5e4a09/tomli-2.2.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:02abe224de6ae62c19f090f68da4e27b10af2b93213d36cf44e6e1c5abd19fdd", size = 259645, upload-time = "2024-11-27T22:38:15.843Z" }, - { url = "https://files.pythonhosted.org/packages/9c/de/6b432d66e986e501586da298e28ebeefd3edc2c780f3ad73d22566034239/tomli-2.2.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:b82ebccc8c8a36f2094e969560a1b836758481f3dc360ce9a3277c65f374285e", size = 244584, upload-time = "2024-11-27T22:38:17.645Z" }, - { url = "https://files.pythonhosted.org/packages/1c/9a/47c0449b98e6e7d1be6cbac02f93dd79003234ddc4aaab6ba07a9a7482e2/tomli-2.2.1-cp312-cp312-win32.whl", hash = "sha256:889f80ef92701b9dbb224e49ec87c645ce5df3fa2cc548664eb8a25e03127a98", size = 98875, upload-time = "2024-11-27T22:38:19.159Z" }, - { url = "https://files.pythonhosted.org/packages/ef/60/9b9638f081c6f1261e2688bd487625cd1e660d0a85bd469e91d8db969734/tomli-2.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:7fc04e92e1d624a4a63c76474610238576942d6b8950a2d7f908a340494e67e4", size = 109418, upload-time = "2024-11-27T22:38:20.064Z" }, - { url = "https://files.pythonhosted.org/packages/04/90/2ee5f2e0362cb8a0b6499dc44f4d7d48f8fff06d28ba46e6f1eaa61a1388/tomli-2.2.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f4039b9cbc3048b2416cc57ab3bda989a6fcf9b36cf8937f01a6e731b64f80d7", size = 132708, upload-time = "2024-11-27T22:38:21.659Z" }, - { url = "https://files.pythonhosted.org/packages/c0/ec/46b4108816de6b385141f082ba99e315501ccd0a2ea23db4a100dd3990ea/tomli-2.2.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:286f0ca2ffeeb5b9bd4fcc8d6c330534323ec51b2f52da063b11c502da16f30c", size = 123582, upload-time = "2024-11-27T22:38:22.693Z" }, - { url = "https://files.pythonhosted.org/packages/a0/bd/b470466d0137b37b68d24556c38a0cc819e8febe392d5b199dcd7f578365/tomli-2.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a92ef1a44547e894e2a17d24e7557a5e85a9e1d0048b0b5e7541f76c5032cb13", size = 232543, upload-time = "2024-11-27T22:38:24.367Z" }, - { url = "https://files.pythonhosted.org/packages/d9/e5/82e80ff3b751373f7cead2815bcbe2d51c895b3c990686741a8e56ec42ab/tomli-2.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9316dc65bed1684c9a98ee68759ceaed29d229e985297003e494aa825ebb0281", size = 241691, upload-time = "2024-11-27T22:38:26.081Z" }, - { url = "https://files.pythonhosted.org/packages/05/7e/2a110bc2713557d6a1bfb06af23dd01e7dde52b6ee7dadc589868f9abfac/tomli-2.2.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e85e99945e688e32d5a35c1ff38ed0b3f41f43fad8df0bdf79f72b2ba7bc5272", size = 251170, upload-time = "2024-11-27T22:38:27.921Z" }, - { url = "https://files.pythonhosted.org/packages/64/7b/22d713946efe00e0adbcdfd6d1aa119ae03fd0b60ebed51ebb3fa9f5a2e5/tomli-2.2.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ac065718db92ca818f8d6141b5f66369833d4a80a9d74435a268c52bdfa73140", size = 236530, upload-time = "2024-11-27T22:38:29.591Z" }, - { url = "https://files.pythonhosted.org/packages/38/31/3a76f67da4b0cf37b742ca76beaf819dca0ebef26d78fc794a576e08accf/tomli-2.2.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:d920f33822747519673ee656a4b6ac33e382eca9d331c87770faa3eef562aeb2", size = 258666, upload-time = "2024-11-27T22:38:30.639Z" }, - { url = "https://files.pythonhosted.org/packages/07/10/5af1293da642aded87e8a988753945d0cf7e00a9452d3911dd3bb354c9e2/tomli-2.2.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:a198f10c4d1b1375d7687bc25294306e551bf1abfa4eace6650070a5c1ae2744", size = 243954, upload-time = "2024-11-27T22:38:31.702Z" }, - { url = "https://files.pythonhosted.org/packages/5b/b9/1ed31d167be802da0fc95020d04cd27b7d7065cc6fbefdd2f9186f60d7bd/tomli-2.2.1-cp313-cp313-win32.whl", hash = "sha256:d3f5614314d758649ab2ab3a62d4f2004c825922f9e370b29416484086b264ec", size = 98724, upload-time = "2024-11-27T22:38:32.837Z" }, - { url = "https://files.pythonhosted.org/packages/c7/32/b0963458706accd9afcfeb867c0f9175a741bf7b19cd424230714d722198/tomli-2.2.1-cp313-cp313-win_amd64.whl", hash = "sha256:a38aa0308e754b0e3c67e344754dff64999ff9b513e691d0e786265c93583c69", size = 109383, upload-time = "2024-11-27T22:38:34.455Z" }, - { url = "https://files.pythonhosted.org/packages/6e/c2/61d3e0f47e2b74ef40a68b9e6ad5984f6241a942f7cd3bbfbdbd03861ea9/tomli-2.2.1-py3-none-any.whl", hash = "sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc", size = 14257, upload-time = "2024-11-27T22:38:35.385Z" }, + { url = "https://files.pythonhosted.org/packages/49/d3/b8441a820a491ddfc024b0b0cf0393375b75ea13866d9c66727e54c2fc80/typing_extensions-4.16.0-py3-none-any.whl", hash = "sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8", size = 45571, upload-time = "2026-07-02T08:40:04.659Z" }, ] [[package]] -name = "typing-extensions" -version = "4.13.2" +name = "typing-inspection" +version = "0.4.2" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/f6/37/23083fcd6e35492953e8d2aaaa68b860eb422b34627b13f2ce3eb6106061/typing_extensions-4.13.2.tar.gz", hash = "sha256:e6c81219bd689f51865d9e372991c540bda33a0379d5573cddb9a3a23f7caaef", size = 106967, upload-time = "2025-04-10T14:19:05.416Z" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/55/e3/70399cb7dd41c10ac53367ae42139cf4b1ca5f36bb3dc6c9d33acdb43655/typing_inspection-0.4.2.tar.gz", hash = "sha256:ba561c48a67c5958007083d386c3295464928b01faa735ab8547c5692e87f464", size = 75949, upload-time = "2025-10-01T02:14:41.687Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/8b/54/b1ae86c0973cc6f0210b53d508ca3641fb6d0c56823f288d108bc7ab3cc8/typing_extensions-4.13.2-py3-none-any.whl", hash = "sha256:a439e7c04b49fec3e5d3e2beaa21755cadbbdc391694e28ccdd36ca4a1408f8c", size = 45806, upload-time = "2025-04-10T14:19:03.967Z" }, + { url = "https://files.pythonhosted.org/packages/dc/9b/47798a6c91d8bdb567fe2698fe81e0c6b7cb7ef4d13da4114b41d239f65d/typing_inspection-0.4.2-py3-none-any.whl", hash = "sha256:4ed1cacbdc298c220f1bd249ed5287caa16f34d44ef4e9c3d0cbad5b521545e7", size = 14611, upload-time = "2025-10-01T02:14:40.154Z" }, ] [[package]] @@ -605,7 +547,6 @@ dependencies = [ { name = "distlib" }, { name = "filelock" }, { name = "platformdirs" }, - { name = "typing-extensions", marker = "python_full_version < '3.11'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/aa/a3/4d310fa5f00863544e1d0f4de93bddec248499ccf97d4791bc3122c9d4f3/virtualenv-20.36.1.tar.gz", hash = "sha256:8befb5c81842c641f8ee658481e42641c68b5eab3521d8e092d18320902466ba", size = 6032239, upload-time = "2026-01-09T18:21:01.296Z" } wheels = [