Compare commits

...
22 Commits
Author SHA1 Message Date
hayodea e87c0fe8ec Stop regenerating openapitools.json in multiple folders 2026-06-11 19:41:49 -04:00
hayodea f2aa8d5c15 db_createfrom: Don't exec pre-/post-migration scripts 2026-06-11 19:29:19 -04:00
hayodea 13ce72f9e5 Env: generate .env file in builddir for DB_TARGET and vars 2026-06-11 19:16:12 -04:00
hayodea 21cdeedc84 Fix dependencies and commands to not regen on each source touch 2026-06-09 21:59:12 -04:00
hayodea 0872cb8078 Only generate headers for tables or something similar 2026-06-09 21:47:17 -04:00
hayodea f56b6b8989 Enum-only headers don't get generated so don't expect them 2026-06-05 15:59:55 -04:00
hayodea 9487dd4778 Something from adversarial review 2026-06-05 13:26:33 -04:00
hayodea b656569fc0 Support enum headers and other stuff 2026-06-05 12:53:05 -04:00
hayodea 6bb451dd94 Ignore node_modules/ 2026-05-24 05:13:37 -04:00
hayodea 588f847296 Fix tests 2026-05-01 04:50:49 -04:00
hayodea 254b7462ba Add tests db DB_TARGET for tests 2026-05-01 03:12:01 -04:00
hayodea c34b959b36 Add node pkg deps 2026-04-30 20:50:22 -04:00
hayodea 3d26d89742 Update readme 2026-04-30 00:17:20 -04:00
hayodea e00601c721 Make psql cli conditional dependency 2026-04-30 00:09:54 -04:00
hayodea e09625c466 Add PGSql tests 2026-04-29 23:49:07 -04:00
hayodea 68724dff8f Add migration commands for SQLite; not PGSql 2026-04-29 23:19:50 -04:00
hayodea e12ad0ecac Split db-gen targets; eradicate SCHEMA_DIR shorthand var 2026-04-29 21:32:35 -04:00
hayodea b16421fd08 Add docs/prommpts dir 2026-04-29 21:30:40 -04:00
hayodea 7e6e5f5081 Add AGENTS.md 2026-04-29 21:30:22 -04:00
hayodea f507cda960 README: Fix typo 2026-03-28 03:16:38 -04:00
hayodea 8df8a764b4 Add generated test-schema-v1.2 2026-03-03 12:18:50 -04:00
hayodea 419d8b2f9f CMake:Split up target-gen functions; tests:only apply snapshots and not migrations 2026-03-03 12:18:12 -04:00
146 changed files with 24799 additions and 242 deletions
+1
View File
@@ -1,3 +1,4 @@
# Ignore any directory named `db` or `build` anywhere in this repository.
**/build/
/b-*/
node_modules/
+11
View File
@@ -0,0 +1,11 @@
# Project Instructions
- Always break functions into logical subfunctions. No long-scrolling functions, in any language. This applies to source code, scripts, build scripts, CMake, Makefiles, and similar project files. Preserve this subfunction splitting discipline during refactors.
- Modularity is non-negotiable. Always group logically related functions together into a module. Preserve modularity during refactors.
- Reuse or extend existing abstractions instead of duplicating logic wherever possible. Don't repeat yourself. The goal here is to prevent duplication. Not to discourage appropriate logical separation of prior abstractions into new logical abstractions where sensible.
- Always isolate configurable behaviour into configuration variables appropriate for the language and framework being used.
- Never bake in literals; at minimum, declare them at the top of the file with a semantically meaningful name.
- UI should be responsive. Always prefer to use pre-packaged UI toolkit widgets, containers and colour sets harmoniously, instead of writing custom CSS overrides. Write custom CSS only if there's no UI toolkit mechanism available.
- Aggressively isolate, split off, deduplicate and reuse code which can be made into common library code. Do the same with UI elements. Do this both when implementing new features and opportunistically while refactoring or changing old code/UI elements.
- Names of files, functions, classes, abstractions, database fields, etc should be aimed at disambiguating purpose and function, rather than at brevity.
- Whenever a backend invariant changes; or in general whenever a backend feature/change can be automatically tested, add all tests reasonable, erring on the side of complete coverage over incomplete coverage.
+19 -4
View File
@@ -9,10 +9,25 @@ if(NOT DEFINED DB_SCHEMA_DIR_TO_GENERATE OR "${DB_SCHEMA_DIR_TO_GENERATE}" STREQ
"Set DB_SCHEMA_DIR_TO_GENERATE to the exact schema directory basename to test, for example -DDB_SCHEMA_DIR_TO_GENERATE=v1.2.")
endif()
set(CPPBESSOT_ODB_TEST_SQLITE_CONNSTR "" CACHE STRING
"Optional SQLite connection string for ODB runtime tests")
set(CPPBESSOT_ODB_TEST_PGSQL_CONNSTR "" CACHE STRING
"Optional PostgreSQL conninfo string for ODB runtime tests")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/dbDependencyCheck.cmake")
cppbessot_check_dependencies()
set(CPPBESSOT_DB_SQLITE_PROD_PATH "" CACHE STRING
"Optional SQLite DB path for DB_TARGET=prod")
set(CPPBESSOT_DB_SQLITE_DEV_PATH "" CACHE STRING
"Optional SQLite DB path for DB_TARGET=dev")
set(CPPBESSOT_DB_SQLITE_PRODDEV_PATH "" CACHE STRING
"Optional SQLite DB path for DB_TARGET=proddev")
set(CPPBESSOT_DB_SQLITE_TESTS_PATH "" CACHE STRING
"Optional SQLite DB path for DB_TARGET=tests")
set(CPPBESSOT_DB_PGSQL_PROD_CONNSTR "" CACHE STRING
"Optional PostgreSQL connstr for DB_TARGET=prod")
set(CPPBESSOT_DB_PGSQL_DEV_CONNSTR "" CACHE STRING
"Optional PostgreSQL connstr for DB_TARGET=dev")
set(CPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR "" CACHE STRING
"Optional PostgreSQL connstr for DB_TARGET=proddev")
set(CPPBESSOT_DB_PGSQL_TESTS_CONNSTR "" CACHE STRING
"Optional PostgreSQL connstr for DB_TARGET=tests")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CppBeSSOT.cmake")
+641 -82
View File
@@ -1,110 +1,669 @@
# CPPBESSOT (C++ BackEnd Single Source of Truth):
# cppbessot
A framework that uses OpenAI to maintain a single source of truth for the data model of a software project. It generates C++ headers, JSON serdes, ODB-based ORM headers, DB migrations, Typescript types and Zod schemas. I.e: a type-safe backend-to-frontend data model manager.
`cppbessot` is a CMake-driven schema pipeline for projects that keep their application data model in OpenAPI and need consistent generated artifacts across C++, TypeScript, Zod, ODB, SQL DDL, and database migrations.
Basically, it enables one to write a web application whose backend is written in C++. This C++ web application can communicate seamlessly with a Typescript frontend without losing type-safety. We leverage Zod to enforce type safety. So you get type-safety from end to end. From C++ through to the Typescript frontend.
The OpenAPI file under a schema directory is the single source of truth. From that, `cppbessot` can:
It works by specifying the data model in OpenAPI. Then the OpenAPI model is transpiled into both C++ headers (with JSON serdes and ODB ORM for your database of choice) and Typescript types with Zod schema descriptions.
- generate C++ model headers and JSON serdes sources
- generate ODB ORM sources for SQLite and PostgreSQL
- generate SQL DDL snapshots for SQLite and PostgreSQL
- generate TypeScript types
- generate Zod schemas
- generate SQL migration artifacts between two schema versions
- build linkable generated C++ libraries
- run live DB actions against `dev`, `prod`, `proddev`, or `tests`
## CMake integration
## Repository Layout
Reusable CMake entry point for embedding in a larger project:
The embedded module entry point is:
- `cmake/CppBeSSOT.cmake`
The primary schema root folder is configurable via:
- `CPPBESSOT_WORKDIR` (defaults to `db`)
This repo also carries self-contained schema fixtures for test runs:
The repo also ships test fixtures under:
- `db/test-schema-v1.1`
- `db/test-schema-v1.2`
## Simple Integration Guide
Each schema directory is expected to look roughly like this:
### 1) Add the module from your parent project
```text
<CPPBESSOT_WORKDIR>/<schema-dir>/
openapi/openapi.yaml
generated-cpp-source/
generated-odb-source/
generated-sql-ddl/
generated-ts-types/
generated-zod/
```
Migration artifacts live under:
```text
<CPPBESSOT_WORKDIR>/migrations/<from>-<to>/
sqlite/
postgre/
pre-structural-backfill.sh # optional
post-structural-backfill.sh # optional
```
## Configure-Time Requirements
`cppbessot` checks its dependencies during configure.
Always required:
- `git`
- `java`
- `npm`
- `npx`
- `odb`
- `sqlite3` CLI
- SQLite development headers and client library
- PostgreSQL development headers and client library
- `nlohmann_json`
- npm packages:
- `@openapitools/openapi-generator-cli`
- `openapi-zod-client`
Conditionally required:
- `psql`
- required when PostgreSQL live DB actions are configured
- required when real PostgreSQL db-action tests are configured
## Top-Level CMake Configuration
When configuring the standalone `cppbessot` repo itself, `DB_SCHEMA_DIR_TO_GENERATE` must be set explicitly:
```bash
cmake -S cmake/cppbessot -B build-cppbessot -DDB_SCHEMA_DIR_TO_GENERATE=test-schema-v1.2
```
The standalone top-level file also exposes these DB target mapping cache variables:
- `CPPBESSOT_DB_SQLITE_PROD_PATH`
- `CPPBESSOT_DB_SQLITE_DEV_PATH`
- `CPPBESSOT_DB_SQLITE_PRODDEV_PATH`
- `CPPBESSOT_DB_SQLITE_TESTS_PATH`
- `CPPBESSOT_DB_PGSQL_PROD_CONNSTR`
- `CPPBESSOT_DB_PGSQL_DEV_CONNSTR`
- `CPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR`
- `CPPBESSOT_DB_PGSQL_TESTS_CONNSTR`
## Embedding In A Parent Project
Minimal parent-project integration:
```cmake
# Parent project CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(MyApp LANGUAGES CXX)
cmake_minimum_required(VERSION 3.20)
project(my_app LANGUAGES CXX)
# Optional: where schema directories live (default is "db")
set(CPPBESSOT_WORKDIR "db")
# Required: exact schema directory basename under CPPBESSOT_WORKDIR
set(DB_SCHEMA_DIR_TO_GENERATE "v1.1")
# Optional: only needed if you will run db_gen_migrations
# set(DB_SCHEMA_DIR_MIGRATION_FROM "v1.1")
# set(DB_SCHEMA_DIR_MIGRATION_TO "v1.2")
set(DB_SCHEMA_DIR_TO_GENERATE "v1.2")
include(path/to/cppbessot/cmake/CppBeSSOT.cmake)
```
### 2) Build generation targets manually
By default, including `CppBeSSOT.cmake` auto-registers all generation targets, live DB action targets, and generated libraries.
```bash
cmake -S . -B build
cmake --build build --target db_gen_orm_serdes_and_zod
cmake --build build --target db_gen_sql_ddl
cmake --build build --target db_check_schema_changes
```
Optional migration generation:
```bash
cmake -S . -B build \
-DDB_SCHEMA_DIR_MIGRATION_FROM=v1.1 \
-DDB_SCHEMA_DIR_MIGRATION_TO=v1.2
cmake --build build --target db_gen_migrations
```
### 2b) Build the bundled serdes tests
These tests validate that checked-in generated C++ model code can be compiled and used for JSON round trips. They are owned by `cppbessot`, not by any parent project.
```bash
git submodule update --init --recursive tests/googletest
cmake -S . -B build-tests -DBUILD_TESTING=ON -DDB_SCHEMA_DIR_TO_GENERATE=test-schema-v1.2
cmake --build build-tests --target cpp_serdes_test_schema_v1_2
ctest --test-dir build-tests --output-on-failure
```
The local test fixtures live under `db/test-schema-v1.1` and `db/test-schema-v1.2`. They intentionally differ so migration generation has real additive schema changes to process.
For ODB runtime tests, also provide backend connection strings:
```bash
cmake -S . -B build-tests \
-DBUILD_TESTING=ON \
-DDB_SCHEMA_DIR_TO_GENERATE=test-schema-v1.1 \
-DCPPBESSOT_ODB_TEST_SQLITE_CONNSTR=/tmp/cppbessot-odb-test.sqlite \
-DCPPBESSOT_ODB_TEST_PGSQL_CONNSTR="host=127.0.0.1 port=5432 dbname=cppbessot_test user=postgres password=postgres"
cmake --build build-tests --target cpp_odb_orm_sqlite_test_schema_v1_1
cmake --build build-tests --target cpp_odb_orm_pgsql_test_schema_v1_1
ctest --test-dir build-tests --output-on-failure
```
Use a dedicated PostgreSQL test database. The ODB runtime tests recreate the schema.
The ODB runtime tests also verify hydration from ORM query result sets by persisting multiple rows, querying them back through `odb::result<T>`, and asserting that distinct field values are materialized correctly for both SQLite and PostgreSQL.
The configured CMake connstring values are baked into the test binaries as defaults, so direct binary execution works without exporting environment variables first. If the matching environment variable is set at runtime, it still overrides the compiled default.
### 3) Link generated libraries
```cmake
target_link_libraries(my_app PRIVATE
cppbessot::openai_model_gen
cppbessot::odb_sqlite # if sqlite odb sources exist
cppbessot::odb_pgsql # if postgre odb sources exist
)
```
### Optional manual enable mode
If you want manual control:
```cmake
set(CPPBESSOT_AUTO_ENABLE OFF)
include(path/to/cppbessot/cmake/CppBeSSOT.cmake)
cppbessot_enable()
```
## CMake Variables
### Core Schema Variables
- `CPPBESSOT_WORKDIR`
- default: `db`
- schema root folder, relative to `PROJECT_SOURCE_DIR` or absolute
- `DB_SCHEMA_DIR_TO_GENERATE`
- default in module mode: `v1.1`
- required in standalone top-level configure
- basename of the schema directory to generate artifacts for
- `DB_SCHEMA_DIR_MIGRATION_FROM`
- default: empty
- source schema basename for `db_gen_migrations`
- `DB_SCHEMA_DIR_MIGRATION_TO`
- default: empty
- target schema basename for `db_gen_migrations`
- `CPPBESSOT_GEN_MIGRATION_BACKENDS`
- default: `sqlite;pgsql`
- ODB backends for `db_gen_migrations`
- supported values: `sqlite`, `pgsql`
- `pgsql` writes artifacts under the historical `postgre` output directory
- compatibility alias: `CPPBESSOT_GEN_MIGRATIONS_BACKENDS`
- `DB_SCHEMA_CHANGES_ARE_ERROR`
- default: `OFF`
- used by schema-drift checking logic
- `CPPBESSOT_AUTO_ENABLE`
- default: `ON`
- when `ON`, including `CppBeSSOT.cmake` immediately registers targets and libraries
### Live DB Action Variables
- `DB_TARGET`
- default: `dev`
- selected live DB target for `db_createfrom` and `db_migrate`
- allowed values: `prod`, `proddev`, `dev`, `tests`
- `DB_CREATEFROM_SCHEMA_DIR`
- default: `DB_SCHEMA_DIR_TO_GENERATE`
- schema basename whose generated SQL DDL should be used by `db_createfrom`
- `DB_MIGRATE_WITH`
- default: empty
- migration directory basename under `<CPPBESSOT_WORKDIR>/migrations`
- example: `v1.1-v1.2`
- `DB_MIGRATE_PRODDEV_USE_STALE`
- default: `OFF`
- when `ON` and `DB_TARGET=proddev`, reuse the existing proddev target instead of recloning from prod
### SQLite Live DB Mapping Variables
Exactly one backend mapping must be set for the selected `DB_TARGET`.
- `CPPBESSOT_DB_SQLITE_PROD_PATH`
- `CPPBESSOT_DB_SQLITE_DEV_PATH`
- `CPPBESSOT_DB_SQLITE_PRODDEV_PATH`
- `CPPBESSOT_DB_SQLITE_TESTS_PATH`
These point at the SQLite DB file to act on for `prod`, `dev`, `proddev`, or `tests`.
### PostgreSQL Live DB Mapping Variables
- `CPPBESSOT_DB_PGSQL_PROD_CONNSTR`
- `CPPBESSOT_DB_PGSQL_DEV_CONNSTR`
- `CPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR`
- `CPPBESSOT_DB_PGSQL_TESTS_CONNSTR`
These are `psql`-compatible PostgreSQL connection strings for `prod`, `dev`, `proddev`, or `tests`.
### Prod-To-Proddev Clone Hook Variables
These are only needed for `DB_TARGET=proddev` when `DB_MIGRATE_PRODDEV_USE_STALE=OFF`.
- `CPPBESSOT_DB_SQLITE_CLONE_PROD_TO_PRODDEV_COMMAND`
- `CPPBESSOT_DB_PGSQL_CLONE_PROD_TO_PRODDEV_COMMAND`
They must be shell command strings that clone the `prod` database into `proddev` for the chosen backend.
## Command Targets
All custom targets are `EXCLUDE_FROM_ALL`, so they run only when explicitly requested or when a dependent library is built.
### `db_check_schema_changes`
Purpose:
- checks for git-tracked schema changes under `CPPBESSOT_WORKDIR`
Primary variables:
- `CPPBESSOT_WORKDIR`
- `DB_SCHEMA_CHANGES_ARE_ERROR`
Output:
- no generated files
- emits success/failure diagnostics about dirty schema state
### `db_gen_ts`
Purpose:
- generates TypeScript types from `openapi/openapi.yaml`
Primary variables:
- `CPPBESSOT_WORKDIR`
- `DB_SCHEMA_DIR_TO_GENERATE`
Output:
- `<CPPBESSOT_WORKDIR>/<schema>/generated-ts-types/`
### `db_gen_zod`
Purpose:
- generates Zod schemas from `openapi/openapi.yaml`
Primary variables:
- `CPPBESSOT_WORKDIR`
- `DB_SCHEMA_DIR_TO_GENERATE`
Output:
- `<CPPBESSOT_WORKDIR>/<schema>/generated-zod/schemas.ts`
### `db_gen_cpp_headers`
Purpose:
- generates C++ model headers and JSON serdes/model sources from OpenAPI
Primary variables:
- `CPPBESSOT_WORKDIR`
- `DB_SCHEMA_DIR_TO_GENERATE`
Output:
- `<CPPBESSOT_WORKDIR>/<schema>/generated-cpp-source/include/`
- `<CPPBESSOT_WORKDIR>/<schema>/generated-cpp-source/src/`
### `db_gen_odb_logic`
Purpose:
- generates ODB ORM sources for both SQLite and PostgreSQL
- depends on `db_gen_cpp_headers`
Primary variables:
- `CPPBESSOT_WORKDIR`
- `DB_SCHEMA_DIR_TO_GENERATE`
Output:
- `<CPPBESSOT_WORKDIR>/<schema>/generated-odb-source/sqlite/`
- `<CPPBESSOT_WORKDIR>/<schema>/generated-odb-source/postgre/`
### `db_gen_sql_ddl`
Purpose:
- generates SQL DDL snapshots for both SQLite and PostgreSQL
- depends on `db_gen_cpp_headers`
Primary variables:
- `CPPBESSOT_WORKDIR`
- `DB_SCHEMA_DIR_TO_GENERATE`
Output:
- `<CPPBESSOT_WORKDIR>/<schema>/generated-sql-ddl/sqlite/`
- `<CPPBESSOT_WORKDIR>/<schema>/generated-sql-ddl/postgre/`
### `db_gen_migrations`
Purpose:
- generates migration SQL artifacts between two schema versions
Primary variables:
- `CPPBESSOT_WORKDIR`
- `DB_SCHEMA_DIR_MIGRATION_FROM`
- `DB_SCHEMA_DIR_MIGRATION_TO`
- `CPPBESSOT_GEN_MIGRATION_BACKENDS`
Output:
- `<CPPBESSOT_WORKDIR>/migrations/<from>-<to>/sqlite/`
- `<CPPBESSOT_WORKDIR>/migrations/<from>-<to>/postgre/`
Notes:
- `from` and `to` must differ
- if either migration variable is empty, `db_gen_migrations` is still registered but intentionally fails with guidance
- enum-only generated C++ headers are skipped; only headers with ODB object pragmas produce migration SQL
- missing source-version changelog XML means the target-version model is treated as a new table and generated from an empty changelog baseline
- PostgreSQL migrations remain incremental when source-version changelog XML exists
- SQLite migrations remain incremental except when ODB reports SQLite's drop-column limitation; in that case only that model is regenerated from the empty changelog baseline with a warning
- for production upgrades, PostgreSQL migration SQL is the meaningful upgrade path; SQLite greenfield fallback artifacts are generated for tree completeness, not as a guaranteed runnable SQLite upgrade path
### `db_gen_orm_serdes_and_zod`
Purpose:
- aggregate generation target
Runs:
- `db_gen_ts`
- `db_gen_zod`
- `db_gen_cpp_headers`
- `db_gen_odb_logic`
- `db_gen_sql_ddl`
Output:
- no unique output of its own
- produces the union of the five generation targets above
### `db_createfrom`
Purpose:
- recreates a live `dev` or `prod` database from pre-generated SQL DDL artifacts
Primary variables:
- `DB_TARGET`
- `DB_CREATEFROM_SCHEMA_DIR`
- one backend mapping for the selected target
Behavior:
- `DB_TARGET=proddev` is illegal and aborts
- validates that `DB_CREATEFROM_SCHEMA_DIR` exists and has `openapi/openapi.yaml`
- chooses backend by inspecting the selected target mapping
- requires non-empty SQL files under:
- `<schema>/generated-sql-ddl/sqlite/`, or
- `<schema>/generated-sql-ddl/postgre/`
- SQLite path:
- deletes the current DB file if it exists
- recreates parent directories
- applies non-empty `.sql` files in sorted order using `sqlite3`
- PostgreSQL path:
- resets the `public` schema in the target DB
- applies non-empty `.sql` files in sorted order using `psql`
Output:
- a recreated live database matching the chosen schema snapshot
### `db_migrate`
Purpose:
- applies a generated migration directory, plus optional backfill hooks, to the selected live DB target
Primary variables:
- `DB_TARGET`
- `DB_MIGRATE_WITH`
- `DB_MIGRATE_PRODDEV_USE_STALE`
- one backend mapping for the selected target
- optional clone hook variable for `proddev`
Behavior:
- validates that `<CPPBESSOT_WORKDIR>/migrations/<DB_MIGRATE_WITH>` exists
- chooses backend by inspecting the selected target mapping
- for `DB_TARGET=proddev`:
- if `DB_MIGRATE_PRODDEV_USE_STALE=OFF`, runs the configured clone command first
- if `DB_MIGRATE_PRODDEV_USE_STALE=ON`, requires that the stale proddev target already exists
- hook order:
1. `pre-structural-backfill.sh` if present
2. non-empty structural SQL files for the selected backend if present
3. `post-structural-backfill.sh` if present
- hooks run with these environment variables:
- `CPPBESSOT_DB_TARGET`
- `CPPBESSOT_DB_BACKEND`
- `CPPBESSOT_DB_MIGRATION_DIR`
- `CPPBESSOT_DB_MIGRATE_WITH`
- `CPPBESSOT_DB_SCHEMA_DIR_TO_GENERATE`
- `CPPBESSOT_DB_CREATEFROM_SCHEMA_DIR`
- `CPPBESSOT_DB_SQLITE_PATH`
- `CPPBESSOT_DB_PGSQL_CONNSTR`
Output:
- a migrated live database for the selected target
## Generated Library Targets
### `cppbessot_add_generated_cpp_model_libraries()`
Registers:
- `cppBeSsotOpenAiModelGen`
- alias `cppbessot::openai_model_gen`
Behavior:
- depends on `db_gen_cpp_headers`
- building a consumer that links `cppbessot::openai_model_gen` forces model generation first
Consumes generated output from:
- `<schema>/generated-cpp-source/include/`
- `<schema>/generated-cpp-source/src/`
### `cppbessot_add_generated_odb_libraries()`
Registers:
- `cppBeSsotOdbSqlite`
- `cppBeSsotOdbPgSql`
- aliases:
- `cppbessot::odb_sqlite`
- `cppbessot::odb_pgsql`
Behavior:
- depends on `db_gen_odb_logic`
- also depends on `db_gen_sql_ddl` so ORM libs stay aligned with the same schema generation pass
- building a consumer that links these libs forces ODB generation first
Consumes generated output from:
- `<schema>/generated-cpp-source/include/`
- `<schema>/generated-odb-source/sqlite/`
- `<schema>/generated-odb-source/postgre/`
### `cppbessot_add_generated_libraries()`
Registers all three generated libraries above.
This is the umbrella library-registration entry point used by `cppbessot_enable()`.
## Sample Workflows
### 1. Generate Everything For One Schema
```bash
cmake -S . -B build \
-DDB_SCHEMA_DIR_TO_GENERATE=v1.2
cmake --build build --target db_gen_orm_serdes_and_zod
```
This produces:
- `generated-ts-types`
- `generated-zod`
- `generated-cpp-source`
- `generated-odb-source`
- `generated-sql-ddl`
### 2. Generate Migration Artifacts Between Two Schemas
```bash
cmake -S . -B build \
-DDB_SCHEMA_DIR_TO_GENERATE=v1.2 \
-DDB_SCHEMA_DIR_MIGRATION_FROM=v1.1 \
-DDB_SCHEMA_DIR_MIGRATION_TO=v1.2
cmake --build build --target db_gen_migrations
```
This writes migration SQL under:
- `db/migrations/v1.1-v1.2/sqlite/`
- `db/migrations/v1.1-v1.2/postgre/`
### 3. Link Only The Generated C++ Model Library
```cmake
target_link_libraries(my_app PRIVATE cppbessot::openai_model_gen)
```
That is valid if your application wants generated C++ models and JSON serdes but does not want ODB ORM libraries.
### 4. Link The Full Generated C++ Stack
```cmake
target_link_libraries(my_app PRIVATE
cppbessot::openai_model_gen
cppbessot::odb_sqlite
cppbessot::odb_pgsql
)
```
### 5. Create A Fresh SQLite `dev` Database From The Current Schema
```bash
cmake -S . -B build \
-DDB_SCHEMA_DIR_TO_GENERATE=v1.2 \
-DDB_TARGET=dev \
-DCPPBESSOT_DB_SQLITE_DEV_PATH=/tmp/myapp-dev.sqlite
cmake --build build --target db_gen_sql_ddl
cmake --build build --target db_createfrom
```
This recreates `/tmp/myapp-dev.sqlite` from:
- `db/v1.2/generated-sql-ddl/sqlite/`
### 6. Create A Fresh PostgreSQL `prod` Database Schema Snapshot
```bash
cmake -S . -B build \
-DDB_SCHEMA_DIR_TO_GENERATE=v1.2 \
-DDB_TARGET=prod \
-DCPPBESSOT_DB_PGSQL_PROD_CONNSTR="host=127.0.0.1 port=5432 dbname=myapp_prod user=postgres password=postgres"
cmake --build build --target db_gen_sql_ddl
cmake --build build --target db_createfrom
```
This resets the `public` schema in the target PostgreSQL DB, then reapplies the generated DDL.
### 7. Migrate A SQLite `dev` Database With Optional Backfills
```bash
cmake -S . -B build \
-DDB_SCHEMA_DIR_TO_GENERATE=v1.2 \
-DDB_TARGET=dev \
-DDB_MIGRATE_WITH=v1.1-v1.2 \
-DCPPBESSOT_DB_SQLITE_DEV_PATH=/tmp/myapp-dev.sqlite
cmake --build build --target db_migrate
```
If present, these run in order:
1. `db/migrations/v1.1-v1.2/pre-structural-backfill.sh`
2. non-empty SQL files under `db/migrations/v1.1-v1.2/sqlite/`
3. `db/migrations/v1.1-v1.2/post-structural-backfill.sh`
### 8. Migrate A `proddev` Clone From `prod`
SQLite example:
```bash
cmake -S . -B build \
-DDB_SCHEMA_DIR_TO_GENERATE=v1.2 \
-DDB_TARGET=proddev \
-DDB_MIGRATE_WITH=v1.1-v1.2 \
-DCPPBESSOT_DB_SQLITE_PROD_PATH=/srv/myapp/prod.sqlite \
-DCPPBESSOT_DB_SQLITE_PRODDEV_PATH=/srv/myapp/proddev.sqlite \
-DCPPBESSOT_DB_SQLITE_CLONE_PROD_TO_PRODDEV_COMMAND='cp /srv/myapp/prod.sqlite /srv/myapp/proddev.sqlite'
cmake --build build --target db_migrate
```
PostgreSQL example:
```bash
cmake -S . -B build \
-DDB_SCHEMA_DIR_TO_GENERATE=v1.2 \
-DDB_TARGET=proddev \
-DDB_MIGRATE_WITH=v1.1-v1.2 \
-DCPPBESSOT_DB_PGSQL_PROD_CONNSTR="host=127.0.0.1 port=5432 dbname=myapp_prod user=postgres password=postgres" \
-DCPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR="host=127.0.0.1 port=5432 dbname=myapp_proddev user=postgres password=postgres" \
-DCPPBESSOT_DB_PGSQL_CLONE_PROD_TO_PRODDEV_COMMAND='psql "host=127.0.0.1 port=5432 dbname=postgres user=postgres password=postgres" -v ON_ERROR_STOP=1 -c "DROP DATABASE IF EXISTS myapp_proddev;" -c "CREATE DATABASE myapp_proddev TEMPLATE myapp_prod;"'
cmake --build build --target db_migrate
```
### 9. Reuse An Existing Stale `proddev`
```bash
cmake -S . -B build \
-DDB_SCHEMA_DIR_TO_GENERATE=v1.2 \
-DDB_TARGET=proddev \
-DDB_MIGRATE_WITH=v1.1-v1.2 \
-DDB_MIGRATE_PRODDEV_USE_STALE=ON \
-DCPPBESSOT_DB_SQLITE_PRODDEV_PATH=/srv/myapp/proddev.sqlite
cmake --build build --target db_migrate
```
This skips the clone step and aborts if the stale target does not already exist.
## Testing
### Configure The Standalone Repo For Tests
```bash
git -C cmake/cppbessot submodule update --init --recursive tests/googletest
cmake -S cmake/cppbessot -B build-cppbessot-tests \
-DBUILD_TESTING=ON \
-DDB_SCHEMA_DIR_TO_GENERATE=test-schema-v1.2
```
### Run All Registered Tests
```bash
ctest --test-dir build-cppbessot-tests --output-on-failure
```
### ODB Runtime Tests
Provide DB target mappings:
```bash
cmake -S cmake/cppbessot -B build-cppbessot-tests \
-DBUILD_TESTING=ON \
-DDB_SCHEMA_DIR_TO_GENERATE=test-schema-v1.2 \
-DCPPBESSOT_DB_SQLITE_PRODDEV_PATH=/tmp/cppbessot-odb.sqlite \
-DCPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR="host=127.0.0.1 port=5432 dbname=cppbessot_odb_test user=postgres password=postgres"
```
### Real PostgreSQL DB-Action Tests
These tests are only registered when all of the following are true:
- `BUILD_TESTING=ON`
- `psql` is available
- the required target connstr variables for the individual test are non-empty
Example:
```bash
cmake -S cmake/cppbessot -B build-cppbessot-tests \
-DBUILD_TESTING=ON \
-DDB_SCHEMA_DIR_TO_GENERATE=test-schema-v1.2 \
-DCPPBESSOT_DB_PGSQL_DEV_CONNSTR="host=127.0.0.1 port=5432 dbname=cppbessot_dev user=postgres password=postgres" \
-DCPPBESSOT_DB_PGSQL_PROD_CONNSTR="host=127.0.0.1 port=5432 dbname=cppbessot_prod user=postgres password=postgres" \
-DCPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR="host=127.0.0.1 port=5432 dbname=cppbessot_proddev user=postgres password=postgres"
ctest --test-dir build-cppbessot-tests -R 'cppbessot_db_action_pgsql_.*_real' --output-on-failure
```
## Notes
- Schema directory names must be basenames, not paths.
- `DB_TARGET` must resolve to exactly one backend mapping.
- `db_createfrom` and `db_migrate` operate on pre-generated SQL artifacts. If those artifacts are stale, regenerate them first.
- The PostgreSQL live-action path resets the `public` schema. Use dedicated databases and be deliberate with `prod` mappings.
+204 -65
View File
@@ -1,6 +1,5 @@
include_guard(GLOBAL)
include(CMakeParseArguments)
include("${CMAKE_CURRENT_LIST_DIR}/dbGenerationCommon.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/dbDependencyCheck.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/dbSchemaCheck.cmake")
@@ -10,6 +9,10 @@ include("${CMAKE_CURRENT_LIST_DIR}/dbGenCpp.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/dbGenODB.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/dbGenSqlDDL.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/dbGenMigrations.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/dbActionCommon.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/dbActionCreateFrom.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/dbActionMigrate.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/dbRuntimeEnv.cmake")
if(NOT DEFINED CPPBESSOT_WORKDIR)
set(CPPBESSOT_WORKDIR "db" CACHE STRING "CppBeSSOT schema root folder")
@@ -29,10 +32,64 @@ if(NOT DEFINED DB_SCHEMA_DIR_MIGRATION_TO)
"Optional target schema directory basename for migration generation")
endif()
if(NOT DEFINED CPPBESSOT_GEN_MIGRATION_BACKENDS)
if(DEFINED CPPBESSOT_GEN_MIGRATIONS_BACKENDS)
set(CPPBESSOT_GEN_MIGRATION_BACKENDS "${CPPBESSOT_GEN_MIGRATIONS_BACKENDS}")
else()
set(CPPBESSOT_GEN_MIGRATION_BACKENDS "sqlite;pgsql")
endif()
endif()
set(CPPBESSOT_GEN_MIGRATION_BACKENDS "${CPPBESSOT_GEN_MIGRATION_BACKENDS}" CACHE STRING
"ODB backends for db_gen_migrations; supported values: sqlite, pgsql")
set(CPPBESSOT_GEN_MIGRATIONS_BACKENDS "${CPPBESSOT_GEN_MIGRATION_BACKENDS}" CACHE STRING
"Compatibility alias for CPPBESSOT_GEN_MIGRATION_BACKENDS" FORCE)
if(NOT DEFINED DB_SCHEMA_CHANGES_ARE_ERROR)
option(DB_SCHEMA_CHANGES_ARE_ERROR "Treat dirty schema changes as hard CMake error" OFF)
endif()
if(NOT DEFINED DB_TARGET)
set(DB_TARGET "dev" CACHE STRING "Live DB target to act on: prod, proddev, dev, or tests")
endif()
if(NOT DEFINED DB_CREATEFROM_SCHEMA_DIR)
set(DB_CREATEFROM_SCHEMA_DIR "${DB_SCHEMA_DIR_TO_GENERATE}" CACHE STRING
"Schema directory basename under CPPBESSOT_WORKDIR to create a live DB from")
endif()
if(NOT DEFINED DB_MIGRATE_WITH)
set(DB_MIGRATE_WITH "" CACHE STRING
"Migration directory basename under CPPBESSOT_WORKDIR/migrations to apply to the selected DB target")
endif()
if(NOT DEFINED DB_MIGRATE_PRODDEV_USE_STALE)
option(DB_MIGRATE_PRODDEV_USE_STALE "Reuse an existing stale proddev clone instead of recloning from prod" OFF)
endif()
set(CPPBESSOT_DB_SQLITE_PROD_PATH "${CPPBESSOT_DB_SQLITE_PROD_PATH}" CACHE STRING
"Parent-supplied SQLite DB path for DB_TARGET=prod")
set(CPPBESSOT_DB_SQLITE_DEV_PATH "${CPPBESSOT_DB_SQLITE_DEV_PATH}" CACHE STRING
"Parent-supplied SQLite DB path for DB_TARGET=dev")
set(CPPBESSOT_DB_SQLITE_PRODDEV_PATH "${CPPBESSOT_DB_SQLITE_PRODDEV_PATH}" CACHE STRING
"Parent-supplied SQLite DB path for DB_TARGET=proddev")
set(CPPBESSOT_DB_SQLITE_TESTS_PATH "${CPPBESSOT_DB_SQLITE_TESTS_PATH}" CACHE STRING
"Parent-supplied SQLite DB path for DB_TARGET=tests")
set(CPPBESSOT_DB_PGSQL_PROD_CONNSTR "${CPPBESSOT_DB_PGSQL_PROD_CONNSTR}" CACHE STRING
"Parent-supplied PostgreSQL connection string for DB_TARGET=prod")
set(CPPBESSOT_DB_PGSQL_DEV_CONNSTR "${CPPBESSOT_DB_PGSQL_DEV_CONNSTR}" CACHE STRING
"Parent-supplied PostgreSQL connection string for DB_TARGET=dev")
set(CPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR "${CPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR}" CACHE STRING
"Parent-supplied PostgreSQL connection string for DB_TARGET=proddev")
set(CPPBESSOT_DB_PGSQL_TESTS_CONNSTR "${CPPBESSOT_DB_PGSQL_TESTS_CONNSTR}" CACHE STRING
"Parent-supplied PostgreSQL connection string for DB_TARGET=tests")
set(CPPBESSOT_DB_SQLITE_CLONE_PROD_TO_PRODDEV_COMMAND "${CPPBESSOT_DB_SQLITE_CLONE_PROD_TO_PRODDEV_COMMAND}" CACHE STRING
"Parent-supplied command string that clones the prod SQLite DB into proddev")
set(CPPBESSOT_DB_PGSQL_CLONE_PROD_TO_PRODDEV_COMMAND "${CPPBESSOT_DB_PGSQL_CLONE_PROD_TO_PRODDEV_COMMAND}" CACHE STRING
"Parent-supplied command string that clones the prod PostgreSQL DB into proddev")
cppbessot_write_runtime_env_file("${CMAKE_BINARY_DIR}/cppbessot.env")
if(NOT DEFINED CPPBESSOT_AUTO_ENABLE)
option(CPPBESSOT_AUTO_ENABLE "Auto-register CppBeSSOT targets when this file is included" ON)
endif()
@@ -48,11 +105,145 @@ function(_cppbessot_try_link_nlohmann target_name)
endif()
endfunction()
function(_cppbessot_assert_generation_targets_registered consumer_name)
# Purpose: Ensure split public library registration functions are only used
# after generation targets are registered (typically via cppbessot_enable()).
# Inputs:
# - consumer_name: Human-readable function name for diagnostics.
# Outputs:
# - No return value; raises FATAL_ERROR when prerequisites are missing.
if(NOT TARGET db_gen_cpp_headers OR NOT TARGET db_gen_odb_logic OR NOT TARGET db_gen_sql_ddl)
message(FATAL_ERROR
"${consumer_name} requires generation targets to be registered first. "
"Call cppbessot_enable() before invoking split generated-library registration functions.")
endif()
endfunction()
function(_cppbessot_add_generated_model_library cpp_include_dir expected_model_headers expected_model_sources)
set_source_files_properties(${expected_model_headers} ${expected_model_sources}
PROPERTIES GENERATED TRUE)
add_library(cppBeSsotOpenAiModelGen STATIC ${expected_model_sources})
add_dependencies(cppBeSsotOpenAiModelGen db_gen_cpp_headers)
set_target_properties(cppBeSsotOpenAiModelGen PROPERTIES
OUTPUT_NAME "cppBeSsotOpenAiModelGen"
POSITION_INDEPENDENT_CODE ON)
target_include_directories(cppBeSsotOpenAiModelGen PUBLIC "${cpp_include_dir}")
_cppbessot_try_link_nlohmann(cppBeSsotOpenAiModelGen)
add_library(cppbessot::openai_model_gen ALIAS cppBeSsotOpenAiModelGen)
endfunction()
function(_cppbessot_add_generated_sqlite_library
cpp_include_dir
model_leaf_include_dir
version_dir
expected_sqlite_odb_sources)
set_source_files_properties(${expected_sqlite_odb_sources} PROPERTIES GENERATED TRUE)
add_library(cppBeSsotOdbSqlite SHARED ${expected_sqlite_odb_sources})
# Keep the ODB library aligned with the SQL snapshots emitted from the same schema generation pass.
add_dependencies(cppBeSsotOdbSqlite
db_gen_odb_logic
db_gen_sql_ddl)
set_target_properties(cppBeSsotOdbSqlite PROPERTIES
OUTPUT_NAME "cppBeSsotOdbSqlite"
POSITION_INDEPENDENT_CODE ON)
target_include_directories(cppBeSsotOdbSqlite PUBLIC
"${cpp_include_dir}"
"${model_leaf_include_dir}"
"${version_dir}/generated-odb-source/sqlite"
"${CPPBESSOT_SQLITE_INCLUDE_DIR}")
target_link_libraries(cppBeSsotOdbSqlite PUBLIC
"${CPPBESSOT_ODB_RUNTIME_LIB}"
"${CPPBESSOT_ODB_SQLITE_RUNTIME_LIB}")
add_library(cppbessot::odb_sqlite ALIAS cppBeSsotOdbSqlite)
endfunction()
function(_cppbessot_add_generated_pgsql_library
cpp_include_dir
model_leaf_include_dir
version_dir
expected_pgsql_odb_sources)
set_source_files_properties(${expected_pgsql_odb_sources} PROPERTIES GENERATED TRUE)
add_library(cppBeSsotOdbPgSql SHARED ${expected_pgsql_odb_sources})
# Keep the ODB library aligned with the SQL snapshots emitted from the same schema generation pass.
add_dependencies(cppBeSsotOdbPgSql
db_gen_odb_logic
db_gen_sql_ddl)
set_target_properties(cppBeSsotOdbPgSql PROPERTIES
OUTPUT_NAME "cppBeSsotOdbPgSql"
POSITION_INDEPENDENT_CODE ON)
target_include_directories(cppBeSsotOdbPgSql PUBLIC
"${cpp_include_dir}"
"${model_leaf_include_dir}"
"${version_dir}/generated-odb-source/postgre"
"${CPPBESSOT_PGSQL_INCLUDE_DIR}")
target_link_libraries(cppBeSsotOdbPgSql PUBLIC
"${CPPBESSOT_ODB_RUNTIME_LIB}"
"${CPPBESSOT_ODB_PGSQL_RUNTIME_LIB}")
add_library(cppbessot::odb_pgsql ALIAS cppBeSsotOdbPgSql)
endfunction()
function(cppbessot_add_generated_cpp_model_libraries)
# Purpose: Create consumable C++ model library from generated model sources.
# Inputs:
# - DB_SCHEMA_DIR_TO_GENERATE: Schema directory basename under CPPBESSOT_WORKDIR.
# Outputs:
# - Library target:
# - cppBeSsotOpenAiModelGen
# - Alias target:
# - cppbessot::openai_model_gen
_cppbessot_assert_generation_targets_registered("cppbessot_add_generated_cpp_model_libraries")
cppbessot_validate_schema_dir_name("${DB_SCHEMA_DIR_TO_GENERATE}")
cppbessot_get_schema_dir_path(_version_dir "${DB_SCHEMA_DIR_TO_GENERATE}")
set(_cpp_include_dir "${_version_dir}/generated-cpp-source/include")
cppbessot_get_expected_cpp_model_outputs(
_expected_model_headers
_expected_model_sources
"${DB_SCHEMA_DIR_TO_GENERATE}")
_cppbessot_add_generated_model_library(
"${_cpp_include_dir}"
"${_expected_model_headers}"
"${_expected_model_sources}")
endfunction()
function(cppbessot_add_generated_odb_libraries)
# Purpose: Create consumable ODB libraries from generated ODB sources.
# Inputs:
# - DB_SCHEMA_DIR_TO_GENERATE: Schema directory basename under CPPBESSOT_WORKDIR.
# Outputs:
# - Library targets:
# - cppBeSsotOdbSqlite
# - cppBeSsotOdbPgSql
# - Alias targets:
# - cppbessot::odb_sqlite
# - cppbessot::odb_pgsql
_cppbessot_assert_generation_targets_registered("cppbessot_add_generated_odb_libraries")
cppbessot_validate_schema_dir_name("${DB_SCHEMA_DIR_TO_GENERATE}")
cppbessot_get_schema_dir_path(_version_dir "${DB_SCHEMA_DIR_TO_GENERATE}")
set(_cpp_include_dir "${_version_dir}/generated-cpp-source/include")
set(_model_leaf_include_dir "${_cpp_include_dir}/cppbessot/model")
cppbessot_get_expected_odb_outputs(
_expected_sqlite_odb_sources
_expected_pgsql_odb_sources
"${DB_SCHEMA_DIR_TO_GENERATE}")
_cppbessot_add_generated_sqlite_library(
"${_cpp_include_dir}"
"${_model_leaf_include_dir}"
"${_version_dir}"
"${_expected_sqlite_odb_sources}")
_cppbessot_add_generated_pgsql_library(
"${_cpp_include_dir}"
"${_model_leaf_include_dir}"
"${_version_dir}"
"${_expected_pgsql_odb_sources}")
endfunction()
function(cppbessot_add_generated_libraries)
# Purpose: Create consumable libraries from generated model and ODB sources.
# Inputs:
# - SCHEMA_DIR (optional named arg): Schema directory basename to consume.
# - DB_SCHEMA_DIR_TO_GENERATE (fallback): Default schema directory basename.
# - DB_SCHEMA_DIR_TO_GENERATE: Schema directory basename under CPPBESSOT_WORKDIR.
# Outputs:
# - Library targets (when sources exist):
# - cppBeSsotOpenAiModelGen
@@ -62,66 +253,8 @@ function(cppbessot_add_generated_libraries)
# - cppbessot::openai_model_gen
# - cppbessot::odb_sqlite
# - cppbessot::odb_pgsql
# - Emits warnings if expected source sets are missing.
set(options)
set(one_value_args SCHEMA_DIR)
set(multi_value_args)
cmake_parse_arguments(CPPB "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
if(NOT CPPB_SCHEMA_DIR)
set(CPPB_SCHEMA_DIR "${DB_SCHEMA_DIR_TO_GENERATE}")
endif()
cppbessot_validate_schema_dir_name("${CPPB_SCHEMA_DIR}")
cppbessot_get_schema_dir_path(_version_dir "${CPPB_SCHEMA_DIR}")
set(_cpp_include_dir "${_version_dir}/generated-cpp-source/include")
set(_model_leaf_include_dir "${_cpp_include_dir}/cppbessot/model")
cppbessot_get_expected_cpp_model_outputs(_expected_model_headers _expected_model_sources "${CPPB_SCHEMA_DIR}")
cppbessot_get_expected_odb_outputs(_expected_sqlite_odb_sources _expected_pgsql_odb_sources "${CPPB_SCHEMA_DIR}")
set_source_files_properties(${_expected_model_headers} ${_expected_model_sources}
PROPERTIES GENERATED TRUE)
add_library(cppBeSsotOpenAiModelGen STATIC ${_expected_model_sources})
add_dependencies(cppBeSsotOpenAiModelGen db_gen_cpp_headers)
set_target_properties(cppBeSsotOpenAiModelGen PROPERTIES
OUTPUT_NAME "cppBeSsotOpenAiModelGen"
POSITION_INDEPENDENT_CODE ON)
target_include_directories(cppBeSsotOpenAiModelGen PUBLIC "${_cpp_include_dir}")
_cppbessot_try_link_nlohmann(cppBeSsotOpenAiModelGen)
add_library(cppbessot::openai_model_gen ALIAS cppBeSsotOpenAiModelGen)
set_source_files_properties(${_expected_sqlite_odb_sources} PROPERTIES GENERATED TRUE)
add_library(cppBeSsotOdbSqlite SHARED ${_expected_sqlite_odb_sources})
add_dependencies(cppBeSsotOdbSqlite db_gen_odb_logic)
set_target_properties(cppBeSsotOdbSqlite PROPERTIES
OUTPUT_NAME "cppBeSsotOdbSqlite"
POSITION_INDEPENDENT_CODE ON)
target_include_directories(cppBeSsotOdbSqlite PUBLIC
"${_cpp_include_dir}"
"${_model_leaf_include_dir}"
"${_version_dir}/generated-odb-source/sqlite"
"${CPPBESSOT_SQLITE_INCLUDE_DIR}")
target_link_libraries(cppBeSsotOdbSqlite PUBLIC
"${CPPBESSOT_ODB_RUNTIME_LIB}"
"${CPPBESSOT_ODB_SQLITE_RUNTIME_LIB}")
add_library(cppbessot::odb_sqlite ALIAS cppBeSsotOdbSqlite)
set_source_files_properties(${_expected_pgsql_odb_sources} PROPERTIES GENERATED TRUE)
add_library(cppBeSsotOdbPgSql SHARED ${_expected_pgsql_odb_sources})
add_dependencies(cppBeSsotOdbPgSql db_gen_odb_logic)
set_target_properties(cppBeSsotOdbPgSql PROPERTIES
OUTPUT_NAME "cppBeSsotOdbPgSql"
POSITION_INDEPENDENT_CODE ON)
target_include_directories(cppBeSsotOdbPgSql PUBLIC
"${_cpp_include_dir}"
"${_model_leaf_include_dir}"
"${_version_dir}/generated-odb-source/postgre"
"${CPPBESSOT_PGSQL_INCLUDE_DIR}")
target_link_libraries(cppBeSsotOdbPgSql PUBLIC
"${CPPBESSOT_ODB_RUNTIME_LIB}"
"${CPPBESSOT_ODB_PGSQL_RUNTIME_LIB}")
add_library(cppbessot::odb_pgsql ALIAS cppBeSsotOdbPgSql)
cppbessot_add_generated_cpp_model_libraries()
cppbessot_add_generated_odb_libraries()
endfunction()
function(cppbessot_enable)
@@ -132,6 +265,7 @@ function(cppbessot_enable)
# - DB_SCHEMA_DIR_TO_GENERATE
# - DB_SCHEMA_DIR_MIGRATION_FROM
# - DB_SCHEMA_DIR_MIGRATION_TO
# - CPPBESSOT_GEN_MIGRATION_BACKENDS
# - DB_SCHEMA_CHANGES_ARE_ERROR (optional behavior control)
# Outputs:
# - Custom targets:
@@ -143,11 +277,14 @@ function(cppbessot_enable)
# - db_gen_sql_ddl
# - db_gen_migrations
# - db_gen_orm_serdes_and_zod
# - db_createfrom
# - db_migrate
# - Generated library targets for selected schema version.
cppbessot_initialize_paths()
cppbessot_validate_schema_dir_name("${DB_SCHEMA_DIR_TO_GENERATE}")
cppbessot_assert_schema_dir_exists("${DB_SCHEMA_DIR_TO_GENERATE}")
cppbessot_assert_openapi_exists("${DB_SCHEMA_DIR_TO_GENERATE}")
cppbessot_check_dependencies()
@@ -171,7 +308,7 @@ function(cppbessot_enable)
COMMAND "${CMAKE_COMMAND}" -E echo
"Set DB_SCHEMA_DIR_MIGRATION_FROM and DB_SCHEMA_DIR_MIGRATION_TO to enable migration generation."
COMMAND "${CMAKE_COMMAND}" -E false
VERBATIM
VERBATIM
)
set_target_properties(db_gen_migrations PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
@@ -185,7 +322,9 @@ function(cppbessot_enable)
db_gen_sql_ddl)
set_target_properties(db_gen_orm_serdes_and_zod PROPERTIES EXCLUDE_FROM_ALL TRUE)
cppbessot_add_generated_libraries(SCHEMA_DIR "${DB_SCHEMA_DIR_TO_GENERATE}")
cppbessot_add_db_createfrom_target()
cppbessot_add_db_migrate_target()
cppbessot_add_generated_libraries()
endfunction()
if(CPPBESSOT_AUTO_ENABLE)
+55
View File
@@ -0,0 +1,55 @@
include_guard(GLOBAL)
include("${CMAKE_CURRENT_LIST_DIR}/dbGenerationCommon.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/dbActionShared.cmake")
function(cppbessot_validate_db_target db_target)
_cppbessot_db_action_validate_db_target_impl("${db_target}")
endfunction()
function(cppbessot_validate_migration_dir_name migration_dir)
_cppbessot_db_action_validate_basename(
"${migration_dir}"
"Migration directory name"
"CPPBESSOT_WORKDIR/migrations")
endfunction()
function(cppbessot_get_migration_dir_path out_var migration_dir)
cppbessot_validate_migration_dir_name("${migration_dir}")
cppbessot_abs_path(_workdir "${CPPBESSOT_WORKDIR}")
set(${out_var} "${_workdir}/migrations/${migration_dir}" PARENT_SCOPE)
endfunction()
function(cppbessot_assert_migration_dir_exists migration_dir)
cppbessot_get_migration_dir_path(_migration_dir_path "${migration_dir}")
if(NOT IS_DIRECTORY "${_migration_dir_path}")
message(FATAL_ERROR "Migration directory does not exist: ${_migration_dir_path}")
endif()
endfunction()
function(_cppbessot_db_action_common_cache_args out_var)
set(_args
"-DCPPBESSOT_PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}"
"-DCPPBESSOT_WORKDIR=${CPPBESSOT_WORKDIR}"
"-DDB_SCHEMA_DIR_TO_GENERATE=${DB_SCHEMA_DIR_TO_GENERATE}"
"-DDB_CREATEFROM_SCHEMA_DIR=${DB_CREATEFROM_SCHEMA_DIR}"
"-DDB_TARGET=${DB_TARGET}"
"-DCPPBESSOT_DB_SQLITE_PROD_PATH=${CPPBESSOT_DB_SQLITE_PROD_PATH}"
"-DCPPBESSOT_DB_SQLITE_DEV_PATH=${CPPBESSOT_DB_SQLITE_DEV_PATH}"
"-DCPPBESSOT_DB_SQLITE_PRODDEV_PATH=${CPPBESSOT_DB_SQLITE_PRODDEV_PATH}"
"-DCPPBESSOT_DB_SQLITE_TESTS_PATH=${CPPBESSOT_DB_SQLITE_TESTS_PATH}"
"-DCPPBESSOT_DB_PGSQL_PROD_CONNSTR=${CPPBESSOT_DB_PGSQL_PROD_CONNSTR}"
"-DCPPBESSOT_DB_PGSQL_DEV_CONNSTR=${CPPBESSOT_DB_PGSQL_DEV_CONNSTR}"
"-DCPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR=${CPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR}"
"-DCPPBESSOT_DB_PGSQL_TESTS_CONNSTR=${CPPBESSOT_DB_PGSQL_TESTS_CONNSTR}")
set(${out_var} "${_args}" PARENT_SCOPE)
endfunction()
function(_cppbessot_add_db_action_target target_name script_path comment_text)
add_custom_target(${target_name}
COMMAND "${CMAKE_COMMAND}" ${ARGN} -P "${script_path}"
COMMENT "${comment_text}"
VERBATIM
)
set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
endfunction()
+13
View File
@@ -0,0 +1,13 @@
include_guard(GLOBAL)
include("${CMAKE_CURRENT_LIST_DIR}/dbActionCommon.cmake")
set(_CPPBESSOT_DB_ACTION_CREATEFROM_DIR "${CMAKE_CURRENT_LIST_DIR}")
function(cppbessot_add_db_createfrom_target)
_cppbessot_db_action_common_cache_args(_common_args)
_cppbessot_add_db_action_target(
db_createfrom
"${_CPPBESSOT_DB_ACTION_CREATEFROM_DIR}/scripts/run_db_createfrom.cmake"
"Creating live DB target `${DB_TARGET}` from schema `${DB_CREATEFROM_SCHEMA_DIR}`"
${_common_args})
endfunction()
+17
View File
@@ -0,0 +1,17 @@
include_guard(GLOBAL)
include("${CMAKE_CURRENT_LIST_DIR}/dbActionCommon.cmake")
set(_CPPBESSOT_DB_ACTION_MIGRATE_DIR "${CMAKE_CURRENT_LIST_DIR}")
function(cppbessot_add_db_migrate_target)
_cppbessot_db_action_common_cache_args(_common_args)
_cppbessot_add_db_action_target(
db_migrate
"${_CPPBESSOT_DB_ACTION_MIGRATE_DIR}/scripts/run_db_migrate.cmake"
"Migrating live DB target `${DB_TARGET}` using migration `${DB_MIGRATE_WITH}`"
${_common_args}
"-DDB_MIGRATE_WITH=${DB_MIGRATE_WITH}"
"-DDB_MIGRATE_PRODDEV_USE_STALE=${DB_MIGRATE_PRODDEV_USE_STALE}"
"-DCPPBESSOT_DB_SQLITE_CLONE_PROD_TO_PRODDEV_COMMAND=${CPPBESSOT_DB_SQLITE_CLONE_PROD_TO_PRODDEV_COMMAND}"
"-DCPPBESSOT_DB_PGSQL_CLONE_PROD_TO_PRODDEV_COMMAND=${CPPBESSOT_DB_PGSQL_CLONE_PROD_TO_PRODDEV_COMMAND}")
endfunction()
+21
View File
@@ -0,0 +1,21 @@
include_guard(GLOBAL)
function(_cppbessot_db_action_validate_basename value kind relative_root)
if("${value}" STREQUAL "")
message(FATAL_ERROR "${kind} must not be empty.")
endif()
if("${value}" MATCHES "[/\\\\]")
message(FATAL_ERROR
"${kind} `${value}` must be a basename under ${relative_root}, not a path.")
endif()
endfunction()
function(_cppbessot_db_action_validate_db_target_impl db_target)
if(NOT "${db_target}" STREQUAL "prod"
AND NOT "${db_target}" STREQUAL "proddev"
AND NOT "${db_target}" STREQUAL "dev"
AND NOT "${db_target}" STREQUAL "tests")
message(FATAL_ERROR "DB_TARGET must be one of: prod, proddev, dev, tests.")
endif()
endfunction()
+53 -14
View File
@@ -4,6 +4,23 @@ include("${CMAKE_CURRENT_LIST_DIR}/dbGenerationCommon.cmake")
include(CheckIncludeFileCXX)
include(CMakePushCheckState)
function(_cppbessot_publish_dependency_outputs)
set(CPPBESSOT_ODB_EXECUTABLE "${CPPBESSOT_ODB_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_NPX_EXECUTABLE "${CPPBESSOT_NPX_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_NPM_EXECUTABLE "${CPPBESSOT_NPM_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_JAVA_EXECUTABLE "${CPPBESSOT_JAVA_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_GIT_EXECUTABLE "${CPPBESSOT_GIT_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_SQLITE3_EXECUTABLE "${CPPBESSOT_SQLITE3_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_ODB_RUNTIME_LIB "${CPPBESSOT_ODB_RUNTIME_LIB}" PARENT_SCOPE)
set(CPPBESSOT_ODB_SQLITE_RUNTIME_LIB "${CPPBESSOT_ODB_SQLITE_RUNTIME_LIB}" PARENT_SCOPE)
set(CPPBESSOT_ODB_PGSQL_RUNTIME_LIB "${CPPBESSOT_ODB_PGSQL_RUNTIME_LIB}" PARENT_SCOPE)
set(CPPBESSOT_SQLITE_INCLUDE_DIR "${CPPBESSOT_SQLITE_INCLUDE_DIR}" PARENT_SCOPE)
set(CPPBESSOT_PGSQL_INCLUDE_DIR "${CPPBESSOT_PGSQL_INCLUDE_DIR}" PARENT_SCOPE)
set(CPPBESSOT_SQLITE_CLIENT_LIB "${CPPBESSOT_SQLITE_CLIENT_LIB}" PARENT_SCOPE)
set(CPPBESSOT_PGSQL_CLIENT_LIB "${CPPBESSOT_PGSQL_CLIENT_LIB}" PARENT_SCOPE)
set(CPPBESSOT_OPENAPI_ZOD_AVAILABLE TRUE PARENT_SCOPE)
endfunction()
function(_cppbessot_require_program var_name program_name hint)
# Purpose: Locate an executable and fail with a clear install hint if missing.
# Inputs:
@@ -20,6 +37,17 @@ function(_cppbessot_require_program var_name program_name hint)
endif()
endfunction()
function(_cppbessot_any_nonempty_var out_var)
foreach(_var_name IN LISTS ARGN)
if(DEFINED ${_var_name} AND NOT "${${_var_name}}" STREQUAL "")
set(${out_var} TRUE PARENT_SCOPE)
return()
endif()
endforeach()
set(${out_var} FALSE PARENT_SCOPE)
endfunction()
function(_cppbessot_require_npm_package npm_executable package_name)
# Purpose: Ensure an npm package exists either locally in PROJECT_SOURCE_DIR
# or globally in the active npm installation.
@@ -28,9 +56,10 @@ function(_cppbessot_require_npm_package npm_executable package_name)
# - package_name: Package name to validate.
# Outputs:
# - No return value; raises FATAL_ERROR when package is not installed.
cppbessot_get_module_root(_module_root)
execute_process(
COMMAND "${npm_executable}" list --depth=0 "${package_name}"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
WORKING_DIRECTORY "${_module_root}"
RESULT_VARIABLE _local_result
OUTPUT_QUIET
ERROR_QUIET
@@ -62,8 +91,10 @@ function(_cppbessot_require_npx_package_executable npx_executable package_execut
# - package_executable: Executable name exposed by a package.
# Outputs:
# - No return value; raises FATAL_ERROR if execution fails.
cppbessot_get_module_root(_module_root)
execute_process(
COMMAND "${npx_executable}" --no-install "${package_executable}" --help
WORKING_DIRECTORY "${_module_root}"
RESULT_VARIABLE _help_result
OUTPUT_QUIET
ERROR_VARIABLE _help_stderr
@@ -76,6 +107,7 @@ function(_cppbessot_require_npx_package_executable npx_executable package_execut
# Some CLIs return non-zero for --help; verify with version as fallback.
execute_process(
COMMAND "${npx_executable}" --no-install "${package_executable}" version
WORKING_DIRECTORY "${_module_root}"
RESULT_VARIABLE _version_result
OUTPUT_QUIET
ERROR_VARIABLE _version_stderr
@@ -101,6 +133,12 @@ function(cppbessot_check_dependencies)
# - CPPBESSOT_GIT_EXECUTABLE (PARENT_SCOPE)
# - CPPBESSOT_OPENAPI_ZOD_AVAILABLE (PARENT_SCOPE)
# - No return value; raises FATAL_ERROR on missing dependencies.
get_property(_cppbessot_dependencies_checked GLOBAL PROPERTY CPPBESSOT_DEPENDENCIES_CHECKED)
if(_cppbessot_dependencies_checked)
_cppbessot_publish_dependency_outputs()
return()
endif()
_cppbessot_require_program(CPPBESSOT_ODB_EXECUTABLE odb
"Install ODB compiler and ensure `odb` is in PATH.")
_cppbessot_require_program(CPPBESSOT_NPX_EXECUTABLE npx
@@ -111,6 +149,18 @@ function(cppbessot_check_dependencies)
"Install a Java runtime (OpenAPI generator uses Java).")
_cppbessot_require_program(CPPBESSOT_GIT_EXECUTABLE git
"Install Git and ensure it is available in PATH.")
_cppbessot_require_program(CPPBESSOT_SQLITE3_EXECUTABLE sqlite3
"Install the SQLite CLI so live SQLite DB actions can apply SQL files.")
_cppbessot_any_nonempty_var(
_cppbessot_require_psql
CPPBESSOT_DB_PGSQL_PROD_CONNSTR
CPPBESSOT_DB_PGSQL_DEV_CONNSTR
CPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR
CPPBESSOT_DB_PGSQL_TESTS_CONNSTR)
if(_cppbessot_require_psql)
_cppbessot_require_program(_cppbessot_psql_executable psql
"Install the PostgreSQL client CLI so live PostgreSQL DB actions can run.")
endif()
_cppbessot_require_npm_package("${CPPBESSOT_NPM_EXECUTABLE}" "@openapitools/openapi-generator-cli")
_cppbessot_require_npx_package_executable("${CPPBESSOT_NPX_EXECUTABLE}" "@openapitools/openapi-generator-cli")
@@ -187,17 +237,6 @@ function(cppbessot_check_dependencies)
"PostgreSQL client library was not found. On Ubuntu/Debian install package `libpq-dev`.")
endif()
set(CPPBESSOT_ODB_EXECUTABLE "${CPPBESSOT_ODB_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_NPX_EXECUTABLE "${CPPBESSOT_NPX_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_NPM_EXECUTABLE "${CPPBESSOT_NPM_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_JAVA_EXECUTABLE "${CPPBESSOT_JAVA_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_GIT_EXECUTABLE "${CPPBESSOT_GIT_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_ODB_RUNTIME_LIB "${CPPBESSOT_ODB_RUNTIME_LIB}" PARENT_SCOPE)
set(CPPBESSOT_ODB_SQLITE_RUNTIME_LIB "${CPPBESSOT_ODB_SQLITE_RUNTIME_LIB}" PARENT_SCOPE)
set(CPPBESSOT_ODB_PGSQL_RUNTIME_LIB "${CPPBESSOT_ODB_PGSQL_RUNTIME_LIB}" PARENT_SCOPE)
set(CPPBESSOT_SQLITE_INCLUDE_DIR "${CPPBESSOT_SQLITE_INCLUDE_DIR}" PARENT_SCOPE)
set(CPPBESSOT_PGSQL_INCLUDE_DIR "${CPPBESSOT_PGSQL_INCLUDE_DIR}" PARENT_SCOPE)
set(CPPBESSOT_SQLITE_CLIENT_LIB "${CPPBESSOT_SQLITE_CLIENT_LIB}" PARENT_SCOPE)
set(CPPBESSOT_PGSQL_CLIENT_LIB "${CPPBESSOT_PGSQL_CLIENT_LIB}" PARENT_SCOPE)
set(CPPBESSOT_OPENAPI_ZOD_AVAILABLE TRUE PARENT_SCOPE)
set_property(GLOBAL PROPERTY CPPBESSOT_DEPENDENCIES_CHECKED TRUE)
_cppbessot_publish_dependency_outputs()
endfunction()
+11 -7
View File
@@ -1,7 +1,6 @@
include_guard(GLOBAL)
include("${CMAKE_CURRENT_LIST_DIR}/dbGenerationCommon.cmake")
set(_CPPBESSOT_DB_GEN_CPP_DIR "${CMAKE_CURRENT_LIST_DIR}")
function(cppbessot_add_db_gen_cpp_target schema_dir)
# Purpose: Register C++ model generation target using checked-in templates.
@@ -13,19 +12,20 @@ function(cppbessot_add_db_gen_cpp_target schema_dir)
# - Files under `<schema_dir>/generated-cpp-source`.
cppbessot_validate_schema_dir_name("${schema_dir}")
cppbessot_get_schema_dir_path(_version_dir "${schema_dir}")
if(DEFINED CPPBESSOT_MODULE_ROOT AND NOT "${CPPBESSOT_MODULE_ROOT}" STREQUAL "")
set(_module_root "${CPPBESSOT_MODULE_ROOT}")
else()
get_filename_component(_module_root "${_CPPBESSOT_DB_GEN_CPP_DIR}/.." ABSOLUTE)
endif()
cppbessot_get_module_root(_module_root)
set(_openapi_file "${_version_dir}/openapi/openapi.yaml")
set(_template_dir "${_module_root}/openapi/templates/cpp-odb-json")
set(_template_config "${_template_dir}/config.yaml")
set(_output_dir "${_version_dir}/generated-cpp-source")
file(GLOB_RECURSE _template_inputs CONFIGURE_DEPENDS "${_template_dir}/*")
cppbessot_get_expected_cpp_model_outputs(
_expected_model_headers
_expected_model_sources
"${schema_dir}")
add_custom_target(db_gen_cpp_headers
add_custom_command(
OUTPUT ${_expected_model_headers} ${_expected_model_sources}
COMMAND ${CMAKE_COMMAND} -E make_directory "${_output_dir}"
COMMAND "${CPPBESSOT_NPX_EXECUTABLE}" @openapitools/openapi-generator-cli generate
-i "${_openapi_file}"
@@ -35,9 +35,13 @@ function(cppbessot_add_db_gen_cpp_target schema_dir)
-o "${_output_dir}"
--global-property models
DEPENDS "${_openapi_file}" ${_template_inputs}
WORKING_DIRECTORY "${_module_root}"
COMMENT "Generating C++ model headers/sources for ${schema_dir}"
VERBATIM
)
add_custom_target(db_gen_cpp_headers
DEPENDS ${_expected_model_headers} ${_expected_model_sources})
set_target_properties(db_gen_cpp_headers PROPERTIES EXCLUDE_FROM_ALL TRUE)
endfunction()
+6 -4
View File
@@ -9,6 +9,7 @@ function(cppbessot_add_db_gen_migrations_target from_schema_dir to_schema_dir)
# - from_schema_dir: Source schema directory basename.
# - to_schema_dir: Target schema directory basename.
# - CPPBESSOT_ODB_EXECUTABLE: Path to `odb` compiler.
# - CPPBESSOT_GEN_MIGRATION_BACKENDS: List of ODB backends to generate.
# Outputs:
# - CMake target: `db_gen_migrations` (EXCLUDE_FROM_ALL).
# - Files under `migrations/<from>-<to>/{sqlite,postgre}`.
@@ -26,10 +27,11 @@ function(cppbessot_add_db_gen_migrations_target from_schema_dir to_schema_dir)
add_custom_target(db_gen_migrations
COMMAND "${CMAKE_COMMAND}"
-DCPPBESSOT_ODB_EXECUTABLE=${CPPBESSOT_ODB_EXECUTABLE}
-DCPPBESSOT_FROM_VERSION_DIR=${_from_dir}
-DCPPBESSOT_TO_VERSION_DIR=${_to_dir}
-DCPPBESSOT_MIGRATION_DIR=${_migration_dir}
"-DCPPBESSOT_ODB_EXECUTABLE=${CPPBESSOT_ODB_EXECUTABLE}"
"-DCPPBESSOT_FROM_VERSION_DIR=${_from_dir}"
"-DCPPBESSOT_TO_VERSION_DIR=${_to_dir}"
"-DCPPBESSOT_MIGRATION_DIR=${_migration_dir}"
"-DCPPBESSOT_GEN_MIGRATION_BACKENDS=${CPPBESSOT_GEN_MIGRATION_BACKENDS}"
-P "${_CPPBESSOT_DB_GEN_MIGRATIONS_DIR}/scripts/run_odb_migrations.cmake"
COMMENT "Generating DB migrations: ${from_schema_dir} -> ${to_schema_dir}"
VERBATIM
+12 -2
View File
@@ -13,16 +13,26 @@ function(cppbessot_add_db_gen_odb_target schema_dir)
# - Files under `<schema_dir>/generated-odb-source/{sqlite,postgre}`.
cppbessot_validate_schema_dir_name("${schema_dir}")
cppbessot_get_schema_dir_path(_version_dir "${schema_dir}")
cppbessot_get_expected_odb_generation_artifacts(
_expected_odb_model_headers
_expected_odb_sources
"${schema_dir}")
_cppbessot_get_openapi_file_path(_openapi_file "${schema_dir}")
add_custom_target(db_gen_odb_logic
add_custom_command(
OUTPUT ${_expected_odb_sources}
COMMAND "${CMAKE_COMMAND}"
-DCPPBESSOT_ODB_EXECUTABLE=${CPPBESSOT_ODB_EXECUTABLE}
-DCPPBESSOT_VERSION_DIR=${_version_dir}
-P "${_CPPBESSOT_DB_GEN_ODB_DIR}/scripts/run_odb_logic.cmake"
DEPENDS db_gen_cpp_headers
DEPENDS "${_openapi_file}" ${_expected_odb_model_headers}
COMMENT "Generating ODB ORM sources for ${schema_dir} (sqlite + postgre)"
VERBATIM
)
add_custom_target(db_gen_odb_logic
DEPENDS ${_expected_odb_sources})
add_dependencies(db_gen_odb_logic db_gen_cpp_headers)
set_target_properties(db_gen_odb_logic PROPERTIES EXCLUDE_FROM_ALL TRUE)
endfunction()
+16 -2
View File
@@ -13,16 +13,30 @@ function(cppbessot_add_db_gen_sql_ddl_target schema_dir)
# - Files under `<schema_dir>/generated-sql-ddl/{sqlite,postgre}`.
cppbessot_validate_schema_dir_name("${schema_dir}")
cppbessot_get_schema_dir_path(_version_dir "${schema_dir}")
cppbessot_get_expected_odb_generation_artifacts(
_expected_model_headers
_expected_odb_sources
"${schema_dir}")
add_custom_target(db_gen_sql_ddl
set(_stamp_dir "${CMAKE_CURRENT_BINARY_DIR}/cppbessot/${schema_dir}")
set(_stamp_file "${_stamp_dir}/db_gen_sql_ddl.stamp")
add_custom_command(
OUTPUT "${_stamp_file}"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${_stamp_dir}"
COMMAND "${CMAKE_COMMAND}"
-DCPPBESSOT_ODB_EXECUTABLE=${CPPBESSOT_ODB_EXECUTABLE}
-DCPPBESSOT_VERSION_DIR=${_version_dir}
-P "${_CPPBESSOT_DB_GEN_SQL_DDL_DIR}/scripts/run_odb_sql_ddl.cmake"
DEPENDS db_gen_cpp_headers
COMMAND "${CMAKE_COMMAND}" -E touch "${_stamp_file}"
DEPENDS db_gen_cpp_headers ${_expected_model_headers}
COMMENT "Generating SQL DDL snapshots for ${schema_dir} (sqlite + postgre)"
VERBATIM
)
add_custom_target(db_gen_sql_ddl
DEPENDS "${_stamp_file}")
add_dependencies(db_gen_sql_ddl db_gen_cpp_headers)
set_target_properties(db_gen_sql_ddl PROPERTIES EXCLUDE_FROM_ALL TRUE)
endfunction()
+2
View File
@@ -12,6 +12,7 @@ function(cppbessot_add_db_gen_ts_target schema_dir)
# - Files under `<schema_dir>/generated-ts-types`.
cppbessot_validate_schema_dir_name("${schema_dir}")
cppbessot_get_schema_dir_path(_version_dir "${schema_dir}")
cppbessot_get_module_root(_module_root)
set(_openapi_file "${_version_dir}/openapi/openapi.yaml")
set(_output_dir "${_version_dir}/generated-ts-types")
@@ -22,6 +23,7 @@ function(cppbessot_add_db_gen_ts_target schema_dir)
-i "${_openapi_file}"
-g typescript-fetch
-o "${_output_dir}"
WORKING_DIRECTORY "${_module_root}"
COMMENT "Generating TypeScript types for ${schema_dir}"
VERBATIM
)
+1 -1
View File
@@ -20,7 +20,7 @@ function(cppbessot_add_db_gen_zod_target schema_dir)
add_custom_target(db_gen_zod
COMMAND ${CMAKE_COMMAND} -E make_directory "${_output_dir}"
COMMAND "${CPPBESSOT_NPX_EXECUTABLE}" --no-install openapi-zod-client
COMMAND "${CPPBESSOT_NPX_EXECUTABLE}" --yes openapi-zod-client
"${_openapi_file}"
--output "${_output_file}"
--export-schemas
+192 -25
View File
@@ -41,6 +41,20 @@ function(cppbessot_initialize_paths)
set(CPPBESSOT_WORKDIR_ABS "${CPPBESSOT_WORKDIR_ABS}" PARENT_SCOPE)
endfunction()
function(cppbessot_get_module_root out_var)
# Purpose: Resolve the CppBeSSOT module root, respecting parent overrides.
# Inputs:
# - CPPBESSOT_MODULE_ROOT (optional): Parent-provided module root path.
# Outputs:
# - <out_var> (PARENT_SCOPE): Absolute module root path.
if(DEFINED CPPBESSOT_MODULE_ROOT AND NOT "${CPPBESSOT_MODULE_ROOT}" STREQUAL "")
get_filename_component(_module_root "${CPPBESSOT_MODULE_ROOT}" ABSOLUTE)
else()
get_filename_component(_module_root "${_CPPBESSOT_GENERATION_COMMON_DIR}/.." ABSOLUTE)
endif()
set(${out_var} "${_module_root}" PARENT_SCOPE)
endfunction()
function(cppbessot_require_var var_name)
# Purpose: Fail fast if a required CMake variable is missing/empty.
# Inputs:
@@ -92,6 +106,19 @@ function(cppbessot_assert_schema_dir_exists schema_dir)
endif()
endfunction()
function(cppbessot_assert_openapi_exists schema_dir)
# Purpose: Assert that a schema directory's SSOT OpenAPI file exists on disk.
# Inputs:
# - schema_dir: Schema directory basename.
# Outputs:
# - No return value; raises FATAL_ERROR if file is missing.
cppbessot_get_schema_dir_path(_schema_dir_path "${schema_dir}")
set(_openapi_file "${_schema_dir_path}/openapi/openapi.yaml")
if(NOT EXISTS "${_openapi_file}")
message(FATAL_ERROR "OpenAPI file does not exist: ${_openapi_file}")
endif()
endfunction()
function(cppbessot_get_model_headers_glob out_var schema_dir)
# Purpose: Build a model-header glob expression for a schema directory.
# Inputs:
@@ -103,21 +130,22 @@ function(cppbessot_get_model_headers_glob out_var schema_dir)
set(${out_var} "${_schema_dir_path}/generated-cpp-source/include/*/model/*.h" PARENT_SCOPE)
endfunction()
function(cppbessot_get_openapi_schema_names out_var schema_dir)
# Purpose: Parse top-level component schema names from a schema directory's OpenAPI file.
function(_cppbessot_collect_openapi_schema_names out_var openapi_file filter_mode)
# Purpose: Shared OpenAPI components.schemas walker.
# Inputs:
# - out_var: Parent-scope variable name to receive the schema names.
# - schema_dir: Schema directory basename.
# - out_var: Parent-scope variable for collected schema names.
# - openapi_file: Absolute path to openapi.yaml.
# - filter_mode: ALL (every top-level schema) or ODB_TABLE (x-odbTable only).
# Outputs:
# - <out_var> (PARENT_SCOPE): List of top-level component schema names.
cppbessot_get_schema_dir_path(_schema_dir_path "${schema_dir}")
set(_openapi_file "${_schema_dir_path}/openapi/openapi.yaml")
if(NOT EXISTS "${_openapi_file}")
message(FATAL_ERROR "OpenAPI file does not exist: ${_openapi_file}")
# - <out_var> (PARENT_SCOPE): Collected schema names.
if(NOT "${filter_mode}" STREQUAL "ALL" AND NOT "${filter_mode}" STREQUAL "ODB_TABLE")
message(FATAL_ERROR
"Unsupported OpenAPI schema filter `${filter_mode}`; expected ALL or ODB_TABLE.")
endif()
file(STRINGS "${_openapi_file}" _openapi_lines)
file(STRINGS "${openapi_file}" _openapi_lines)
set(_schema_names)
set(_current_schema_name)
set(_in_components FALSE)
set(_in_schemas FALSE)
@@ -125,8 +153,16 @@ function(cppbessot_get_openapi_schema_names out_var schema_dir)
if(_in_schemas)
if(_line MATCHES "^[^ ]" OR _line MATCHES "^ [^ ]")
set(_in_schemas FALSE)
unset(_current_schema_name)
elseif(_line MATCHES "^ ([A-Za-z_][A-Za-z0-9_]*)[ \t]*:[ \t]*$")
list(APPEND _schema_names "${CMAKE_MATCH_1}")
set(_current_schema_name "${CMAKE_MATCH_1}")
if("${filter_mode}" STREQUAL "ALL")
list(APPEND _schema_names "${_current_schema_name}")
endif()
elseif("${filter_mode}" STREQUAL "ODB_TABLE"
AND _current_schema_name
AND _line MATCHES "^ x-odbTable:[ \t]*")
list(APPEND _schema_names "${_current_schema_name}")
endif()
endif()
@@ -144,10 +180,52 @@ function(cppbessot_get_openapi_schema_names out_var schema_dir)
endforeach()
if(NOT _schema_names)
message(FATAL_ERROR
"No component schema names were found in ${_openapi_file}.")
if("${filter_mode}" STREQUAL "ODB_TABLE")
message(FATAL_ERROR
"No x-odbTable schema names were found in ${openapi_file}.")
else()
message(FATAL_ERROR
"No component schema names were found in ${openapi_file}.")
endif()
endif()
list(REMOVE_DUPLICATES _schema_names)
set(${out_var} "${_schema_names}" PARENT_SCOPE)
endfunction()
function(_cppbessot_get_openapi_file_path out_var schema_dir)
# Purpose: Resolve and validate a schema directory's SSOT OpenAPI file path.
# Inputs:
# - out_var: Parent-scope variable name to receive the absolute OpenAPI path.
# - schema_dir: Schema directory basename.
# Outputs:
# - <out_var> (PARENT_SCOPE): Absolute path to openapi.yaml.
cppbessot_get_schema_dir_path(_schema_dir_path "${schema_dir}")
cppbessot_assert_openapi_exists("${schema_dir}")
set(${out_var} "${_schema_dir_path}/openapi/openapi.yaml" PARENT_SCOPE)
endfunction()
function(cppbessot_get_openapi_schema_names out_var schema_dir)
# Purpose: Parse top-level component schema names from a schema directory's OpenAPI file.
# Inputs:
# - out_var: Parent-scope variable name to receive the schema names.
# - schema_dir: Schema directory basename.
# Outputs:
# - <out_var> (PARENT_SCOPE): List of top-level component schema names.
_cppbessot_get_openapi_file_path(_openapi_file "${schema_dir}")
_cppbessot_collect_openapi_schema_names(_schema_names "${_openapi_file}" "ALL")
set(${out_var} "${_schema_names}" PARENT_SCOPE)
endfunction()
function(cppbessot_get_openapi_odb_table_schema_names out_var schema_dir)
# Purpose: Parse OpenAPI schema names that declare x-odbTable (ODB object models).
# Inputs:
# - out_var: Parent-scope variable name to receive the schema names.
# - schema_dir: Schema directory basename.
# Outputs:
# - <out_var> (PARENT_SCOPE): Schema names with x-odbTable in the OpenAPI file.
_cppbessot_get_openapi_file_path(_openapi_file "${schema_dir}")
_cppbessot_collect_openapi_schema_names(_schema_names "${_openapi_file}" "ODB_TABLE")
set(${out_var} "${_schema_names}" PARENT_SCOPE)
endfunction()
@@ -176,8 +254,41 @@ function(cppbessot_get_expected_cpp_model_outputs out_headers_var out_sources_va
set(${out_sources_var} "${_sources}" PARENT_SCOPE)
endfunction()
function(_cppbessot_build_odb_table_artifact_paths
schema_dir
schema_names
out_model_headers_var
out_sqlite_sources_var
out_pgsql_sources_var)
# Purpose: Build expected ODB model-header and backend source paths from schema names.
# Inputs:
# - schema_dir: Schema directory basename.
# - schema_names: x-odbTable schema names.
# Outputs:
# - <out_model_headers_var> (PARENT_SCOPE): Expected generated ODB model headers.
# - <out_sqlite_sources_var> (PARENT_SCOPE): Expected sqlite `*-odb.cxx` sources.
# - <out_pgsql_sources_var> (PARENT_SCOPE): Expected postgre `*-odb.cxx` sources.
cppbessot_get_schema_dir_path(_schema_dir_path "${schema_dir}")
set(_headers)
set(_sqlite_sources)
set(_pgsql_sources)
foreach(_schema_name IN LISTS schema_names)
list(APPEND _headers
"${_schema_dir_path}/generated-cpp-source/include/cppbessot/model/${_schema_name}.h")
list(APPEND _sqlite_sources
"${_schema_dir_path}/generated-odb-source/sqlite/${_schema_name}-odb.cxx")
list(APPEND _pgsql_sources
"${_schema_dir_path}/generated-odb-source/postgre/${_schema_name}-odb.cxx")
endforeach()
set(${out_model_headers_var} "${_headers}" PARENT_SCOPE)
set(${out_sqlite_sources_var} "${_sqlite_sources}" PARENT_SCOPE)
set(${out_pgsql_sources_var} "${_pgsql_sources}" PARENT_SCOPE)
endfunction()
function(cppbessot_get_expected_odb_outputs out_sqlite_sources_var out_pgsql_sources_var schema_dir)
# Purpose: Infer generated ODB backend source files from OpenAPI schema names.
# Purpose: Infer generated ODB backend source files from x-odbTable OpenAPI schemas.
# Inputs:
# - out_sqlite_sources_var: Parent-scope variable for sqlite `*-odb.cxx`.
# - out_pgsql_sources_var: Parent-scope variable for postgre `*-odb.cxx`.
@@ -185,18 +296,74 @@ function(cppbessot_get_expected_odb_outputs out_sqlite_sources_var out_pgsql_sou
# Outputs:
# - <out_sqlite_sources_var> (PARENT_SCOPE): Expected sqlite ODB sources.
# - <out_pgsql_sources_var> (PARENT_SCOPE): Expected postgre ODB sources.
cppbessot_get_schema_dir_path(_schema_dir_path "${schema_dir}")
cppbessot_get_openapi_schema_names(_schema_names "${schema_dir}")
set(_sqlite_sources)
set(_pgsql_sources)
foreach(_schema_name IN LISTS _schema_names)
list(APPEND _sqlite_sources
"${_schema_dir_path}/generated-odb-source/sqlite/${_schema_name}-odb.cxx")
list(APPEND _pgsql_sources
"${_schema_dir_path}/generated-odb-source/postgre/${_schema_name}-odb.cxx")
endforeach()
cppbessot_get_openapi_odb_table_schema_names(_schema_names "${schema_dir}")
_cppbessot_build_odb_table_artifact_paths(
"${schema_dir}"
"${_schema_names}"
_expected_model_headers
_sqlite_sources
_pgsql_sources)
set(${out_sqlite_sources_var} "${_sqlite_sources}" PARENT_SCOPE)
set(${out_pgsql_sources_var} "${_pgsql_sources}" PARENT_SCOPE)
endfunction()
function(cppbessot_get_expected_odb_model_headers out_var schema_dir)
# Purpose: Infer generated C++ model headers for x-odbTable OpenAPI schemas.
# Inputs:
# - out_var: Parent-scope variable name to receive expected ODB model headers.
# - schema_dir: Schema directory basename.
# Outputs:
# - <out_var> (PARENT_SCOPE): Expected generated model headers for ODB objects.
cppbessot_get_openapi_odb_table_schema_names(_schema_names "${schema_dir}")
_cppbessot_build_odb_table_artifact_paths(
"${schema_dir}"
"${_schema_names}"
_headers
_sqlite_sources
_pgsql_sources)
set(${out_var} "${_headers}" PARENT_SCOPE)
endfunction()
function(cppbessot_get_expected_odb_outputs_all out_var schema_dir)
# Purpose: Infer all generated ODB backend `*-odb.cxx` files for both backends.
# Inputs:
# - out_var: Parent-scope variable name to receive expected ODB sources.
# - schema_dir: Schema directory basename.
# Outputs:
# - <out_var> (PARENT_SCOPE): Expected sqlite + postgre ODB sources.
cppbessot_get_expected_odb_outputs(
_expected_sqlite_odb_sources
_expected_pgsql_odb_sources
"${schema_dir}")
set(_combined
${_expected_sqlite_odb_sources}
${_expected_pgsql_odb_sources})
set(${out_var} "${_combined}" PARENT_SCOPE)
endfunction()
function(cppbessot_get_expected_odb_generation_artifacts
out_model_headers_var
out_all_sources_var
schema_dir)
# Purpose: Infer ODB generation dependencies and outputs in a single OpenAPI pass.
# Inputs:
# - out_model_headers_var: Parent-scope variable for expected ODB model headers.
# - out_all_sources_var: Parent-scope variable for expected sqlite + postgre sources.
# - schema_dir: Schema directory basename.
# Outputs:
# - <out_model_headers_var> (PARENT_SCOPE): Expected generated ODB model headers.
# - <out_all_sources_var> (PARENT_SCOPE): Expected sqlite + postgre `*-odb.cxx` sources.
cppbessot_get_openapi_odb_table_schema_names(_schema_names "${schema_dir}")
_cppbessot_build_odb_table_artifact_paths(
"${schema_dir}"
"${_schema_names}"
_headers
_sqlite_sources
_pgsql_sources)
set(_combined ${_sqlite_sources} ${_pgsql_sources})
set(${out_model_headers_var} "${_headers}" PARENT_SCOPE)
set(${out_all_sources_var} "${_combined}" PARENT_SCOPE)
endfunction()
+41
View File
@@ -0,0 +1,41 @@
include_guard(GLOBAL)
function(_cppbessot_dotenv_escape output_var value)
set(escaped "${value}")
string(REPLACE "\\" "\\\\" escaped "${escaped}")
string(REPLACE "\"" "\\\"" escaped "${escaped}")
string(REPLACE "\n" "\\n" escaped "${escaped}")
string(REPLACE "\r" "\\r" escaped "${escaped}")
string(REPLACE "\t" "\\t" escaped "${escaped}")
set(${output_var} "${escaped}" PARENT_SCOPE)
endfunction()
function(_cppbessot_dotenv_append output_var name value)
_cppbessot_dotenv_escape(escaped_value "${value}")
set(line "${name}=\"${escaped_value}\"\n")
set(${output_var} "${${output_var}}${line}" PARENT_SCOPE)
endfunction()
function(cppbessot_write_runtime_env_file output_path)
set(env_contents
"# Generated by cppbessot during CMake configure. Do not edit.\n")
_cppbessot_dotenv_append(env_contents
"DB_TARGET" "${DB_TARGET}")
_cppbessot_dotenv_append(env_contents
"CPPBESSOT_DB_PGSQL_PROD_CONNSTR" "${CPPBESSOT_DB_PGSQL_PROD_CONNSTR}")
_cppbessot_dotenv_append(env_contents
"CPPBESSOT_DB_PGSQL_DEV_CONNSTR" "${CPPBESSOT_DB_PGSQL_DEV_CONNSTR}")
_cppbessot_dotenv_append(env_contents
"CPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR" "${CPPBESSOT_DB_PGSQL_PRODDEV_CONNSTR}")
_cppbessot_dotenv_append(env_contents
"CPPBESSOT_DB_PGSQL_TESTS_CONNSTR" "${CPPBESSOT_DB_PGSQL_TESTS_CONNSTR}")
_cppbessot_dotenv_append(env_contents
"CPPBESSOT_DB_SQLITE_PROD_PATH" "${CPPBESSOT_DB_SQLITE_PROD_PATH}")
_cppbessot_dotenv_append(env_contents
"CPPBESSOT_DB_SQLITE_DEV_PATH" "${CPPBESSOT_DB_SQLITE_DEV_PATH}")
_cppbessot_dotenv_append(env_contents
"CPPBESSOT_DB_SQLITE_PRODDEV_PATH" "${CPPBESSOT_DB_SQLITE_PRODDEV_PATH}")
_cppbessot_dotenv_append(env_contents
"CPPBESSOT_DB_SQLITE_TESTS_PATH" "${CPPBESSOT_DB_SQLITE_TESTS_PATH}")
file(WRITE "${output_path}" "${env_contents}")
endfunction()
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.16)
function(cppbessot_db_action_get_hook_path out_var migration_dir hook_name)
set(_hook_path "${migration_dir}/${hook_name}")
if(EXISTS "${_hook_path}")
set(${out_var} "${_hook_path}" PARENT_SCOPE)
else()
set(${out_var} "" PARENT_SCOPE)
endif()
endfunction()
function(cppbessot_db_action_run_hook
hook_path
db_target
backend
migration_dir
migrate_with
schema_dir_to_generate
createfrom_schema_dir
sqlite_path
pgsql_connstr)
if("${hook_path}" STREQUAL "")
return()
endif()
set(_env_args
"CPPBESSOT_DB_TARGET=${db_target}"
"CPPBESSOT_DB_BACKEND=${backend}"
"CPPBESSOT_DB_MIGRATION_DIR=${migration_dir}"
"CPPBESSOT_DB_MIGRATE_WITH=${migrate_with}"
"CPPBESSOT_DB_SCHEMA_DIR_TO_GENERATE=${schema_dir_to_generate}"
"CPPBESSOT_DB_CREATEFROM_SCHEMA_DIR=${createfrom_schema_dir}"
"CPPBESSOT_DB_SQLITE_PATH=${sqlite_path}"
"CPPBESSOT_DB_PGSQL_CONNSTR=${pgsql_connstr}")
execute_process(
COMMAND "${CMAKE_COMMAND}" -E env ${_env_args} sh "${hook_path}"
WORKING_DIRECTORY "${migration_dir}"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _stdout
ERROR_VARIABLE _stderr
)
if(NOT _result EQUAL 0)
message(FATAL_ERROR
"Backfill hook failed: ${hook_path}\n${_stdout}\n${_stderr}")
endif()
endfunction()
@@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 3.16)
function(cppbessot_db_action_target_exists out_var backend sqlite_path pgsql_connstr)
if("${backend}" STREQUAL "sqlite")
if(EXISTS "${sqlite_path}")
set(${out_var} TRUE PARENT_SCOPE)
else()
set(${out_var} FALSE PARENT_SCOPE)
endif()
return()
endif()
cppbessot_db_action_find_program_or_fail(_psql psql
"PostgreSQL live actions require `psql` to be available in PATH.")
execute_process(
COMMAND "${_psql}" "${pgsql_connstr}" -v ON_ERROR_STOP=1 -c "SELECT 1;"
RESULT_VARIABLE _result
OUTPUT_QUIET
ERROR_QUIET
)
if(_result EQUAL 0)
set(${out_var} TRUE PARENT_SCOPE)
else()
set(${out_var} FALSE PARENT_SCOPE)
endif()
endfunction()
function(cppbessot_db_action_get_clone_command out_var backend target)
if("${backend}" STREQUAL "sqlite")
set(_command "${CPPBESSOT_DB_SQLITE_CLONE_PROD_TO_PRODDEV_COMMAND}")
else()
set(_command "${CPPBESSOT_DB_PGSQL_CLONE_PROD_TO_PRODDEV_COMMAND}")
endif()
set(${out_var} "${_command}" PARENT_SCOPE)
endfunction()
function(cppbessot_db_action_invoke_clone_hook backend target)
cppbessot_db_action_get_clone_command(_clone_command "${backend}" "${target}")
if("${_clone_command}" STREQUAL "")
message(FATAL_ERROR
"No clone command is configured for backend `${backend}` while preparing target `${target}`.")
endif()
execute_process(
COMMAND sh -c "${_clone_command}"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _stdout
ERROR_VARIABLE _stderr
)
if(NOT _result EQUAL 0)
message(FATAL_ERROR
"Clone command failed for backend `${backend}` target `${target}`.\n${_stdout}\n${_stderr}")
endif()
endfunction()
function(cppbessot_db_action_prepare_proddev target backend use_stale sqlite_path pgsql_connstr)
if(NOT "${target}" STREQUAL "proddev")
return()
endif()
if(use_stale)
cppbessot_db_action_target_exists(_exists "${backend}" "${sqlite_path}" "${pgsql_connstr}")
if(NOT _exists)
message(FATAL_ERROR
"DB_MIGRATE_PRODDEV_USE_STALE is ON, but no current stale proddev target exists.")
endif()
return()
endif()
cppbessot_db_action_invoke_clone_hook("${backend}" "${target}")
cppbessot_db_action_target_exists(_exists "${backend}" "${sqlite_path}" "${pgsql_connstr}")
if(NOT _exists)
message(FATAL_ERROR
"Proddev clone command completed, but the proddev target still does not appear to exist.")
endif()
endfunction()
+168
View File
@@ -0,0 +1,168 @@
cmake_minimum_required(VERSION 3.16)
include("${CMAKE_CURRENT_LIST_DIR}/../dbActionShared.cmake")
function(cppbessot_db_action_require_var var_name)
if(NOT DEFINED ${var_name} OR "${${var_name}}" STREQUAL "")
message(FATAL_ERROR "Required variable `${var_name}` is missing.")
endif()
endfunction()
function(cppbessot_db_action_resolve_project_path out_var input_path)
cppbessot_db_action_require_var(CPPBESSOT_PROJECT_SOURCE_DIR)
if(IS_ABSOLUTE "${input_path}")
set(_resolved "${input_path}")
else()
set(_resolved "${CPPBESSOT_PROJECT_SOURCE_DIR}/${input_path}")
endif()
get_filename_component(_resolved "${_resolved}" ABSOLUTE)
set(${out_var} "${_resolved}" PARENT_SCOPE)
endfunction()
function(cppbessot_db_action_validate_schema_dir_name schema_dir)
_cppbessot_db_action_validate_basename(
"${schema_dir}"
"Schema directory name"
"CPPBESSOT_WORKDIR")
endfunction()
function(cppbessot_db_action_get_schema_dir_path out_var schema_dir)
cppbessot_db_action_validate_schema_dir_name("${schema_dir}")
cppbessot_db_action_resolve_project_path(_workdir "${CPPBESSOT_WORKDIR}")
set(${out_var} "${_workdir}/${schema_dir}" PARENT_SCOPE)
endfunction()
function(cppbessot_db_action_assert_schema_dir_ready schema_dir)
cppbessot_db_action_get_schema_dir_path(_schema_dir_path "${schema_dir}")
if(NOT IS_DIRECTORY "${_schema_dir_path}")
message(FATAL_ERROR "Schema directory does not exist: ${_schema_dir_path}")
endif()
set(_openapi_file "${_schema_dir_path}/openapi/openapi.yaml")
if(NOT EXISTS "${_openapi_file}")
message(FATAL_ERROR "OpenAPI file does not exist: ${_openapi_file}")
endif()
endfunction()
function(cppbessot_db_action_validate_migration_dir_name migration_dir)
_cppbessot_db_action_validate_basename(
"${migration_dir}"
"Migration directory name"
"CPPBESSOT_WORKDIR/migrations")
endfunction()
function(cppbessot_db_action_get_migration_dir_path out_var migration_dir)
cppbessot_db_action_validate_migration_dir_name("${migration_dir}")
cppbessot_db_action_resolve_project_path(_workdir "${CPPBESSOT_WORKDIR}")
set(${out_var} "${_workdir}/migrations/${migration_dir}" PARENT_SCOPE)
endfunction()
function(cppbessot_db_action_assert_migration_dir_exists migration_dir)
cppbessot_db_action_get_migration_dir_path(_migration_dir_path "${migration_dir}")
if(NOT IS_DIRECTORY "${_migration_dir_path}")
message(FATAL_ERROR "Migration directory does not exist: ${_migration_dir_path}")
endif()
endfunction()
function(cppbessot_db_action_validate_db_target db_target)
_cppbessot_db_action_validate_db_target_impl("${db_target}")
endfunction()
function(cppbessot_db_action_backend_subdir out_var backend)
if("${backend}" STREQUAL "sqlite")
set(${out_var} "sqlite" PARENT_SCOPE)
return()
endif()
if("${backend}" STREQUAL "postgre")
set(${out_var} "postgre" PARENT_SCOPE)
return()
endif()
message(FATAL_ERROR "Unsupported backend `${backend}`.")
endfunction()
function(cppbessot_db_action_collect_nonempty_sql_files out_var sql_dir)
if(NOT IS_DIRECTORY "${sql_dir}")
set(${out_var} "" PARENT_SCOPE)
return()
endif()
file(GLOB _candidate_files "${sql_dir}/*.sql")
list(SORT _candidate_files)
set(_sql_files)
foreach(_candidate IN LISTS _candidate_files)
file(READ "${_candidate}" _contents)
string(STRIP "${_contents}" _trimmed)
if(NOT "${_trimmed}" STREQUAL "")
list(APPEND _sql_files "${_candidate}")
endif()
endforeach()
set(${out_var} "${_sql_files}" PARENT_SCOPE)
endfunction()
function(cppbessot_db_action_is_migration_sql_file out_var sql_file)
get_filename_component(_filename "${sql_file}" NAME)
if("${_filename}" MATCHES "-[0-9]+-(pre|post)\\.sql$")
set(${out_var} TRUE PARENT_SCOPE)
return()
endif()
set(${out_var} FALSE PARENT_SCOPE)
endfunction()
function(cppbessot_db_action_collect_schema_sql_files out_var sql_dir)
cppbessot_db_action_collect_nonempty_sql_files(_candidate_files "${sql_dir}")
set(_sql_files)
foreach(_candidate IN LISTS _candidate_files)
cppbessot_db_action_is_migration_sql_file(_is_migration_sql "${_candidate}")
if(NOT _is_migration_sql)
list(APPEND _sql_files "${_candidate}")
endif()
endforeach()
set(${out_var} "${_sql_files}" PARENT_SCOPE)
endfunction()
function(cppbessot_db_action_migration_sort_key out_var sql_file)
get_filename_component(_filename "${sql_file}" NAME)
string(REGEX REPLACE "-([0-9]+)-pre\\.sql$" "-\\1-0-pre.sql" _sort_key "${_filename}")
string(REGEX REPLACE "-([0-9]+)-post\\.sql$" "-\\1-1-post.sql" _sort_key "${_sort_key}")
set(${out_var} "${_sort_key}" PARENT_SCOPE)
endfunction()
function(cppbessot_db_action_collect_migration_sql_files out_var sql_dir)
cppbessot_db_action_collect_nonempty_sql_files(_candidate_files "${sql_dir}")
set(_keyed_files)
foreach(_candidate IN LISTS _candidate_files)
cppbessot_db_action_is_migration_sql_file(_is_migration_sql "${_candidate}")
if(_is_migration_sql)
cppbessot_db_action_migration_sort_key(_sort_key "${_candidate}")
list(APPEND _keyed_files "${_sort_key}|${_candidate}")
endif()
endforeach()
list(SORT _keyed_files)
set(_sql_files)
foreach(_keyed_file IN LISTS _keyed_files)
string(REGEX REPLACE "^[^|]+\\|" "" _sql_file "${_keyed_file}")
list(APPEND _sql_files "${_sql_file}")
endforeach()
set(${out_var} "${_sql_files}" PARENT_SCOPE)
endfunction()
function(cppbessot_db_action_require_nonempty_sql_dir sql_dir failure_prefix)
cppbessot_db_action_collect_schema_sql_files(_sql_files "${sql_dir}")
if(NOT _sql_files)
message(FATAL_ERROR "${failure_prefix}: no non-empty SQL files found under ${sql_dir}")
endif()
endfunction()
function(cppbessot_db_action_find_program_or_fail out_var program_name hint)
find_program(_program "${program_name}")
if(NOT _program)
message(FATAL_ERROR "Missing required program `${program_name}`. ${hint}")
endif()
set(${out_var} "${_program}" PARENT_SCOPE)
endfunction()
@@ -0,0 +1,78 @@
cmake_minimum_required(VERSION 3.16)
function(cppbessot_db_action_reset_sqlite_db sqlite_path)
if(EXISTS "${sqlite_path}")
file(REMOVE "${sqlite_path}")
endif()
get_filename_component(_sqlite_parent "${sqlite_path}" DIRECTORY)
if(NOT "${_sqlite_parent}" STREQUAL "")
file(MAKE_DIRECTORY "${_sqlite_parent}")
endif()
endfunction()
function(cppbessot_db_action_apply_sqlite_files sqlite_path)
set(_sql_files "${ARGN}")
if(NOT _sql_files)
return()
endif()
cppbessot_db_action_find_program_or_fail(_sqlite3 sqlite3
"SQLite live actions require the `sqlite3` CLI to be available in PATH.")
foreach(_sql_file IN LISTS _sql_files)
string(REPLACE "\"" "\\\"" _sqlite_read_file "${_sql_file}")
execute_process(
COMMAND "${_sqlite3}" "${sqlite_path}" ".read \"${_sqlite_read_file}\""
RESULT_VARIABLE _result
OUTPUT_VARIABLE _stdout
ERROR_VARIABLE _stderr
)
if(NOT _result EQUAL 0)
message(FATAL_ERROR
"SQLite SQL apply failed for `${_sql_file}` against `${sqlite_path}`.\n${_stdout}\n${_stderr}")
endif()
endforeach()
endfunction()
function(cppbessot_db_action_reset_pgsql_schema pgsql_connstr)
cppbessot_db_action_find_program_or_fail(_psql psql
"PostgreSQL live actions require `psql` to be available in PATH.")
execute_process(
COMMAND "${_psql}" "${pgsql_connstr}" -v ON_ERROR_STOP=1
-c "DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public;"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _stdout
ERROR_VARIABLE _stderr
)
if(NOT _result EQUAL 0)
message(FATAL_ERROR
"PostgreSQL schema reset failed.\n${_stdout}\n${_stderr}")
endif()
endfunction()
function(cppbessot_db_action_apply_pgsql_files pgsql_connstr)
set(_sql_files "${ARGN}")
if(NOT _sql_files)
return()
endif()
cppbessot_db_action_find_program_or_fail(_psql psql
"PostgreSQL live actions require `psql` to be available in PATH.")
foreach(_sql_file IN LISTS _sql_files)
execute_process(
COMMAND "${_psql}" "${pgsql_connstr}" -v ON_ERROR_STOP=1 -f "${_sql_file}"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _stdout
ERROR_VARIABLE _stderr
)
if(NOT _result EQUAL 0)
message(FATAL_ERROR
"PostgreSQL SQL apply failed for `${_sql_file}`.\n${_stdout}\n${_stderr}")
endif()
endforeach()
endfunction()
@@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.16)
function(cppbessot_db_action_target_upper out_var db_target)
string(TOUPPER "${db_target}" _upper)
set(${out_var} "${_upper}" PARENT_SCOPE)
endfunction()
function(cppbessot_db_action_resolve_backend_for_target
out_backend
out_sqlite_path
out_pgsql_connstr
db_target)
cppbessot_db_action_validate_db_target("${db_target}")
cppbessot_db_action_target_upper(_target_upper "${db_target}")
set(_sqlite_var "CPPBESSOT_DB_SQLITE_${_target_upper}_PATH")
set(_pgsql_var "CPPBESSOT_DB_PGSQL_${_target_upper}_CONNSTR")
set(_has_sqlite FALSE)
set(_has_pgsql FALSE)
if(DEFINED ${_sqlite_var} AND NOT "${${_sqlite_var}}" STREQUAL "")
set(_has_sqlite TRUE)
endif()
if(DEFINED ${_pgsql_var} AND NOT "${${_pgsql_var}}" STREQUAL "")
set(_has_pgsql TRUE)
endif()
if(_has_sqlite AND _has_pgsql)
message(FATAL_ERROR
"DB target `${db_target}` is ambiguous: both `${_sqlite_var}` and `${_pgsql_var}` are set.")
endif()
if(NOT _has_sqlite AND NOT _has_pgsql)
message(FATAL_ERROR
"DB target `${db_target}` is not mapped: set exactly one of `${_sqlite_var}` or `${_pgsql_var}`.")
endif()
if(_has_sqlite)
set(${out_backend} "sqlite" PARENT_SCOPE)
set(${out_sqlite_path} "${${_sqlite_var}}" PARENT_SCOPE)
set(${out_pgsql_connstr} "" PARENT_SCOPE)
return()
endif()
set(${out_backend} "postgre" PARENT_SCOPE)
set(${out_sqlite_path} "" PARENT_SCOPE)
set(${out_pgsql_connstr} "${${_pgsql_var}}" PARENT_SCOPE)
endfunction()
@@ -0,0 +1,20 @@
function(cppbessot_odb_find_object_headers out_var include_dir)
file(GLOB _headers "${include_dir}/*/model/*.h")
if(NOT _headers)
message(FATAL_ERROR "No model headers found under ${include_dir}")
endif()
set(_object_headers "")
foreach(_header IN LISTS _headers)
file(READ "${_header}" _header_contents)
if(_header_contents MATCHES "#pragma db object")
list(APPEND _object_headers "${_header}")
endif()
endforeach()
if(NOT _object_headers)
message(FATAL_ERROR "No ODB object headers found under ${include_dir}")
endif()
set(${out_var} "${_object_headers}" PARENT_SCOPE)
endfunction()
+38
View File
@@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 3.16)
include("${CMAKE_CURRENT_LIST_DIR}/cppbessotDbActionCommon.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cppbessotDbActionTargetResolution.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cppbessotDbActionSqlApply.cmake")
cppbessot_db_action_require_var(CPPBESSOT_PROJECT_SOURCE_DIR)
cppbessot_db_action_require_var(CPPBESSOT_WORKDIR)
cppbessot_db_action_require_var(DB_CREATEFROM_SCHEMA_DIR)
cppbessot_db_action_require_var(DB_TARGET)
cppbessot_db_action_validate_db_target("${DB_TARGET}")
if("${DB_TARGET}" STREQUAL "proddev")
message(FATAL_ERROR "db_createfrom does not support DB_TARGET=proddev.")
endif()
cppbessot_db_action_assert_schema_dir_ready("${DB_CREATEFROM_SCHEMA_DIR}")
cppbessot_db_action_resolve_backend_for_target(
_backend
_sqlite_path
_pgsql_connstr
"${DB_TARGET}")
cppbessot_db_action_backend_subdir(_backend_subdir "${_backend}")
cppbessot_db_action_get_schema_dir_path(_schema_dir "${DB_CREATEFROM_SCHEMA_DIR}")
set(_ddl_dir "${_schema_dir}/generated-sql-ddl/${_backend_subdir}")
cppbessot_db_action_require_nonempty_sql_dir(
"${_ddl_dir}"
"db_createfrom cannot continue")
cppbessot_db_action_collect_schema_sql_files(_sql_files "${_ddl_dir}")
if("${_backend}" STREQUAL "sqlite")
cppbessot_db_action_reset_sqlite_db("${_sqlite_path}")
cppbessot_db_action_apply_sqlite_files("${_sqlite_path}" ${_sql_files})
return()
endif()
cppbessot_db_action_reset_pgsql_schema("${_pgsql_connstr}")
cppbessot_db_action_apply_pgsql_files("${_pgsql_connstr}" ${_sql_files})
+64
View File
@@ -0,0 +1,64 @@
cmake_minimum_required(VERSION 3.16)
include("${CMAKE_CURRENT_LIST_DIR}/cppbessotDbActionCommon.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cppbessotDbActionTargetResolution.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cppbessotDbActionBackfill.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cppbessotDbActionSqlApply.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cppbessotDbActionClone.cmake")
cppbessot_db_action_require_var(CPPBESSOT_PROJECT_SOURCE_DIR)
cppbessot_db_action_require_var(CPPBESSOT_WORKDIR)
cppbessot_db_action_require_var(DB_MIGRATE_WITH)
cppbessot_db_action_require_var(DB_TARGET)
cppbessot_db_action_require_var(DB_SCHEMA_DIR_TO_GENERATE)
cppbessot_db_action_require_var(DB_CREATEFROM_SCHEMA_DIR)
cppbessot_db_action_validate_db_target("${DB_TARGET}")
cppbessot_db_action_assert_migration_dir_exists("${DB_MIGRATE_WITH}")
cppbessot_db_action_resolve_backend_for_target(
_backend
_sqlite_path
_pgsql_connstr
"${DB_TARGET}")
cppbessot_db_action_prepare_proddev(
"${DB_TARGET}"
"${_backend}"
"${DB_MIGRATE_PRODDEV_USE_STALE}"
"${_sqlite_path}"
"${_pgsql_connstr}")
cppbessot_db_action_backend_subdir(_backend_subdir "${_backend}")
cppbessot_db_action_get_migration_dir_path(_migration_dir "${DB_MIGRATE_WITH}")
set(_sql_dir "${_migration_dir}/${_backend_subdir}")
cppbessot_db_action_collect_migration_sql_files(_sql_files "${_sql_dir}")
cppbessot_db_action_get_hook_path(_pre_hook "${_migration_dir}" "pre-structural-backfill.sh")
cppbessot_db_action_get_hook_path(_post_hook "${_migration_dir}" "post-structural-backfill.sh")
cppbessot_db_action_run_hook(
"${_pre_hook}"
"${DB_TARGET}"
"${_backend}"
"${_migration_dir}"
"${DB_MIGRATE_WITH}"
"${DB_SCHEMA_DIR_TO_GENERATE}"
"${DB_CREATEFROM_SCHEMA_DIR}"
"${_sqlite_path}"
"${_pgsql_connstr}")
if(_sql_files)
if("${_backend}" STREQUAL "sqlite")
cppbessot_db_action_apply_sqlite_files("${_sqlite_path}" ${_sql_files})
else()
cppbessot_db_action_apply_pgsql_files("${_pgsql_connstr}" ${_sql_files})
endif()
endif()
cppbessot_db_action_run_hook(
"${_post_hook}"
"${DB_TARGET}"
"${_backend}"
"${_migration_dir}"
"${DB_MIGRATE_WITH}"
"${DB_SCHEMA_DIR_TO_GENERATE}"
"${DB_CREATEFROM_SCHEMA_DIR}"
"${_sqlite_path}"
"${_pgsql_connstr}")
+3 -5
View File
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.16)
include("${CMAKE_CURRENT_LIST_DIR}/cppbessotOdbHeaderDiscovery.cmake")
if(NOT DEFINED CPPBESSOT_ODB_EXECUTABLE OR CPPBESSOT_ODB_EXECUTABLE STREQUAL "")
message(FATAL_ERROR "CPPBESSOT_ODB_EXECUTABLE is required")
@@ -8,10 +9,7 @@ if(NOT DEFINED CPPBESSOT_VERSION_DIR OR CPPBESSOT_VERSION_DIR STREQUAL "")
endif()
set(_include_dir "${CPPBESSOT_VERSION_DIR}/generated-cpp-source/include")
file(GLOB _headers "${_include_dir}/*/model/*.h")
if(NOT _headers)
message(FATAL_ERROR "No model headers found under ${_include_dir}")
endif()
cppbessot_odb_find_object_headers(_object_headers "${_include_dir}")
foreach(_backend IN ITEMS sqlite pgsql)
if(_backend STREQUAL "sqlite")
@@ -25,7 +23,7 @@ foreach(_backend IN ITEMS sqlite pgsql)
execute_process(
COMMAND "${CPPBESSOT_ODB_EXECUTABLE}" -I "${_include_dir}" --std c++11 -d "${_backend}" -q
-o "${_out_dir}" --changelog-dir "${_out_dir}" ${_headers}
-o "${_out_dir}" --changelog-dir "${_out_dir}" ${_object_headers}
RESULT_VARIABLE _result
OUTPUT_VARIABLE _stdout
ERROR_VARIABLE _stderr
+120 -15
View File
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.16)
include("${CMAKE_CURRENT_LIST_DIR}/cppbessotOdbHeaderDiscovery.cmake")
if(NOT DEFINED CPPBESSOT_ODB_EXECUTABLE OR CPPBESSOT_ODB_EXECUTABLE STREQUAL "")
message(FATAL_ERROR "CPPBESSOT_ODB_EXECUTABLE is required")
@@ -13,36 +14,115 @@ if(NOT DEFINED CPPBESSOT_MIGRATION_DIR OR CPPBESSOT_MIGRATION_DIR STREQUAL "")
message(FATAL_ERROR "CPPBESSOT_MIGRATION_DIR is required")
endif()
set(_to_include_dir "${CPPBESSOT_TO_VERSION_DIR}/generated-cpp-source/include")
file(GLOB _to_headers "${_to_include_dir}/*/model/*.h")
if(NOT _to_headers)
message(FATAL_ERROR "No target-version headers found under ${_to_include_dir}")
endif()
foreach(_backend IN ITEMS sqlite pgsql)
if(_backend STREQUAL "sqlite")
set(_subdir sqlite)
function(cppbessot_migration_resolve_backends out_var)
if(NOT DEFINED CPPBESSOT_GEN_MIGRATION_BACKENDS OR CPPBESSOT_GEN_MIGRATION_BACKENDS STREQUAL "")
if(DEFINED CPPBESSOT_GEN_MIGRATIONS_BACKENDS AND NOT CPPBESSOT_GEN_MIGRATIONS_BACKENDS STREQUAL "")
set(_raw_backends "${CPPBESSOT_GEN_MIGRATIONS_BACKENDS}")
else()
set(_raw_backends "sqlite;pgsql")
endif()
else()
set(_subdir postgre)
set(_raw_backends "${CPPBESSOT_GEN_MIGRATION_BACKENDS}")
endif()
set(_resolved_backends "")
foreach(_backend IN LISTS _raw_backends)
string(STRIP "${_backend}" _backend)
string(TOLOWER "${_backend}" _backend)
if(_backend STREQUAL "")
message(FATAL_ERROR "CPPBESSOT_GEN_MIGRATION_BACKENDS contains an empty backend name.")
endif()
if(NOT _backend STREQUAL "sqlite" AND NOT _backend STREQUAL "pgsql")
message(FATAL_ERROR
"Unsupported migration backend `${_backend}`. "
"CPPBESSOT_GEN_MIGRATION_BACKENDS supports sqlite and pgsql.")
endif()
if(NOT _backend IN_LIST _resolved_backends)
list(APPEND _resolved_backends "${_backend}")
endif()
endforeach()
if(NOT _resolved_backends)
message(FATAL_ERROR "CPPBESSOT_GEN_MIGRATION_BACKENDS must name at least one backend.")
endif()
set(${out_var} "${_resolved_backends}" PARENT_SCOPE)
endfunction()
function(cppbessot_migration_backend_metadata backend out_subdir out_odb_database out_database_attr)
if("${backend}" STREQUAL "sqlite")
set(${out_subdir} "sqlite" PARENT_SCOPE)
set(${out_odb_database} "sqlite" PARENT_SCOPE)
set(${out_database_attr} "sqlite" PARENT_SCOPE)
elseif("${backend}" STREQUAL "pgsql")
set(${out_subdir} "postgre" PARENT_SCOPE)
set(${out_odb_database} "pgsql" PARENT_SCOPE)
set(${out_database_attr} "pgsql" PARENT_SCOPE)
else()
message(FATAL_ERROR "Unsupported migration backend `${backend}`.")
endif()
endfunction()
function(cppbessot_migration_write_empty_changelog changelog_path database_attr)
if(NOT EXISTS "${changelog_path}")
file(WRITE "${changelog_path}"
"<changelog xmlns=\"http://www.codesynthesis.com/xmlns/odb/changelog\" database=\"${database_attr}\" version=\"1\">\n"
" <model version=\"1\">\n"
" </model>\n"
"</changelog>\n")
endif()
endfunction()
function(cppbessot_migration_should_retry_sqlite_from_empty out_var backend from_xml empty_changelog stdout stderr)
set(_should_retry FALSE)
if("${backend}" STREQUAL "sqlite" AND NOT "${from_xml}" STREQUAL "${empty_changelog}")
set(_diagnostics "${stdout}\n${stderr}")
if(_diagnostics MATCHES "SQLite does not support dropping of columns")
set(_should_retry TRUE)
endif()
endif()
set(${out_var} "${_should_retry}" PARENT_SCOPE)
endfunction()
cppbessot_migration_resolve_backends(_migration_backends)
set(_to_include_dir "${CPPBESSOT_TO_VERSION_DIR}/generated-cpp-source/include")
cppbessot_odb_find_object_headers(_object_headers "${_to_include_dir}")
set(_empty_changelog_dir "${CPPBESSOT_MIGRATION_DIR}/.empty-baseline")
file(MAKE_DIRECTORY "${_empty_changelog_dir}")
foreach(_backend IN LISTS _migration_backends)
cppbessot_migration_backend_metadata(
"${_backend}"
_subdir
_odb_database
_database_attr)
set(_empty_changelog "${_empty_changelog_dir}/${_subdir}-empty.xml")
cppbessot_migration_write_empty_changelog("${_empty_changelog}" "${_database_attr}")
set(_migration_backend_dir "${CPPBESSOT_MIGRATION_DIR}/${_subdir}")
file(MAKE_DIRECTORY "${_migration_backend_dir}")
foreach(_header IN LISTS _to_headers)
foreach(_header IN LISTS _object_headers)
get_filename_component(_name "${_header}" NAME_WE)
set(_in_xml "${CPPBESSOT_FROM_VERSION_DIR}/generated-odb-source/${_subdir}/${_name}.xml")
set(_out_xml "${CPPBESSOT_TO_VERSION_DIR}/generated-odb-source/${_subdir}/${_name}.xml")
if(NOT EXISTS "${_in_xml}")
message(FATAL_ERROR "Missing changelog input for `${_name}`: ${_in_xml}")
set(_from_xml "${_in_xml}")
if(NOT EXISTS "${_from_xml}")
set(_from_xml "${_empty_changelog}")
endif()
execute_process(
COMMAND "${CPPBESSOT_ODB_EXECUTABLE}" -I "${_to_include_dir}" --std c++11 -d "${_backend}"
COMMAND "${CPPBESSOT_ODB_EXECUTABLE}" -I "${_to_include_dir}" --std c++11 -d "${_odb_database}"
--generate-schema --schema-format sql -q
-o "${_migration_backend_dir}"
--changelog-in "${_in_xml}"
--changelog-in "${_from_xml}"
--changelog-out "${_out_xml}"
"${_header}"
RESULT_VARIABLE _result
@@ -50,6 +130,31 @@ foreach(_backend IN ITEMS sqlite pgsql)
ERROR_VARIABLE _stderr
)
cppbessot_migration_should_retry_sqlite_from_empty(
_retry_from_empty
"${_backend}"
"${_from_xml}"
"${_empty_changelog}"
"${_stdout}"
"${_stderr}")
if(NOT _result EQUAL 0 AND _retry_from_empty)
message(WARNING
"SQLite incremental migration failed for `${_name}`; retrying from empty baseline. "
"Generated SQLite migration SQL is a greenfield create for this model.")
execute_process(
COMMAND "${CPPBESSOT_ODB_EXECUTABLE}" -I "${_to_include_dir}" --std c++11 -d "${_odb_database}"
--generate-schema --schema-format sql -q
-o "${_migration_backend_dir}"
--changelog-in "${_empty_changelog}"
--changelog-out "${_out_xml}"
"${_header}"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _stdout
ERROR_VARIABLE _stderr
)
endif()
if(NOT _result EQUAL 0)
message(FATAL_ERROR
"Migration generation failed for `${_name}` backend `${_backend}`.\n${_stdout}\n${_stderr}")
+3 -5
View File
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.16)
include("${CMAKE_CURRENT_LIST_DIR}/cppbessotOdbHeaderDiscovery.cmake")
if(NOT DEFINED CPPBESSOT_ODB_EXECUTABLE OR CPPBESSOT_ODB_EXECUTABLE STREQUAL "")
message(FATAL_ERROR "CPPBESSOT_ODB_EXECUTABLE is required")
@@ -8,10 +9,7 @@ if(NOT DEFINED CPPBESSOT_VERSION_DIR OR CPPBESSOT_VERSION_DIR STREQUAL "")
endif()
set(_include_dir "${CPPBESSOT_VERSION_DIR}/generated-cpp-source/include")
file(GLOB _headers "${_include_dir}/*/model/*.h")
if(NOT _headers)
message(FATAL_ERROR "No model headers found under ${_include_dir}")
endif()
cppbessot_odb_find_object_headers(_object_headers "${_include_dir}")
foreach(_backend IN ITEMS sqlite pgsql)
if(_backend STREQUAL "sqlite")
@@ -28,7 +26,7 @@ foreach(_backend IN ITEMS sqlite pgsql)
execute_process(
COMMAND "${CPPBESSOT_ODB_EXECUTABLE}" -I "${_include_dir}" --std c++11 -d "${_backend}"
--generate-schema --schema-format sql -q
-o "${_ddl_dir}" --changelog-dir "${_changelog_dir}" ${_headers}
-o "${_ddl_dir}" --changelog-dir "${_changelog_dir}" ${_object_headers}
RESULT_VARIABLE _result
OUTPUT_VARIABLE _stdout
ERROR_VARIABLE _stderr
@@ -0,0 +1,47 @@
/*
* AUTO-GENERATED BY CppBeSsot.
* Direct edits are pointless: this file is regenerated.
* Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs.
*/
#pragma once
#include <cstdint>
#include <string>
#include <nlohmann/json.hpp>
#include <odb/core.hxx>
namespace models {
#pragma db model version(1, 2)
#pragma db object table("Agent")
class Agent
{
public:
#pragma db id
// odbAddedIn: 1.1
std::string id{};
// odbAddedIn: 1.1
std::string role{};
// odbAddedIn: 1.1
bool persistent{};
// odbAddedIn: 1.1
std::string displayName{};
// odbAddedIn: 1.2
int32_t trustScore{};
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Agent, id, role, persistent, displayName, trustScore)
nlohmann::json toJson() const
{
return nlohmann::json(*this);
}
static Agent fromJson(const nlohmann::json& j)
{
return j.get<Agent>();
}
};
} // namespace models
@@ -0,0 +1,43 @@
/*
* AUTO-GENERATED BY CppBeSsot.
* Direct edits are pointless: this file is regenerated.
* Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs.
*/
#pragma once
#include <cstdint>
#include <string>
#include <nlohmann/json.hpp>
#include <odb/core.hxx>
namespace models {
#pragma db model version(1, 2)
#pragma db object table("GovernmentAddress")
class GovernmentAddress
{
public:
#pragma db id
// odbAddedIn: 1.1
std::string id{};
// odbAddedIn: 1.1
std::string addressLabel{};
// odbAddedIn: 1.1
std::string regionLookupKey{};
NLOHMANN_DEFINE_TYPE_INTRUSIVE(GovernmentAddress, id, addressLabel, regionLookupKey)
nlohmann::json toJson() const
{
return nlohmann::json(*this);
}
static GovernmentAddress fromJson(const nlohmann::json& j)
{
return j.get<GovernmentAddress>();
}
};
} // namespace models
@@ -0,0 +1,61 @@
/*
* AUTO-GENERATED BY CppBeSsot.
* Direct edits are pointless: this file is regenerated.
* Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs.
*/
#pragma once
#include <cstdint>
#include <string>
#include <nlohmann/json.hpp>
#include <odb/core.hxx>
namespace models {
#pragma db model version(1, 2)
#pragma db object table("TripAttemptResult")
class TripAttemptResult
{
public:
#pragma db id
// odbAddedIn: 1.1
std::string id{};
// odbAddedIn: 1.1
std::string result{};
// odbAddedIn: 1.1
std::string retryReason{};
// odbAddedIn: 1.1
std::string governmentSuspensionReason{};
// odbAddedIn: 1.1
std::string governmentTerminationReason{};
// odbAddedIn: 1.1
std::string complianceSuspensionReason{};
// odbAddedIn: 1.1
std::string complianceTerminationReason{};
// odbAddedIn: 1.1
std::string policySuspensionReason{};
// odbAddedIn: 1.1
std::string policyTerminationReason{};
// odbAddedIn: 1.1
std::string cancelationReason{};
// odbAddedIn: 1.1
std::string failureReason{};
// odbAddedIn: 1.1
std::string details{};
NLOHMANN_DEFINE_TYPE_INTRUSIVE(TripAttemptResult, id, result, retryReason, governmentSuspensionReason, governmentTerminationReason, complianceSuspensionReason, complianceTerminationReason, policySuspensionReason, policyTerminationReason, cancelationReason, failureReason, details)
nlohmann::json toJson() const
{
return nlohmann::json(*this);
}
static TripAttemptResult fromJson(const nlohmann::json& j)
{
return j.get<TripAttemptResult>();
}
};
} // namespace models
@@ -0,0 +1,11 @@
/*
* AUTO-GENERATED BY CppBeSsot.
* Direct edits are pointless: this file is regenerated.
* Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs.
*/
#include "cppbessot/model/Agent.h"
namespace models {
// Nlohmann-based models are header-only for now.
} // namespace models
@@ -0,0 +1,11 @@
/*
* AUTO-GENERATED BY CppBeSsot.
* Direct edits are pointless: this file is regenerated.
* Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs.
*/
#include "cppbessot/model/GovernmentAddress.h"
namespace models {
// Nlohmann-based models are header-only for now.
} // namespace models
@@ -0,0 +1,11 @@
/*
* AUTO-GENERATED BY CppBeSsot.
* Direct edits are pointless: this file is regenerated.
* Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs.
*/
#include "cppbessot/model/TripAttemptResult.h"
namespace models {
// Nlohmann-based models are header-only for now.
} // namespace models
@@ -0,0 +1,864 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#include <odb/pre.hxx>
#include "Agent-odb.hxx"
#include <cassert>
#include <cstring> // std::memcpy
#include <odb/pgsql/traits.hxx>
#include <odb/pgsql/database.hxx>
#include <odb/pgsql/transaction.hxx>
#include <odb/pgsql/connection.hxx>
#include <odb/pgsql/statement.hxx>
#include <odb/pgsql/statement-cache.hxx>
#include <odb/pgsql/simple-object-statements.hxx>
#include <odb/pgsql/container-statements.hxx>
#include <odb/pgsql/exceptions.hxx>
#include <odb/pgsql/simple-object-result.hxx>
namespace odb
{
// Agent
//
const char access::object_traits_impl< ::models::Agent, id_pgsql >::
persist_statement_name[] = "persist_models_Agent";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::
find_statement_name[] = "find_models_Agent";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::
update_statement_name[] = "update_models_Agent";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::
erase_statement_name[] = "erase_models_Agent";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::
query_statement_name[] = "query_models_Agent";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::
erase_query_statement_name[] = "erase_query_models_Agent";
const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >::
persist_statement_types[] =
{
pgsql::text_oid,
pgsql::text_oid,
pgsql::bool_oid,
pgsql::text_oid,
pgsql::int4_oid
};
const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >::
find_statement_types[] =
{
pgsql::text_oid
};
const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >::
update_statement_types[] =
{
pgsql::text_oid,
pgsql::bool_oid,
pgsql::text_oid,
pgsql::int4_oid,
pgsql::text_oid
};
struct access::object_traits_impl< ::models::Agent, id_pgsql >::extra_statement_cache_type
{
extra_statement_cache_type (
pgsql::connection&,
image_type&,
id_image_type&,
pgsql::binding&,
pgsql::binding&,
pgsql::native_binding&,
const unsigned int*)
{
}
};
access::object_traits_impl< ::models::Agent, id_pgsql >::id_type
access::object_traits_impl< ::models::Agent, id_pgsql >::
id (const image_type& i)
{
pgsql::database* db (0);
ODB_POTENTIALLY_UNUSED (db);
id_type id;
{
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
id,
i.id_value,
i.id_size,
i.id_null);
}
return id;
}
bool access::object_traits_impl< ::models::Agent, id_pgsql >::
grow (image_type& i,
bool* t)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (t);
bool grew (false);
// id
//
if (t[0UL])
{
i.id_value.capacity (i.id_size);
grew = true;
}
// role
//
if (t[1UL])
{
i.role_value.capacity (i.role_size);
grew = true;
}
// persistent
//
t[2UL] = 0;
// displayName
//
if (t[3UL])
{
i.displayName_value.capacity (i.displayName_size);
grew = true;
}
// trustScore
//
t[4UL] = 0;
return grew;
}
void access::object_traits_impl< ::models::Agent, id_pgsql >::
bind (pgsql::bind* b,
image_type& i,
pgsql::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (sk);
using namespace pgsql;
std::size_t n (0);
// id
//
if (sk != statement_update)
{
b[n].type = pgsql::bind::text;
b[n].buffer = i.id_value.data ();
b[n].capacity = i.id_value.capacity ();
b[n].size = &i.id_size;
b[n].is_null = &i.id_null;
n++;
}
// role
//
b[n].type = pgsql::bind::text;
b[n].buffer = i.role_value.data ();
b[n].capacity = i.role_value.capacity ();
b[n].size = &i.role_size;
b[n].is_null = &i.role_null;
n++;
// persistent
//
b[n].type = pgsql::bind::boolean_;
b[n].buffer = &i.persistent_value;
b[n].is_null = &i.persistent_null;
n++;
// displayName
//
b[n].type = pgsql::bind::text;
b[n].buffer = i.displayName_value.data ();
b[n].capacity = i.displayName_value.capacity ();
b[n].size = &i.displayName_size;
b[n].is_null = &i.displayName_null;
n++;
// trustScore
//
b[n].type = pgsql::bind::integer;
b[n].buffer = &i.trustScore_value;
b[n].is_null = &i.trustScore_null;
n++;
}
void access::object_traits_impl< ::models::Agent, id_pgsql >::
bind (pgsql::bind* b, id_image_type& i)
{
std::size_t n (0);
b[n].type = pgsql::bind::text;
b[n].buffer = i.id_value.data ();
b[n].capacity = i.id_value.capacity ();
b[n].size = &i.id_size;
b[n].is_null = &i.id_null;
}
bool access::object_traits_impl< ::models::Agent, id_pgsql >::
init (image_type& i,
const object_type& o,
pgsql::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (sk);
using namespace pgsql;
bool grew (false);
// id
//
if (sk == statement_insert)
{
::std::string const& v =
o.id;
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.id_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.id_value,
size,
is_null,
v);
i.id_null = is_null;
i.id_size = size;
grew = grew || (cap != i.id_value.capacity ());
}
// role
//
{
::std::string const& v =
o.role;
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.role_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.role_value,
size,
is_null,
v);
i.role_null = is_null;
i.role_size = size;
grew = grew || (cap != i.role_value.capacity ());
}
// persistent
//
{
bool const& v =
o.persistent;
bool is_null (false);
pgsql::value_traits<
bool,
pgsql::id_boolean >::set_image (
i.persistent_value, is_null, v);
i.persistent_null = is_null;
}
// displayName
//
{
::std::string const& v =
o.displayName;
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.displayName_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.displayName_value,
size,
is_null,
v);
i.displayName_null = is_null;
i.displayName_size = size;
grew = grew || (cap != i.displayName_value.capacity ());
}
// trustScore
//
{
::int32_t const& v =
o.trustScore;
bool is_null (false);
pgsql::value_traits<
::int32_t,
pgsql::id_integer >::set_image (
i.trustScore_value, is_null, v);
i.trustScore_null = is_null;
}
return grew;
}
void access::object_traits_impl< ::models::Agent, id_pgsql >::
init (object_type& o,
const image_type& i,
database* db)
{
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (db);
// id
//
{
::std::string& v =
o.id;
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
v,
i.id_value,
i.id_size,
i.id_null);
}
// role
//
{
::std::string& v =
o.role;
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
v,
i.role_value,
i.role_size,
i.role_null);
}
// persistent
//
{
bool& v =
o.persistent;
pgsql::value_traits<
bool,
pgsql::id_boolean >::set_value (
v,
i.persistent_value,
i.persistent_null);
}
// displayName
//
{
::std::string& v =
o.displayName;
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
v,
i.displayName_value,
i.displayName_size,
i.displayName_null);
}
// trustScore
//
{
::int32_t& v =
o.trustScore;
pgsql::value_traits<
::int32_t,
pgsql::id_integer >::set_value (
v,
i.trustScore_value,
i.trustScore_null);
}
}
void access::object_traits_impl< ::models::Agent, id_pgsql >::
init (id_image_type& i, const id_type& id)
{
bool grew (false);
{
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.id_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.id_value,
size,
is_null,
id);
i.id_null = is_null;
i.id_size = size;
grew = grew || (cap != i.id_value.capacity ());
}
if (grew)
i.version++;
}
const char access::object_traits_impl< ::models::Agent, id_pgsql >::persist_statement[] =
"INSERT INTO \"Agent\" "
"(\"id\", "
"\"role\", "
"\"persistent\", "
"\"displayName\", "
"\"trustScore\") "
"VALUES "
"($1, $2, $3, $4, $5)";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::find_statement[] =
"SELECT "
"\"Agent\".\"id\", "
"\"Agent\".\"role\", "
"\"Agent\".\"persistent\", "
"\"Agent\".\"displayName\", "
"\"Agent\".\"trustScore\" "
"FROM \"Agent\" "
"WHERE \"Agent\".\"id\"=$1";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::update_statement[] =
"UPDATE \"Agent\" "
"SET "
"\"role\"=$1, "
"\"persistent\"=$2, "
"\"displayName\"=$3, "
"\"trustScore\"=$4 "
"WHERE \"id\"=$5";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::erase_statement[] =
"DELETE FROM \"Agent\" "
"WHERE \"id\"=$1";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::query_statement[] =
"SELECT "
"\"Agent\".\"id\", "
"\"Agent\".\"role\", "
"\"Agent\".\"persistent\", "
"\"Agent\".\"displayName\", "
"\"Agent\".\"trustScore\" "
"FROM \"Agent\"";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::erase_query_statement[] =
"DELETE FROM \"Agent\"";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::table_name[] =
"\"Agent\"";
void access::object_traits_impl< ::models::Agent, id_pgsql >::
persist (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
callback (db,
obj,
callback_event::pre_persist);
image_type& im (sts.image ());
binding& imb (sts.insert_image_binding ());
if (init (im, obj, statement_insert))
im.version++;
if (im.version != sts.insert_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_insert);
sts.insert_image_version (im.version);
imb.version++;
}
insert_statement& st (sts.persist_statement ());
if (!st.execute ())
throw object_already_persistent ();
callback (db,
obj,
callback_event::post_persist);
}
void access::object_traits_impl< ::models::Agent, id_pgsql >::
update (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace pgsql;
using pgsql::update_statement;
callback (db, obj, callback_event::pre_update);
pgsql::transaction& tr (pgsql::transaction::current ());
pgsql::connection& conn (tr.connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
const id_type& id (
obj.id);
id_image_type& idi (sts.id_image ());
init (idi, id);
image_type& im (sts.image ());
if (init (im, obj, statement_update))
im.version++;
bool u (false);
binding& imb (sts.update_image_binding ());
if (im.version != sts.update_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_update);
sts.update_image_version (im.version);
imb.version++;
u = true;
}
binding& idb (sts.id_image_binding ());
if (idi.version != sts.update_id_image_version () ||
idb.version == 0)
{
if (idi.version != sts.id_image_version () ||
idb.version == 0)
{
bind (idb.bind, idi);
sts.id_image_version (idi.version);
idb.version++;
}
sts.update_id_image_version (idi.version);
if (!u)
imb.version++;
}
update_statement& st (sts.update_statement ());
if (st.execute () == 0)
throw object_not_persistent ();
callback (db, obj, callback_event::post_update);
pointer_cache_traits::update (db, obj);
}
void access::object_traits_impl< ::models::Agent, id_pgsql >::
erase (database& db, const id_type& id)
{
using namespace pgsql;
ODB_POTENTIALLY_UNUSED (db);
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
id_image_type& i (sts.id_image ());
init (i, id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
if (sts.erase_statement ().execute () != 1)
throw object_not_persistent ();
pointer_cache_traits::erase (db, id);
}
access::object_traits_impl< ::models::Agent, id_pgsql >::pointer_type
access::object_traits_impl< ::models::Agent, id_pgsql >::
find (database& db, const id_type& id)
{
using namespace pgsql;
{
pointer_type p (pointer_cache_traits::find (db, id));
if (!pointer_traits::null_ptr (p))
return p;
}
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (l.locked ())
{
if (!find_ (sts, &id))
return pointer_type ();
}
pointer_type p (
access::object_factory<object_type, pointer_type>::create ());
pointer_traits::guard pg (p);
pointer_cache_traits::insert_guard ig (
pointer_cache_traits::insert (db, id, p));
object_type& obj (pointer_traits::get_ref (p));
if (l.locked ())
{
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
pointer_cache_traits::load (ig.position ());
}
else
sts.delay_load (id, obj, ig.position ());
ig.release ();
pg.release ();
return p;
}
bool access::object_traits_impl< ::models::Agent, id_pgsql >::
find (database& db, const id_type& id, object_type& obj)
{
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
reference_cache_traits::position_type pos (
reference_cache_traits::insert (db, id, obj));
reference_cache_traits::insert_guard ig (pos);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
reference_cache_traits::load (pos);
ig.release ();
return true;
}
bool access::object_traits_impl< ::models::Agent, id_pgsql >::
reload (database& db, object_type& obj)
{
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
const id_type& id (
obj.id);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, true);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
return true;
}
bool access::object_traits_impl< ::models::Agent, id_pgsql >::
find_ (statements_type& sts,
const id_type* id)
{
using namespace pgsql;
id_image_type& i (sts.id_image ());
init (i, *id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
select_statement& st (sts.find_statement ());
st.execute ();
auto_result ar (st);
select_statement::result r (st.fetch ());
if (r == select_statement::truncated)
{
if (grow (im, sts.select_image_truncated ()))
im.version++;
if (im.version != sts.select_image_version ())
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
st.refetch ();
}
}
return r != select_statement::no_data;
}
result< access::object_traits_impl< ::models::Agent, id_pgsql >::object_type >
access::object_traits_impl< ::models::Agent, id_pgsql >::
query (database&, const query_base_type& q)
{
using namespace pgsql;
using odb::details::shared;
using odb::details::shared_ptr;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
std::string text (query_statement);
if (!q.empty ())
{
text += " ";
text += q.clause ();
}
q.init_parameters ();
shared_ptr<select_statement> st (
new (shared) select_statement (
sts.connection (),
query_statement_name,
text,
false,
true,
q.parameter_types (),
q.parameter_count (),
q.parameters_binding (),
imb));
st->execute ();
st->deallocate ();
shared_ptr< odb::object_result_impl<object_type> > r (
new (shared) pgsql::object_result_impl<object_type> (
q, st, sts, 0));
return result<object_type> (r);
}
unsigned long long access::object_traits_impl< ::models::Agent, id_pgsql >::
erase_query (database&, const query_base_type& q)
{
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
std::string text (erase_query_statement);
if (!q.empty ())
{
text += ' ';
text += q.clause ();
}
q.init_parameters ();
delete_statement st (
conn,
erase_query_statement_name,
text,
q.parameter_types (),
q.parameter_count (),
q.parameters_binding ());
return st.execute ();
}
}
#include <odb/post.hxx>
@@ -0,0 +1,353 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef AGENT_ODB_HXX
#define AGENT_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "Agent.h"
#include <memory>
#include <cstddef>
#include <utility>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// Agent
//
template <>
struct class_traits< ::models::Agent >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::models::Agent >
{
public:
typedef ::models::Agent object_type;
typedef ::models::Agent* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;
static const bool polymorphic = false;
typedef ::std::string id_type;
static const bool auto_id = false;
static const bool abstract = false;
static id_type
id (const object_type&);
typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;
typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;
static void
callback (database&, object_type&, callback_event);
static void
callback (database&, const object_type&, callback_event);
};
}
#include <odb/details/buffer.hxx>
#include <odb/pgsql/version.hxx>
#include <odb/pgsql/forward.hxx>
#include <odb/pgsql/binding.hxx>
#include <odb/pgsql/pgsql-types.hxx>
#include <odb/pgsql/query.hxx>
namespace odb
{
// Agent
//
template <typename A>
struct query_columns< ::models::Agent, id_pgsql, A >
{
// id
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
id_type_;
static const id_type_ id;
// role
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
role_type_;
static const role_type_ role;
// persistent
//
typedef
pgsql::query_column<
pgsql::value_traits<
bool,
pgsql::id_boolean >::query_type,
pgsql::id_boolean >
persistent_type_;
static const persistent_type_ persistent;
// displayName
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
displayName_type_;
static const displayName_type_ displayName;
// trustScore
//
typedef
pgsql::query_column<
pgsql::value_traits<
::int32_t,
pgsql::id_integer >::query_type,
pgsql::id_integer >
trustScore_type_;
static const trustScore_type_ trustScore;
};
template <typename A>
const typename query_columns< ::models::Agent, id_pgsql, A >::id_type_
query_columns< ::models::Agent, id_pgsql, A >::
id (A::table_name, "\"id\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_pgsql, A >::role_type_
query_columns< ::models::Agent, id_pgsql, A >::
role (A::table_name, "\"role\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_pgsql, A >::persistent_type_
query_columns< ::models::Agent, id_pgsql, A >::
persistent (A::table_name, "\"persistent\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_pgsql, A >::displayName_type_
query_columns< ::models::Agent, id_pgsql, A >::
displayName (A::table_name, "\"displayName\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_pgsql, A >::trustScore_type_
query_columns< ::models::Agent, id_pgsql, A >::
trustScore (A::table_name, "\"trustScore\"", 0);
template <typename A>
struct pointer_query_columns< ::models::Agent, id_pgsql, A >:
query_columns< ::models::Agent, id_pgsql, A >
{
};
template <>
class access::object_traits_impl< ::models::Agent, id_pgsql >:
public access::object_traits< ::models::Agent >
{
public:
struct id_image_type
{
details::buffer id_value;
std::size_t id_size;
bool id_null;
std::size_t version;
};
struct image_type
{
// id
//
details::buffer id_value;
std::size_t id_size;
bool id_null;
// role
//
details::buffer role_value;
std::size_t role_size;
bool role_null;
// persistent
//
bool persistent_value;
bool persistent_null;
// displayName
//
details::buffer displayName_value;
std::size_t displayName_size;
bool displayName_null;
// trustScore
//
int trustScore_value;
bool trustScore_null;
std::size_t version;
};
struct extra_statement_cache_type;
using object_traits<object_type>::id;
static id_type
id (const image_type&);
static bool
grow (image_type&,
bool*);
static void
bind (pgsql::bind*,
image_type&,
pgsql::statement_kind);
static void
bind (pgsql::bind*, id_image_type&);
static bool
init (image_type&,
const object_type&,
pgsql::statement_kind);
static void
init (object_type&,
const image_type&,
database*);
static void
init (id_image_type&, const id_type&);
typedef pgsql::object_statements<object_type> statements_type;
typedef pgsql::query_base query_base_type;
static const std::size_t column_count = 5UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 0UL;
static const std::size_t managed_optimistic_column_count = 0UL;
static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;
static const bool versioned = false;
static const char persist_statement[];
static const char find_statement[];
static const char update_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];
static const char table_name[];
static void
persist (database&, const object_type&);
static pointer_type
find (database&, const id_type&);
static bool
find (database&, const id_type&, object_type&);
static bool
reload (database&, object_type&);
static void
update (database&, const object_type&);
static void
erase (database&, const id_type&);
static void
erase (database&, const object_type&);
static result<object_type>
query (database&, const query_base_type&);
static unsigned long long
erase_query (database&, const query_base_type&);
static const char persist_statement_name[];
static const char find_statement_name[];
static const char update_statement_name[];
static const char erase_statement_name[];
static const char query_statement_name[];
static const char erase_query_statement_name[];
static const unsigned int persist_statement_types[];
static const unsigned int find_statement_types[];
static const unsigned int update_statement_types[];
public:
static bool
find_ (statements_type&,
const id_type*);
static void
load_ (statements_type&,
object_type&,
bool reload);
};
template <>
class access::object_traits_impl< ::models::Agent, id_common >:
public access::object_traits_impl< ::models::Agent, id_pgsql >
{
};
// Agent
//
}
#include "Agent-odb.ixx"
#include <odb/post.hxx>
#endif // AGENT_ODB_HXX
@@ -0,0 +1,61 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
namespace odb
{
// Agent
//
inline
access::object_traits< ::models::Agent >::id_type
access::object_traits< ::models::Agent >::
id (const object_type& o)
{
return o.id;
}
inline
void access::object_traits< ::models::Agent >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
inline
void access::object_traits< ::models::Agent >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}
namespace odb
{
// Agent
//
inline
void access::object_traits_impl< ::models::Agent, id_pgsql >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}
inline
void access::object_traits_impl< ::models::Agent, id_pgsql >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}
@@ -0,0 +1,16 @@
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="pgsql" version="1">
<changeset version="2">
<add-table name="Agent" kind="object">
<column name="id" type="TEXT" null="false"/>
<column name="role" type="TEXT" null="false"/>
<column name="persistent" type="BOOLEAN" null="false"/>
<column name="displayName" type="TEXT" null="false"/>
<column name="trustScore" type="INTEGER" null="false"/>
<primary-key>
<column name="id"/>
</primary-key>
</add-table>
</changeset>
<model version="1"/>
</changelog>
@@ -0,0 +1,774 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#include <odb/pre.hxx>
#include "GovernmentAddress-odb.hxx"
#include <cassert>
#include <cstring> // std::memcpy
#include <odb/pgsql/traits.hxx>
#include <odb/pgsql/database.hxx>
#include <odb/pgsql/transaction.hxx>
#include <odb/pgsql/connection.hxx>
#include <odb/pgsql/statement.hxx>
#include <odb/pgsql/statement-cache.hxx>
#include <odb/pgsql/simple-object-statements.hxx>
#include <odb/pgsql/container-statements.hxx>
#include <odb/pgsql/exceptions.hxx>
#include <odb/pgsql/simple-object-result.hxx>
namespace odb
{
// GovernmentAddress
//
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
persist_statement_name[] = "persist_models_GovernmentAddress";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
find_statement_name[] = "find_models_GovernmentAddress";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
update_statement_name[] = "update_models_GovernmentAddress";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
erase_statement_name[] = "erase_models_GovernmentAddress";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
query_statement_name[] = "query_models_GovernmentAddress";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
erase_query_statement_name[] = "erase_query_models_GovernmentAddress";
const unsigned int access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
persist_statement_types[] =
{
pgsql::text_oid,
pgsql::text_oid,
pgsql::text_oid
};
const unsigned int access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
find_statement_types[] =
{
pgsql::text_oid
};
const unsigned int access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
update_statement_types[] =
{
pgsql::text_oid,
pgsql::text_oid,
pgsql::text_oid
};
struct access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::extra_statement_cache_type
{
extra_statement_cache_type (
pgsql::connection&,
image_type&,
id_image_type&,
pgsql::binding&,
pgsql::binding&,
pgsql::native_binding&,
const unsigned int*)
{
}
};
access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::id_type
access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
id (const image_type& i)
{
pgsql::database* db (0);
ODB_POTENTIALLY_UNUSED (db);
id_type id;
{
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
id,
i.id_value,
i.id_size,
i.id_null);
}
return id;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
grow (image_type& i,
bool* t)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (t);
bool grew (false);
// id
//
if (t[0UL])
{
i.id_value.capacity (i.id_size);
grew = true;
}
// addressLabel
//
if (t[1UL])
{
i.addressLabel_value.capacity (i.addressLabel_size);
grew = true;
}
// regionLookupKey
//
if (t[2UL])
{
i.regionLookupKey_value.capacity (i.regionLookupKey_size);
grew = true;
}
return grew;
}
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
bind (pgsql::bind* b,
image_type& i,
pgsql::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (sk);
using namespace pgsql;
std::size_t n (0);
// id
//
if (sk != statement_update)
{
b[n].type = pgsql::bind::text;
b[n].buffer = i.id_value.data ();
b[n].capacity = i.id_value.capacity ();
b[n].size = &i.id_size;
b[n].is_null = &i.id_null;
n++;
}
// addressLabel
//
b[n].type = pgsql::bind::text;
b[n].buffer = i.addressLabel_value.data ();
b[n].capacity = i.addressLabel_value.capacity ();
b[n].size = &i.addressLabel_size;
b[n].is_null = &i.addressLabel_null;
n++;
// regionLookupKey
//
b[n].type = pgsql::bind::text;
b[n].buffer = i.regionLookupKey_value.data ();
b[n].capacity = i.regionLookupKey_value.capacity ();
b[n].size = &i.regionLookupKey_size;
b[n].is_null = &i.regionLookupKey_null;
n++;
}
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
bind (pgsql::bind* b, id_image_type& i)
{
std::size_t n (0);
b[n].type = pgsql::bind::text;
b[n].buffer = i.id_value.data ();
b[n].capacity = i.id_value.capacity ();
b[n].size = &i.id_size;
b[n].is_null = &i.id_null;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
init (image_type& i,
const object_type& o,
pgsql::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (sk);
using namespace pgsql;
bool grew (false);
// id
//
if (sk == statement_insert)
{
::std::string const& v =
o.id;
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.id_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.id_value,
size,
is_null,
v);
i.id_null = is_null;
i.id_size = size;
grew = grew || (cap != i.id_value.capacity ());
}
// addressLabel
//
{
::std::string const& v =
o.addressLabel;
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.addressLabel_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.addressLabel_value,
size,
is_null,
v);
i.addressLabel_null = is_null;
i.addressLabel_size = size;
grew = grew || (cap != i.addressLabel_value.capacity ());
}
// regionLookupKey
//
{
::std::string const& v =
o.regionLookupKey;
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.regionLookupKey_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.regionLookupKey_value,
size,
is_null,
v);
i.regionLookupKey_null = is_null;
i.regionLookupKey_size = size;
grew = grew || (cap != i.regionLookupKey_value.capacity ());
}
return grew;
}
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
init (object_type& o,
const image_type& i,
database* db)
{
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (db);
// id
//
{
::std::string& v =
o.id;
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
v,
i.id_value,
i.id_size,
i.id_null);
}
// addressLabel
//
{
::std::string& v =
o.addressLabel;
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
v,
i.addressLabel_value,
i.addressLabel_size,
i.addressLabel_null);
}
// regionLookupKey
//
{
::std::string& v =
o.regionLookupKey;
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
v,
i.regionLookupKey_value,
i.regionLookupKey_size,
i.regionLookupKey_null);
}
}
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
init (id_image_type& i, const id_type& id)
{
bool grew (false);
{
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.id_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.id_value,
size,
is_null,
id);
i.id_null = is_null;
i.id_size = size;
grew = grew || (cap != i.id_value.capacity ());
}
if (grew)
i.version++;
}
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::persist_statement[] =
"INSERT INTO \"GovernmentAddress\" "
"(\"id\", "
"\"addressLabel\", "
"\"regionLookupKey\") "
"VALUES "
"($1, $2, $3)";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::find_statement[] =
"SELECT "
"\"GovernmentAddress\".\"id\", "
"\"GovernmentAddress\".\"addressLabel\", "
"\"GovernmentAddress\".\"regionLookupKey\" "
"FROM \"GovernmentAddress\" "
"WHERE \"GovernmentAddress\".\"id\"=$1";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::update_statement[] =
"UPDATE \"GovernmentAddress\" "
"SET "
"\"addressLabel\"=$1, "
"\"regionLookupKey\"=$2 "
"WHERE \"id\"=$3";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::erase_statement[] =
"DELETE FROM \"GovernmentAddress\" "
"WHERE \"id\"=$1";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::query_statement[] =
"SELECT "
"\"GovernmentAddress\".\"id\", "
"\"GovernmentAddress\".\"addressLabel\", "
"\"GovernmentAddress\".\"regionLookupKey\" "
"FROM \"GovernmentAddress\"";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::erase_query_statement[] =
"DELETE FROM \"GovernmentAddress\"";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::table_name[] =
"\"GovernmentAddress\"";
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
persist (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
callback (db,
obj,
callback_event::pre_persist);
image_type& im (sts.image ());
binding& imb (sts.insert_image_binding ());
if (init (im, obj, statement_insert))
im.version++;
if (im.version != sts.insert_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_insert);
sts.insert_image_version (im.version);
imb.version++;
}
insert_statement& st (sts.persist_statement ());
if (!st.execute ())
throw object_already_persistent ();
callback (db,
obj,
callback_event::post_persist);
}
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
update (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace pgsql;
using pgsql::update_statement;
callback (db, obj, callback_event::pre_update);
pgsql::transaction& tr (pgsql::transaction::current ());
pgsql::connection& conn (tr.connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
const id_type& id (
obj.id);
id_image_type& idi (sts.id_image ());
init (idi, id);
image_type& im (sts.image ());
if (init (im, obj, statement_update))
im.version++;
bool u (false);
binding& imb (sts.update_image_binding ());
if (im.version != sts.update_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_update);
sts.update_image_version (im.version);
imb.version++;
u = true;
}
binding& idb (sts.id_image_binding ());
if (idi.version != sts.update_id_image_version () ||
idb.version == 0)
{
if (idi.version != sts.id_image_version () ||
idb.version == 0)
{
bind (idb.bind, idi);
sts.id_image_version (idi.version);
idb.version++;
}
sts.update_id_image_version (idi.version);
if (!u)
imb.version++;
}
update_statement& st (sts.update_statement ());
if (st.execute () == 0)
throw object_not_persistent ();
callback (db, obj, callback_event::post_update);
pointer_cache_traits::update (db, obj);
}
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
erase (database& db, const id_type& id)
{
using namespace pgsql;
ODB_POTENTIALLY_UNUSED (db);
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
id_image_type& i (sts.id_image ());
init (i, id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
if (sts.erase_statement ().execute () != 1)
throw object_not_persistent ();
pointer_cache_traits::erase (db, id);
}
access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::pointer_type
access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
find (database& db, const id_type& id)
{
using namespace pgsql;
{
pointer_type p (pointer_cache_traits::find (db, id));
if (!pointer_traits::null_ptr (p))
return p;
}
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (l.locked ())
{
if (!find_ (sts, &id))
return pointer_type ();
}
pointer_type p (
access::object_factory<object_type, pointer_type>::create ());
pointer_traits::guard pg (p);
pointer_cache_traits::insert_guard ig (
pointer_cache_traits::insert (db, id, p));
object_type& obj (pointer_traits::get_ref (p));
if (l.locked ())
{
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
pointer_cache_traits::load (ig.position ());
}
else
sts.delay_load (id, obj, ig.position ());
ig.release ();
pg.release ();
return p;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
find (database& db, const id_type& id, object_type& obj)
{
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
reference_cache_traits::position_type pos (
reference_cache_traits::insert (db, id, obj));
reference_cache_traits::insert_guard ig (pos);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
reference_cache_traits::load (pos);
ig.release ();
return true;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
reload (database& db, object_type& obj)
{
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
const id_type& id (
obj.id);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, true);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
return true;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
find_ (statements_type& sts,
const id_type* id)
{
using namespace pgsql;
id_image_type& i (sts.id_image ());
init (i, *id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
select_statement& st (sts.find_statement ());
st.execute ();
auto_result ar (st);
select_statement::result r (st.fetch ());
if (r == select_statement::truncated)
{
if (grow (im, sts.select_image_truncated ()))
im.version++;
if (im.version != sts.select_image_version ())
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
st.refetch ();
}
}
return r != select_statement::no_data;
}
result< access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::object_type >
access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
query (database&, const query_base_type& q)
{
using namespace pgsql;
using odb::details::shared;
using odb::details::shared_ptr;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
std::string text (query_statement);
if (!q.empty ())
{
text += " ";
text += q.clause ();
}
q.init_parameters ();
shared_ptr<select_statement> st (
new (shared) select_statement (
sts.connection (),
query_statement_name,
text,
false,
true,
q.parameter_types (),
q.parameter_count (),
q.parameters_binding (),
imb));
st->execute ();
st->deallocate ();
shared_ptr< odb::object_result_impl<object_type> > r (
new (shared) pgsql::object_result_impl<object_type> (
q, st, sts, 0));
return result<object_type> (r);
}
unsigned long long access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
erase_query (database&, const query_base_type& q)
{
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
std::string text (erase_query_statement);
if (!q.empty ())
{
text += ' ';
text += q.clause ();
}
q.init_parameters ();
delete_statement st (
conn,
erase_query_statement_name,
text,
q.parameter_types (),
q.parameter_count (),
q.parameters_binding ());
return st.execute ();
}
}
#include <odb/post.hxx>
@@ -0,0 +1,309 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef GOVERNMENT_ADDRESS_ODB_HXX
#define GOVERNMENT_ADDRESS_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "GovernmentAddress.h"
#include <memory>
#include <cstddef>
#include <utility>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// GovernmentAddress
//
template <>
struct class_traits< ::models::GovernmentAddress >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::models::GovernmentAddress >
{
public:
typedef ::models::GovernmentAddress object_type;
typedef ::models::GovernmentAddress* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;
static const bool polymorphic = false;
typedef ::std::string id_type;
static const bool auto_id = false;
static const bool abstract = false;
static id_type
id (const object_type&);
typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;
typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;
static void
callback (database&, object_type&, callback_event);
static void
callback (database&, const object_type&, callback_event);
};
}
#include <odb/details/buffer.hxx>
#include <odb/pgsql/version.hxx>
#include <odb/pgsql/forward.hxx>
#include <odb/pgsql/binding.hxx>
#include <odb/pgsql/pgsql-types.hxx>
#include <odb/pgsql/query.hxx>
namespace odb
{
// GovernmentAddress
//
template <typename A>
struct query_columns< ::models::GovernmentAddress, id_pgsql, A >
{
// id
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
id_type_;
static const id_type_ id;
// addressLabel
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
addressLabel_type_;
static const addressLabel_type_ addressLabel;
// regionLookupKey
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
regionLookupKey_type_;
static const regionLookupKey_type_ regionLookupKey;
};
template <typename A>
const typename query_columns< ::models::GovernmentAddress, id_pgsql, A >::id_type_
query_columns< ::models::GovernmentAddress, id_pgsql, A >::
id (A::table_name, "\"id\"", 0);
template <typename A>
const typename query_columns< ::models::GovernmentAddress, id_pgsql, A >::addressLabel_type_
query_columns< ::models::GovernmentAddress, id_pgsql, A >::
addressLabel (A::table_name, "\"addressLabel\"", 0);
template <typename A>
const typename query_columns< ::models::GovernmentAddress, id_pgsql, A >::regionLookupKey_type_
query_columns< ::models::GovernmentAddress, id_pgsql, A >::
regionLookupKey (A::table_name, "\"regionLookupKey\"", 0);
template <typename A>
struct pointer_query_columns< ::models::GovernmentAddress, id_pgsql, A >:
query_columns< ::models::GovernmentAddress, id_pgsql, A >
{
};
template <>
class access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:
public access::object_traits< ::models::GovernmentAddress >
{
public:
struct id_image_type
{
details::buffer id_value;
std::size_t id_size;
bool id_null;
std::size_t version;
};
struct image_type
{
// id
//
details::buffer id_value;
std::size_t id_size;
bool id_null;
// addressLabel
//
details::buffer addressLabel_value;
std::size_t addressLabel_size;
bool addressLabel_null;
// regionLookupKey
//
details::buffer regionLookupKey_value;
std::size_t regionLookupKey_size;
bool regionLookupKey_null;
std::size_t version;
};
struct extra_statement_cache_type;
using object_traits<object_type>::id;
static id_type
id (const image_type&);
static bool
grow (image_type&,
bool*);
static void
bind (pgsql::bind*,
image_type&,
pgsql::statement_kind);
static void
bind (pgsql::bind*, id_image_type&);
static bool
init (image_type&,
const object_type&,
pgsql::statement_kind);
static void
init (object_type&,
const image_type&,
database*);
static void
init (id_image_type&, const id_type&);
typedef pgsql::object_statements<object_type> statements_type;
typedef pgsql::query_base query_base_type;
static const std::size_t column_count = 3UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 0UL;
static const std::size_t managed_optimistic_column_count = 0UL;
static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;
static const bool versioned = false;
static const char persist_statement[];
static const char find_statement[];
static const char update_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];
static const char table_name[];
static void
persist (database&, const object_type&);
static pointer_type
find (database&, const id_type&);
static bool
find (database&, const id_type&, object_type&);
static bool
reload (database&, object_type&);
static void
update (database&, const object_type&);
static void
erase (database&, const id_type&);
static void
erase (database&, const object_type&);
static result<object_type>
query (database&, const query_base_type&);
static unsigned long long
erase_query (database&, const query_base_type&);
static const char persist_statement_name[];
static const char find_statement_name[];
static const char update_statement_name[];
static const char erase_statement_name[];
static const char query_statement_name[];
static const char erase_query_statement_name[];
static const unsigned int persist_statement_types[];
static const unsigned int find_statement_types[];
static const unsigned int update_statement_types[];
public:
static bool
find_ (statements_type&,
const id_type*);
static void
load_ (statements_type&,
object_type&,
bool reload);
};
template <>
class access::object_traits_impl< ::models::GovernmentAddress, id_common >:
public access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >
{
};
// GovernmentAddress
//
}
#include "GovernmentAddress-odb.ixx"
#include <odb/post.hxx>
#endif // GOVERNMENT_ADDRESS_ODB_HXX
@@ -0,0 +1,61 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
namespace odb
{
// GovernmentAddress
//
inline
access::object_traits< ::models::GovernmentAddress >::id_type
access::object_traits< ::models::GovernmentAddress >::
id (const object_type& o)
{
return o.id;
}
inline
void access::object_traits< ::models::GovernmentAddress >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
inline
void access::object_traits< ::models::GovernmentAddress >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}
namespace odb
{
// GovernmentAddress
//
inline
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}
inline
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}
@@ -0,0 +1,14 @@
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="pgsql" version="1">
<changeset version="2">
<add-table name="GovernmentAddress" kind="object">
<column name="id" type="TEXT" null="false"/>
<column name="addressLabel" type="TEXT" null="false"/>
<column name="regionLookupKey" type="TEXT" null="false"/>
<primary-key>
<column name="id"/>
</primary-key>
</add-table>
</changeset>
<model version="1"/>
</changelog>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,516 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef TRIP_ATTEMPT_RESULT_ODB_HXX
#define TRIP_ATTEMPT_RESULT_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "TripAttemptResult.h"
#include <memory>
#include <cstddef>
#include <utility>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// TripAttemptResult
//
template <>
struct class_traits< ::models::TripAttemptResult >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::models::TripAttemptResult >
{
public:
typedef ::models::TripAttemptResult object_type;
typedef ::models::TripAttemptResult* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;
static const bool polymorphic = false;
typedef ::std::string id_type;
static const bool auto_id = false;
static const bool abstract = false;
static id_type
id (const object_type&);
typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;
typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;
static void
callback (database&, object_type&, callback_event);
static void
callback (database&, const object_type&, callback_event);
};
}
#include <odb/details/buffer.hxx>
#include <odb/pgsql/version.hxx>
#include <odb/pgsql/forward.hxx>
#include <odb/pgsql/binding.hxx>
#include <odb/pgsql/pgsql-types.hxx>
#include <odb/pgsql/query.hxx>
namespace odb
{
// TripAttemptResult
//
template <typename A>
struct query_columns< ::models::TripAttemptResult, id_pgsql, A >
{
// id
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
id_type_;
static const id_type_ id;
// result
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
result_type_;
static const result_type_ result;
// retryReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
retryReason_type_;
static const retryReason_type_ retryReason;
// governmentSuspensionReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
governmentSuspensionReason_type_;
static const governmentSuspensionReason_type_ governmentSuspensionReason;
// governmentTerminationReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
governmentTerminationReason_type_;
static const governmentTerminationReason_type_ governmentTerminationReason;
// complianceSuspensionReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
complianceSuspensionReason_type_;
static const complianceSuspensionReason_type_ complianceSuspensionReason;
// complianceTerminationReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
complianceTerminationReason_type_;
static const complianceTerminationReason_type_ complianceTerminationReason;
// policySuspensionReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
policySuspensionReason_type_;
static const policySuspensionReason_type_ policySuspensionReason;
// policyTerminationReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
policyTerminationReason_type_;
static const policyTerminationReason_type_ policyTerminationReason;
// cancelationReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
cancelationReason_type_;
static const cancelationReason_type_ cancelationReason;
// failureReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
failureReason_type_;
static const failureReason_type_ failureReason;
// details
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
details_type_;
static const details_type_ details;
};
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::id_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
id (A::table_name, "\"id\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::result_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
result (A::table_name, "\"result\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::retryReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
retryReason (A::table_name, "\"retryReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::governmentSuspensionReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
governmentSuspensionReason (A::table_name, "\"governmentSuspensionReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::governmentTerminationReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
governmentTerminationReason (A::table_name, "\"governmentTerminationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::complianceSuspensionReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
complianceSuspensionReason (A::table_name, "\"complianceSuspensionReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::complianceTerminationReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
complianceTerminationReason (A::table_name, "\"complianceTerminationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::policySuspensionReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
policySuspensionReason (A::table_name, "\"policySuspensionReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::policyTerminationReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
policyTerminationReason (A::table_name, "\"policyTerminationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::cancelationReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
cancelationReason (A::table_name, "\"cancelationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::failureReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
failureReason (A::table_name, "\"failureReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::details_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
details (A::table_name, "\"details\"", 0);
template <typename A>
struct pointer_query_columns< ::models::TripAttemptResult, id_pgsql, A >:
query_columns< ::models::TripAttemptResult, id_pgsql, A >
{
};
template <>
class access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:
public access::object_traits< ::models::TripAttemptResult >
{
public:
struct id_image_type
{
details::buffer id_value;
std::size_t id_size;
bool id_null;
std::size_t version;
};
struct image_type
{
// id
//
details::buffer id_value;
std::size_t id_size;
bool id_null;
// result
//
details::buffer result_value;
std::size_t result_size;
bool result_null;
// retryReason
//
details::buffer retryReason_value;
std::size_t retryReason_size;
bool retryReason_null;
// governmentSuspensionReason
//
details::buffer governmentSuspensionReason_value;
std::size_t governmentSuspensionReason_size;
bool governmentSuspensionReason_null;
// governmentTerminationReason
//
details::buffer governmentTerminationReason_value;
std::size_t governmentTerminationReason_size;
bool governmentTerminationReason_null;
// complianceSuspensionReason
//
details::buffer complianceSuspensionReason_value;
std::size_t complianceSuspensionReason_size;
bool complianceSuspensionReason_null;
// complianceTerminationReason
//
details::buffer complianceTerminationReason_value;
std::size_t complianceTerminationReason_size;
bool complianceTerminationReason_null;
// policySuspensionReason
//
details::buffer policySuspensionReason_value;
std::size_t policySuspensionReason_size;
bool policySuspensionReason_null;
// policyTerminationReason
//
details::buffer policyTerminationReason_value;
std::size_t policyTerminationReason_size;
bool policyTerminationReason_null;
// cancelationReason
//
details::buffer cancelationReason_value;
std::size_t cancelationReason_size;
bool cancelationReason_null;
// failureReason
//
details::buffer failureReason_value;
std::size_t failureReason_size;
bool failureReason_null;
// details
//
details::buffer details_value;
std::size_t details_size;
bool details_null;
std::size_t version;
};
struct extra_statement_cache_type;
using object_traits<object_type>::id;
static id_type
id (const image_type&);
static bool
grow (image_type&,
bool*);
static void
bind (pgsql::bind*,
image_type&,
pgsql::statement_kind);
static void
bind (pgsql::bind*, id_image_type&);
static bool
init (image_type&,
const object_type&,
pgsql::statement_kind);
static void
init (object_type&,
const image_type&,
database*);
static void
init (id_image_type&, const id_type&);
typedef pgsql::object_statements<object_type> statements_type;
typedef pgsql::query_base query_base_type;
static const std::size_t column_count = 12UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 0UL;
static const std::size_t managed_optimistic_column_count = 0UL;
static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;
static const bool versioned = false;
static const char persist_statement[];
static const char find_statement[];
static const char update_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];
static const char table_name[];
static void
persist (database&, const object_type&);
static pointer_type
find (database&, const id_type&);
static bool
find (database&, const id_type&, object_type&);
static bool
reload (database&, object_type&);
static void
update (database&, const object_type&);
static void
erase (database&, const id_type&);
static void
erase (database&, const object_type&);
static result<object_type>
query (database&, const query_base_type&);
static unsigned long long
erase_query (database&, const query_base_type&);
static const char persist_statement_name[];
static const char find_statement_name[];
static const char update_statement_name[];
static const char erase_statement_name[];
static const char query_statement_name[];
static const char erase_query_statement_name[];
static const unsigned int persist_statement_types[];
static const unsigned int find_statement_types[];
static const unsigned int update_statement_types[];
public:
static bool
find_ (statements_type&,
const id_type*);
static void
load_ (statements_type&,
object_type&,
bool reload);
};
template <>
class access::object_traits_impl< ::models::TripAttemptResult, id_common >:
public access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >
{
};
// TripAttemptResult
//
}
#include "TripAttemptResult-odb.ixx"
#include <odb/post.hxx>
#endif // TRIP_ATTEMPT_RESULT_ODB_HXX
@@ -0,0 +1,61 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
namespace odb
{
// TripAttemptResult
//
inline
access::object_traits< ::models::TripAttemptResult >::id_type
access::object_traits< ::models::TripAttemptResult >::
id (const object_type& o)
{
return o.id;
}
inline
void access::object_traits< ::models::TripAttemptResult >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
inline
void access::object_traits< ::models::TripAttemptResult >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}
namespace odb
{
// TripAttemptResult
//
inline
void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}
inline
void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}
@@ -0,0 +1,23 @@
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="pgsql" version="1">
<changeset version="2">
<add-table name="TripAttemptResult" kind="object">
<column name="id" type="TEXT" null="false"/>
<column name="result" type="TEXT" null="false"/>
<column name="retryReason" type="TEXT" null="false"/>
<column name="governmentSuspensionReason" type="TEXT" null="false"/>
<column name="governmentTerminationReason" type="TEXT" null="false"/>
<column name="complianceSuspensionReason" type="TEXT" null="false"/>
<column name="complianceTerminationReason" type="TEXT" null="false"/>
<column name="policySuspensionReason" type="TEXT" null="false"/>
<column name="policyTerminationReason" type="TEXT" null="false"/>
<column name="cancelationReason" type="TEXT" null="false"/>
<column name="failureReason" type="TEXT" null="false"/>
<column name="details" type="TEXT" null="false"/>
<primary-key>
<column name="id"/>
</primary-key>
</add-table>
</changeset>
<model version="1"/>
</changelog>
@@ -0,0 +1,815 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#include <odb/pre.hxx>
#include "Agent-odb.hxx"
#include <cassert>
#include <cstring> // std::memcpy
#include <odb/sqlite/traits.hxx>
#include <odb/sqlite/database.hxx>
#include <odb/sqlite/transaction.hxx>
#include <odb/sqlite/connection.hxx>
#include <odb/sqlite/statement.hxx>
#include <odb/sqlite/statement-cache.hxx>
#include <odb/sqlite/simple-object-statements.hxx>
#include <odb/sqlite/container-statements.hxx>
#include <odb/sqlite/exceptions.hxx>
#include <odb/sqlite/simple-object-result.hxx>
namespace odb
{
// Agent
//
struct access::object_traits_impl< ::models::Agent, id_sqlite >::extra_statement_cache_type
{
extra_statement_cache_type (
sqlite::connection&,
image_type&,
id_image_type&,
sqlite::binding&,
sqlite::binding&)
{
}
};
access::object_traits_impl< ::models::Agent, id_sqlite >::id_type
access::object_traits_impl< ::models::Agent, id_sqlite >::
id (const image_type& i)
{
sqlite::database* db (0);
ODB_POTENTIALLY_UNUSED (db);
id_type id;
{
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
id,
i.id_value,
i.id_size,
i.id_null);
}
return id;
}
bool access::object_traits_impl< ::models::Agent, id_sqlite >::
grow (image_type& i,
bool* t)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (t);
bool grew (false);
// id
//
if (t[0UL])
{
i.id_value.capacity (i.id_size);
grew = true;
}
// role
//
if (t[1UL])
{
i.role_value.capacity (i.role_size);
grew = true;
}
// persistent
//
t[2UL] = false;
// displayName
//
if (t[3UL])
{
i.displayName_value.capacity (i.displayName_size);
grew = true;
}
// trustScore
//
t[4UL] = false;
return grew;
}
void access::object_traits_impl< ::models::Agent, id_sqlite >::
bind (sqlite::bind* b,
image_type& i,
sqlite::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (sk);
using namespace sqlite;
std::size_t n (0);
// id
//
if (sk != statement_update)
{
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.id_value.data ();
b[n].size = &i.id_size;
b[n].capacity = i.id_value.capacity ();
b[n].is_null = &i.id_null;
n++;
}
// role
//
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.role_value.data ();
b[n].size = &i.role_size;
b[n].capacity = i.role_value.capacity ();
b[n].is_null = &i.role_null;
n++;
// persistent
//
b[n].type = sqlite::bind::integer;
b[n].buffer = &i.persistent_value;
b[n].is_null = &i.persistent_null;
n++;
// displayName
//
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.displayName_value.data ();
b[n].size = &i.displayName_size;
b[n].capacity = i.displayName_value.capacity ();
b[n].is_null = &i.displayName_null;
n++;
// trustScore
//
b[n].type = sqlite::bind::integer;
b[n].buffer = &i.trustScore_value;
b[n].is_null = &i.trustScore_null;
n++;
}
void access::object_traits_impl< ::models::Agent, id_sqlite >::
bind (sqlite::bind* b, id_image_type& i)
{
std::size_t n (0);
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.id_value.data ();
b[n].size = &i.id_size;
b[n].capacity = i.id_value.capacity ();
b[n].is_null = &i.id_null;
}
bool access::object_traits_impl< ::models::Agent, id_sqlite >::
init (image_type& i,
const object_type& o,
sqlite::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (sk);
using namespace sqlite;
bool grew (false);
// id
//
if (sk == statement_insert)
{
::std::string const& v =
o.id;
bool is_null (false);
std::size_t cap (i.id_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.id_value,
i.id_size,
is_null,
v);
i.id_null = is_null;
grew = grew || (cap != i.id_value.capacity ());
}
// role
//
{
::std::string const& v =
o.role;
bool is_null (false);
std::size_t cap (i.role_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.role_value,
i.role_size,
is_null,
v);
i.role_null = is_null;
grew = grew || (cap != i.role_value.capacity ());
}
// persistent
//
{
bool const& v =
o.persistent;
bool is_null (false);
sqlite::value_traits<
bool,
sqlite::id_integer >::set_image (
i.persistent_value,
is_null,
v);
i.persistent_null = is_null;
}
// displayName
//
{
::std::string const& v =
o.displayName;
bool is_null (false);
std::size_t cap (i.displayName_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.displayName_value,
i.displayName_size,
is_null,
v);
i.displayName_null = is_null;
grew = grew || (cap != i.displayName_value.capacity ());
}
// trustScore
//
{
::int32_t const& v =
o.trustScore;
bool is_null (false);
sqlite::value_traits<
::int32_t,
sqlite::id_integer >::set_image (
i.trustScore_value,
is_null,
v);
i.trustScore_null = is_null;
}
return grew;
}
void access::object_traits_impl< ::models::Agent, id_sqlite >::
init (object_type& o,
const image_type& i,
database* db)
{
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (db);
// id
//
{
::std::string& v =
o.id;
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
v,
i.id_value,
i.id_size,
i.id_null);
}
// role
//
{
::std::string& v =
o.role;
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
v,
i.role_value,
i.role_size,
i.role_null);
}
// persistent
//
{
bool& v =
o.persistent;
sqlite::value_traits<
bool,
sqlite::id_integer >::set_value (
v,
i.persistent_value,
i.persistent_null);
}
// displayName
//
{
::std::string& v =
o.displayName;
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
v,
i.displayName_value,
i.displayName_size,
i.displayName_null);
}
// trustScore
//
{
::int32_t& v =
o.trustScore;
sqlite::value_traits<
::int32_t,
sqlite::id_integer >::set_value (
v,
i.trustScore_value,
i.trustScore_null);
}
}
void access::object_traits_impl< ::models::Agent, id_sqlite >::
init (id_image_type& i, const id_type& id)
{
bool grew (false);
{
bool is_null (false);
std::size_t cap (i.id_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.id_value,
i.id_size,
is_null,
id);
i.id_null = is_null;
grew = grew || (cap != i.id_value.capacity ());
}
if (grew)
i.version++;
}
const char access::object_traits_impl< ::models::Agent, id_sqlite >::persist_statement[] =
"INSERT INTO \"Agent\" "
"(\"id\", "
"\"role\", "
"\"persistent\", "
"\"displayName\", "
"\"trustScore\") "
"VALUES "
"(?, ?, ?, ?, ?)";
const char access::object_traits_impl< ::models::Agent, id_sqlite >::find_statement[] =
"SELECT "
"\"Agent\".\"id\", "
"\"Agent\".\"role\", "
"\"Agent\".\"persistent\", "
"\"Agent\".\"displayName\", "
"\"Agent\".\"trustScore\" "
"FROM \"Agent\" "
"WHERE \"Agent\".\"id\"=?";
const char access::object_traits_impl< ::models::Agent, id_sqlite >::update_statement[] =
"UPDATE \"Agent\" "
"SET "
"\"role\"=?, "
"\"persistent\"=?, "
"\"displayName\"=?, "
"\"trustScore\"=? "
"WHERE \"id\"=?";
const char access::object_traits_impl< ::models::Agent, id_sqlite >::erase_statement[] =
"DELETE FROM \"Agent\" "
"WHERE \"id\"=?";
const char access::object_traits_impl< ::models::Agent, id_sqlite >::query_statement[] =
"SELECT "
"\"Agent\".\"id\", "
"\"Agent\".\"role\", "
"\"Agent\".\"persistent\", "
"\"Agent\".\"displayName\", "
"\"Agent\".\"trustScore\" "
"FROM \"Agent\"";
const char access::object_traits_impl< ::models::Agent, id_sqlite >::erase_query_statement[] =
"DELETE FROM \"Agent\"";
const char access::object_traits_impl< ::models::Agent, id_sqlite >::table_name[] =
"\"Agent\"";
void access::object_traits_impl< ::models::Agent, id_sqlite >::
persist (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
callback (db,
obj,
callback_event::pre_persist);
image_type& im (sts.image ());
binding& imb (sts.insert_image_binding ());
if (init (im, obj, statement_insert))
im.version++;
if (im.version != sts.insert_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_insert);
sts.insert_image_version (im.version);
imb.version++;
}
insert_statement& st (sts.persist_statement ());
if (!st.execute ())
throw object_already_persistent ();
callback (db,
obj,
callback_event::post_persist);
}
void access::object_traits_impl< ::models::Agent, id_sqlite >::
update (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace sqlite;
using sqlite::update_statement;
callback (db, obj, callback_event::pre_update);
sqlite::transaction& tr (sqlite::transaction::current ());
sqlite::connection& conn (tr.connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
const id_type& id (
obj.id);
id_image_type& idi (sts.id_image ());
init (idi, id);
image_type& im (sts.image ());
if (init (im, obj, statement_update))
im.version++;
bool u (false);
binding& imb (sts.update_image_binding ());
if (im.version != sts.update_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_update);
sts.update_image_version (im.version);
imb.version++;
u = true;
}
binding& idb (sts.id_image_binding ());
if (idi.version != sts.update_id_image_version () ||
idb.version == 0)
{
if (idi.version != sts.id_image_version () ||
idb.version == 0)
{
bind (idb.bind, idi);
sts.id_image_version (idi.version);
idb.version++;
}
sts.update_id_image_version (idi.version);
if (!u)
imb.version++;
}
update_statement& st (sts.update_statement ());
if (st.execute () == 0)
throw object_not_persistent ();
callback (db, obj, callback_event::post_update);
pointer_cache_traits::update (db, obj);
}
void access::object_traits_impl< ::models::Agent, id_sqlite >::
erase (database& db, const id_type& id)
{
using namespace sqlite;
ODB_POTENTIALLY_UNUSED (db);
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
id_image_type& i (sts.id_image ());
init (i, id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
if (sts.erase_statement ().execute () != 1)
throw object_not_persistent ();
pointer_cache_traits::erase (db, id);
}
access::object_traits_impl< ::models::Agent, id_sqlite >::pointer_type
access::object_traits_impl< ::models::Agent, id_sqlite >::
find (database& db, const id_type& id)
{
using namespace sqlite;
{
pointer_type p (pointer_cache_traits::find (db, id));
if (!pointer_traits::null_ptr (p))
return p;
}
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (l.locked ())
{
if (!find_ (sts, &id))
return pointer_type ();
}
pointer_type p (
access::object_factory<object_type, pointer_type>::create ());
pointer_traits::guard pg (p);
pointer_cache_traits::insert_guard ig (
pointer_cache_traits::insert (db, id, p));
object_type& obj (pointer_traits::get_ref (p));
if (l.locked ())
{
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
pointer_cache_traits::load (ig.position ());
}
else
sts.delay_load (id, obj, ig.position ());
ig.release ();
pg.release ();
return p;
}
bool access::object_traits_impl< ::models::Agent, id_sqlite >::
find (database& db, const id_type& id, object_type& obj)
{
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
reference_cache_traits::position_type pos (
reference_cache_traits::insert (db, id, obj));
reference_cache_traits::insert_guard ig (pos);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
reference_cache_traits::load (pos);
ig.release ();
return true;
}
bool access::object_traits_impl< ::models::Agent, id_sqlite >::
reload (database& db, object_type& obj)
{
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
const id_type& id (
obj.id);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, true);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
return true;
}
bool access::object_traits_impl< ::models::Agent, id_sqlite >::
find_ (statements_type& sts,
const id_type* id)
{
using namespace sqlite;
id_image_type& i (sts.id_image ());
init (i, *id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
select_statement& st (sts.find_statement ());
st.execute ();
auto_result ar (st);
select_statement::result r (st.fetch ());
if (r == select_statement::truncated)
{
if (grow (im, sts.select_image_truncated ()))
im.version++;
if (im.version != sts.select_image_version ())
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
st.refetch ();
}
}
return r != select_statement::no_data;
}
result< access::object_traits_impl< ::models::Agent, id_sqlite >::object_type >
access::object_traits_impl< ::models::Agent, id_sqlite >::
query (database&, const query_base_type& q)
{
using namespace sqlite;
using odb::details::shared;
using odb::details::shared_ptr;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
std::string text (query_statement);
if (!q.empty ())
{
text += " ";
text += q.clause ();
}
q.init_parameters ();
shared_ptr<select_statement> st (
new (shared) select_statement (
conn,
text,
false,
true,
q.parameters_binding (),
imb));
st->execute ();
shared_ptr< odb::object_result_impl<object_type> > r (
new (shared) sqlite::object_result_impl<object_type> (
q, st, sts, 0));
return result<object_type> (r);
}
unsigned long long access::object_traits_impl< ::models::Agent, id_sqlite >::
erase_query (database&, const query_base_type& q)
{
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
std::string text (erase_query_statement);
if (!q.empty ())
{
text += ' ';
text += q.clause ();
}
q.init_parameters ();
delete_statement st (
conn,
text,
q.parameters_binding ());
return st.execute ();
}
}
#include <odb/post.hxx>
@@ -0,0 +1,342 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef AGENT_ODB_HXX
#define AGENT_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "Agent.h"
#include <memory>
#include <cstddef>
#include <utility>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// Agent
//
template <>
struct class_traits< ::models::Agent >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::models::Agent >
{
public:
typedef ::models::Agent object_type;
typedef ::models::Agent* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;
static const bool polymorphic = false;
typedef ::std::string id_type;
static const bool auto_id = false;
static const bool abstract = false;
static id_type
id (const object_type&);
typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;
typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;
static void
callback (database&, object_type&, callback_event);
static void
callback (database&, const object_type&, callback_event);
};
}
#include <odb/details/buffer.hxx>
#include <odb/sqlite/version.hxx>
#include <odb/sqlite/forward.hxx>
#include <odb/sqlite/binding.hxx>
#include <odb/sqlite/sqlite-types.hxx>
#include <odb/sqlite/query.hxx>
namespace odb
{
// Agent
//
template <typename A>
struct query_columns< ::models::Agent, id_sqlite, A >
{
// id
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
id_type_;
static const id_type_ id;
// role
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
role_type_;
static const role_type_ role;
// persistent
//
typedef
sqlite::query_column<
sqlite::value_traits<
bool,
sqlite::id_integer >::query_type,
sqlite::id_integer >
persistent_type_;
static const persistent_type_ persistent;
// displayName
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
displayName_type_;
static const displayName_type_ displayName;
// trustScore
//
typedef
sqlite::query_column<
sqlite::value_traits<
::int32_t,
sqlite::id_integer >::query_type,
sqlite::id_integer >
trustScore_type_;
static const trustScore_type_ trustScore;
};
template <typename A>
const typename query_columns< ::models::Agent, id_sqlite, A >::id_type_
query_columns< ::models::Agent, id_sqlite, A >::
id (A::table_name, "\"id\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_sqlite, A >::role_type_
query_columns< ::models::Agent, id_sqlite, A >::
role (A::table_name, "\"role\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_sqlite, A >::persistent_type_
query_columns< ::models::Agent, id_sqlite, A >::
persistent (A::table_name, "\"persistent\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_sqlite, A >::displayName_type_
query_columns< ::models::Agent, id_sqlite, A >::
displayName (A::table_name, "\"displayName\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_sqlite, A >::trustScore_type_
query_columns< ::models::Agent, id_sqlite, A >::
trustScore (A::table_name, "\"trustScore\"", 0);
template <typename A>
struct pointer_query_columns< ::models::Agent, id_sqlite, A >:
query_columns< ::models::Agent, id_sqlite, A >
{
};
template <>
class access::object_traits_impl< ::models::Agent, id_sqlite >:
public access::object_traits< ::models::Agent >
{
public:
struct id_image_type
{
details::buffer id_value;
std::size_t id_size;
bool id_null;
std::size_t version;
};
struct image_type
{
// id
//
details::buffer id_value;
std::size_t id_size;
bool id_null;
// role
//
details::buffer role_value;
std::size_t role_size;
bool role_null;
// persistent
//
long long persistent_value;
bool persistent_null;
// displayName
//
details::buffer displayName_value;
std::size_t displayName_size;
bool displayName_null;
// trustScore
//
long long trustScore_value;
bool trustScore_null;
std::size_t version;
};
struct extra_statement_cache_type;
using object_traits<object_type>::id;
static id_type
id (const image_type&);
static bool
grow (image_type&,
bool*);
static void
bind (sqlite::bind*,
image_type&,
sqlite::statement_kind);
static void
bind (sqlite::bind*, id_image_type&);
static bool
init (image_type&,
const object_type&,
sqlite::statement_kind);
static void
init (object_type&,
const image_type&,
database*);
static void
init (id_image_type&, const id_type&);
typedef sqlite::object_statements<object_type> statements_type;
typedef sqlite::query_base query_base_type;
static const std::size_t column_count = 5UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 0UL;
static const std::size_t managed_optimistic_column_count = 0UL;
static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;
static const bool versioned = false;
static const char persist_statement[];
static const char find_statement[];
static const char update_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];
static const char table_name[];
static void
persist (database&, const object_type&);
static pointer_type
find (database&, const id_type&);
static bool
find (database&, const id_type&, object_type&);
static bool
reload (database&, object_type&);
static void
update (database&, const object_type&);
static void
erase (database&, const id_type&);
static void
erase (database&, const object_type&);
static result<object_type>
query (database&, const query_base_type&);
static unsigned long long
erase_query (database&, const query_base_type&);
public:
static bool
find_ (statements_type&,
const id_type*);
static void
load_ (statements_type&,
object_type&,
bool reload);
};
template <>
class access::object_traits_impl< ::models::Agent, id_common >:
public access::object_traits_impl< ::models::Agent, id_sqlite >
{
};
// Agent
//
}
#include "Agent-odb.ixx"
#include <odb/post.hxx>
#endif // AGENT_ODB_HXX
@@ -0,0 +1,61 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
namespace odb
{
// Agent
//
inline
access::object_traits< ::models::Agent >::id_type
access::object_traits< ::models::Agent >::
id (const object_type& o)
{
return o.id;
}
inline
void access::object_traits< ::models::Agent >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
inline
void access::object_traits< ::models::Agent >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}
namespace odb
{
// Agent
//
inline
void access::object_traits_impl< ::models::Agent, id_sqlite >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}
inline
void access::object_traits_impl< ::models::Agent, id_sqlite >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}
@@ -0,0 +1,16 @@
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="sqlite" version="1">
<changeset version="2">
<add-table name="Agent" kind="object">
<column name="id" type="TEXT" null="false"/>
<column name="role" type="TEXT" null="false"/>
<column name="persistent" type="INTEGER" null="false"/>
<column name="displayName" type="TEXT" null="false"/>
<column name="trustScore" type="INTEGER" null="false"/>
<primary-key>
<column name="id"/>
</primary-key>
</add-table>
</changeset>
<model version="1"/>
</changelog>
@@ -0,0 +1,725 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#include <odb/pre.hxx>
#include "GovernmentAddress-odb.hxx"
#include <cassert>
#include <cstring> // std::memcpy
#include <odb/sqlite/traits.hxx>
#include <odb/sqlite/database.hxx>
#include <odb/sqlite/transaction.hxx>
#include <odb/sqlite/connection.hxx>
#include <odb/sqlite/statement.hxx>
#include <odb/sqlite/statement-cache.hxx>
#include <odb/sqlite/simple-object-statements.hxx>
#include <odb/sqlite/container-statements.hxx>
#include <odb/sqlite/exceptions.hxx>
#include <odb/sqlite/simple-object-result.hxx>
namespace odb
{
// GovernmentAddress
//
struct access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::extra_statement_cache_type
{
extra_statement_cache_type (
sqlite::connection&,
image_type&,
id_image_type&,
sqlite::binding&,
sqlite::binding&)
{
}
};
access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::id_type
access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
id (const image_type& i)
{
sqlite::database* db (0);
ODB_POTENTIALLY_UNUSED (db);
id_type id;
{
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
id,
i.id_value,
i.id_size,
i.id_null);
}
return id;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
grow (image_type& i,
bool* t)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (t);
bool grew (false);
// id
//
if (t[0UL])
{
i.id_value.capacity (i.id_size);
grew = true;
}
// addressLabel
//
if (t[1UL])
{
i.addressLabel_value.capacity (i.addressLabel_size);
grew = true;
}
// regionLookupKey
//
if (t[2UL])
{
i.regionLookupKey_value.capacity (i.regionLookupKey_size);
grew = true;
}
return grew;
}
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
bind (sqlite::bind* b,
image_type& i,
sqlite::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (sk);
using namespace sqlite;
std::size_t n (0);
// id
//
if (sk != statement_update)
{
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.id_value.data ();
b[n].size = &i.id_size;
b[n].capacity = i.id_value.capacity ();
b[n].is_null = &i.id_null;
n++;
}
// addressLabel
//
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.addressLabel_value.data ();
b[n].size = &i.addressLabel_size;
b[n].capacity = i.addressLabel_value.capacity ();
b[n].is_null = &i.addressLabel_null;
n++;
// regionLookupKey
//
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.regionLookupKey_value.data ();
b[n].size = &i.regionLookupKey_size;
b[n].capacity = i.regionLookupKey_value.capacity ();
b[n].is_null = &i.regionLookupKey_null;
n++;
}
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
bind (sqlite::bind* b, id_image_type& i)
{
std::size_t n (0);
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.id_value.data ();
b[n].size = &i.id_size;
b[n].capacity = i.id_value.capacity ();
b[n].is_null = &i.id_null;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
init (image_type& i,
const object_type& o,
sqlite::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (sk);
using namespace sqlite;
bool grew (false);
// id
//
if (sk == statement_insert)
{
::std::string const& v =
o.id;
bool is_null (false);
std::size_t cap (i.id_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.id_value,
i.id_size,
is_null,
v);
i.id_null = is_null;
grew = grew || (cap != i.id_value.capacity ());
}
// addressLabel
//
{
::std::string const& v =
o.addressLabel;
bool is_null (false);
std::size_t cap (i.addressLabel_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.addressLabel_value,
i.addressLabel_size,
is_null,
v);
i.addressLabel_null = is_null;
grew = grew || (cap != i.addressLabel_value.capacity ());
}
// regionLookupKey
//
{
::std::string const& v =
o.regionLookupKey;
bool is_null (false);
std::size_t cap (i.regionLookupKey_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.regionLookupKey_value,
i.regionLookupKey_size,
is_null,
v);
i.regionLookupKey_null = is_null;
grew = grew || (cap != i.regionLookupKey_value.capacity ());
}
return grew;
}
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
init (object_type& o,
const image_type& i,
database* db)
{
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (db);
// id
//
{
::std::string& v =
o.id;
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
v,
i.id_value,
i.id_size,
i.id_null);
}
// addressLabel
//
{
::std::string& v =
o.addressLabel;
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
v,
i.addressLabel_value,
i.addressLabel_size,
i.addressLabel_null);
}
// regionLookupKey
//
{
::std::string& v =
o.regionLookupKey;
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
v,
i.regionLookupKey_value,
i.regionLookupKey_size,
i.regionLookupKey_null);
}
}
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
init (id_image_type& i, const id_type& id)
{
bool grew (false);
{
bool is_null (false);
std::size_t cap (i.id_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.id_value,
i.id_size,
is_null,
id);
i.id_null = is_null;
grew = grew || (cap != i.id_value.capacity ());
}
if (grew)
i.version++;
}
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::persist_statement[] =
"INSERT INTO \"GovernmentAddress\" "
"(\"id\", "
"\"addressLabel\", "
"\"regionLookupKey\") "
"VALUES "
"(?, ?, ?)";
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::find_statement[] =
"SELECT "
"\"GovernmentAddress\".\"id\", "
"\"GovernmentAddress\".\"addressLabel\", "
"\"GovernmentAddress\".\"regionLookupKey\" "
"FROM \"GovernmentAddress\" "
"WHERE \"GovernmentAddress\".\"id\"=?";
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::update_statement[] =
"UPDATE \"GovernmentAddress\" "
"SET "
"\"addressLabel\"=?, "
"\"regionLookupKey\"=? "
"WHERE \"id\"=?";
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::erase_statement[] =
"DELETE FROM \"GovernmentAddress\" "
"WHERE \"id\"=?";
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::query_statement[] =
"SELECT "
"\"GovernmentAddress\".\"id\", "
"\"GovernmentAddress\".\"addressLabel\", "
"\"GovernmentAddress\".\"regionLookupKey\" "
"FROM \"GovernmentAddress\"";
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::erase_query_statement[] =
"DELETE FROM \"GovernmentAddress\"";
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::table_name[] =
"\"GovernmentAddress\"";
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
persist (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
callback (db,
obj,
callback_event::pre_persist);
image_type& im (sts.image ());
binding& imb (sts.insert_image_binding ());
if (init (im, obj, statement_insert))
im.version++;
if (im.version != sts.insert_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_insert);
sts.insert_image_version (im.version);
imb.version++;
}
insert_statement& st (sts.persist_statement ());
if (!st.execute ())
throw object_already_persistent ();
callback (db,
obj,
callback_event::post_persist);
}
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
update (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace sqlite;
using sqlite::update_statement;
callback (db, obj, callback_event::pre_update);
sqlite::transaction& tr (sqlite::transaction::current ());
sqlite::connection& conn (tr.connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
const id_type& id (
obj.id);
id_image_type& idi (sts.id_image ());
init (idi, id);
image_type& im (sts.image ());
if (init (im, obj, statement_update))
im.version++;
bool u (false);
binding& imb (sts.update_image_binding ());
if (im.version != sts.update_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_update);
sts.update_image_version (im.version);
imb.version++;
u = true;
}
binding& idb (sts.id_image_binding ());
if (idi.version != sts.update_id_image_version () ||
idb.version == 0)
{
if (idi.version != sts.id_image_version () ||
idb.version == 0)
{
bind (idb.bind, idi);
sts.id_image_version (idi.version);
idb.version++;
}
sts.update_id_image_version (idi.version);
if (!u)
imb.version++;
}
update_statement& st (sts.update_statement ());
if (st.execute () == 0)
throw object_not_persistent ();
callback (db, obj, callback_event::post_update);
pointer_cache_traits::update (db, obj);
}
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
erase (database& db, const id_type& id)
{
using namespace sqlite;
ODB_POTENTIALLY_UNUSED (db);
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
id_image_type& i (sts.id_image ());
init (i, id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
if (sts.erase_statement ().execute () != 1)
throw object_not_persistent ();
pointer_cache_traits::erase (db, id);
}
access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::pointer_type
access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
find (database& db, const id_type& id)
{
using namespace sqlite;
{
pointer_type p (pointer_cache_traits::find (db, id));
if (!pointer_traits::null_ptr (p))
return p;
}
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (l.locked ())
{
if (!find_ (sts, &id))
return pointer_type ();
}
pointer_type p (
access::object_factory<object_type, pointer_type>::create ());
pointer_traits::guard pg (p);
pointer_cache_traits::insert_guard ig (
pointer_cache_traits::insert (db, id, p));
object_type& obj (pointer_traits::get_ref (p));
if (l.locked ())
{
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
pointer_cache_traits::load (ig.position ());
}
else
sts.delay_load (id, obj, ig.position ());
ig.release ();
pg.release ();
return p;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
find (database& db, const id_type& id, object_type& obj)
{
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
reference_cache_traits::position_type pos (
reference_cache_traits::insert (db, id, obj));
reference_cache_traits::insert_guard ig (pos);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
reference_cache_traits::load (pos);
ig.release ();
return true;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
reload (database& db, object_type& obj)
{
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
const id_type& id (
obj.id);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, true);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
return true;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
find_ (statements_type& sts,
const id_type* id)
{
using namespace sqlite;
id_image_type& i (sts.id_image ());
init (i, *id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
select_statement& st (sts.find_statement ());
st.execute ();
auto_result ar (st);
select_statement::result r (st.fetch ());
if (r == select_statement::truncated)
{
if (grow (im, sts.select_image_truncated ()))
im.version++;
if (im.version != sts.select_image_version ())
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
st.refetch ();
}
}
return r != select_statement::no_data;
}
result< access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::object_type >
access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
query (database&, const query_base_type& q)
{
using namespace sqlite;
using odb::details::shared;
using odb::details::shared_ptr;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
std::string text (query_statement);
if (!q.empty ())
{
text += " ";
text += q.clause ();
}
q.init_parameters ();
shared_ptr<select_statement> st (
new (shared) select_statement (
conn,
text,
false,
true,
q.parameters_binding (),
imb));
st->execute ();
shared_ptr< odb::object_result_impl<object_type> > r (
new (shared) sqlite::object_result_impl<object_type> (
q, st, sts, 0));
return result<object_type> (r);
}
unsigned long long access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
erase_query (database&, const query_base_type& q)
{
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
std::string text (erase_query_statement);
if (!q.empty ())
{
text += ' ';
text += q.clause ();
}
q.init_parameters ();
delete_statement st (
conn,
text,
q.parameters_binding ());
return st.execute ();
}
}
#include <odb/post.hxx>
@@ -0,0 +1,298 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef GOVERNMENT_ADDRESS_ODB_HXX
#define GOVERNMENT_ADDRESS_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "GovernmentAddress.h"
#include <memory>
#include <cstddef>
#include <utility>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// GovernmentAddress
//
template <>
struct class_traits< ::models::GovernmentAddress >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::models::GovernmentAddress >
{
public:
typedef ::models::GovernmentAddress object_type;
typedef ::models::GovernmentAddress* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;
static const bool polymorphic = false;
typedef ::std::string id_type;
static const bool auto_id = false;
static const bool abstract = false;
static id_type
id (const object_type&);
typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;
typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;
static void
callback (database&, object_type&, callback_event);
static void
callback (database&, const object_type&, callback_event);
};
}
#include <odb/details/buffer.hxx>
#include <odb/sqlite/version.hxx>
#include <odb/sqlite/forward.hxx>
#include <odb/sqlite/binding.hxx>
#include <odb/sqlite/sqlite-types.hxx>
#include <odb/sqlite/query.hxx>
namespace odb
{
// GovernmentAddress
//
template <typename A>
struct query_columns< ::models::GovernmentAddress, id_sqlite, A >
{
// id
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
id_type_;
static const id_type_ id;
// addressLabel
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
addressLabel_type_;
static const addressLabel_type_ addressLabel;
// regionLookupKey
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
regionLookupKey_type_;
static const regionLookupKey_type_ regionLookupKey;
};
template <typename A>
const typename query_columns< ::models::GovernmentAddress, id_sqlite, A >::id_type_
query_columns< ::models::GovernmentAddress, id_sqlite, A >::
id (A::table_name, "\"id\"", 0);
template <typename A>
const typename query_columns< ::models::GovernmentAddress, id_sqlite, A >::addressLabel_type_
query_columns< ::models::GovernmentAddress, id_sqlite, A >::
addressLabel (A::table_name, "\"addressLabel\"", 0);
template <typename A>
const typename query_columns< ::models::GovernmentAddress, id_sqlite, A >::regionLookupKey_type_
query_columns< ::models::GovernmentAddress, id_sqlite, A >::
regionLookupKey (A::table_name, "\"regionLookupKey\"", 0);
template <typename A>
struct pointer_query_columns< ::models::GovernmentAddress, id_sqlite, A >:
query_columns< ::models::GovernmentAddress, id_sqlite, A >
{
};
template <>
class access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:
public access::object_traits< ::models::GovernmentAddress >
{
public:
struct id_image_type
{
details::buffer id_value;
std::size_t id_size;
bool id_null;
std::size_t version;
};
struct image_type
{
// id
//
details::buffer id_value;
std::size_t id_size;
bool id_null;
// addressLabel
//
details::buffer addressLabel_value;
std::size_t addressLabel_size;
bool addressLabel_null;
// regionLookupKey
//
details::buffer regionLookupKey_value;
std::size_t regionLookupKey_size;
bool regionLookupKey_null;
std::size_t version;
};
struct extra_statement_cache_type;
using object_traits<object_type>::id;
static id_type
id (const image_type&);
static bool
grow (image_type&,
bool*);
static void
bind (sqlite::bind*,
image_type&,
sqlite::statement_kind);
static void
bind (sqlite::bind*, id_image_type&);
static bool
init (image_type&,
const object_type&,
sqlite::statement_kind);
static void
init (object_type&,
const image_type&,
database*);
static void
init (id_image_type&, const id_type&);
typedef sqlite::object_statements<object_type> statements_type;
typedef sqlite::query_base query_base_type;
static const std::size_t column_count = 3UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 0UL;
static const std::size_t managed_optimistic_column_count = 0UL;
static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;
static const bool versioned = false;
static const char persist_statement[];
static const char find_statement[];
static const char update_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];
static const char table_name[];
static void
persist (database&, const object_type&);
static pointer_type
find (database&, const id_type&);
static bool
find (database&, const id_type&, object_type&);
static bool
reload (database&, object_type&);
static void
update (database&, const object_type&);
static void
erase (database&, const id_type&);
static void
erase (database&, const object_type&);
static result<object_type>
query (database&, const query_base_type&);
static unsigned long long
erase_query (database&, const query_base_type&);
public:
static bool
find_ (statements_type&,
const id_type*);
static void
load_ (statements_type&,
object_type&,
bool reload);
};
template <>
class access::object_traits_impl< ::models::GovernmentAddress, id_common >:
public access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >
{
};
// GovernmentAddress
//
}
#include "GovernmentAddress-odb.ixx"
#include <odb/post.hxx>
#endif // GOVERNMENT_ADDRESS_ODB_HXX
@@ -0,0 +1,61 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
namespace odb
{
// GovernmentAddress
//
inline
access::object_traits< ::models::GovernmentAddress >::id_type
access::object_traits< ::models::GovernmentAddress >::
id (const object_type& o)
{
return o.id;
}
inline
void access::object_traits< ::models::GovernmentAddress >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
inline
void access::object_traits< ::models::GovernmentAddress >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}
namespace odb
{
// GovernmentAddress
//
inline
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}
inline
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}
@@ -0,0 +1,14 @@
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="sqlite" version="1">
<changeset version="2">
<add-table name="GovernmentAddress" kind="object">
<column name="id" type="TEXT" null="false"/>
<column name="addressLabel" type="TEXT" null="false"/>
<column name="regionLookupKey" type="TEXT" null="false"/>
<primary-key>
<column name="id"/>
</primary-key>
</add-table>
</changeset>
<model version="1"/>
</changelog>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,505 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef TRIP_ATTEMPT_RESULT_ODB_HXX
#define TRIP_ATTEMPT_RESULT_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "TripAttemptResult.h"
#include <memory>
#include <cstddef>
#include <utility>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// TripAttemptResult
//
template <>
struct class_traits< ::models::TripAttemptResult >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::models::TripAttemptResult >
{
public:
typedef ::models::TripAttemptResult object_type;
typedef ::models::TripAttemptResult* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;
static const bool polymorphic = false;
typedef ::std::string id_type;
static const bool auto_id = false;
static const bool abstract = false;
static id_type
id (const object_type&);
typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;
typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;
static void
callback (database&, object_type&, callback_event);
static void
callback (database&, const object_type&, callback_event);
};
}
#include <odb/details/buffer.hxx>
#include <odb/sqlite/version.hxx>
#include <odb/sqlite/forward.hxx>
#include <odb/sqlite/binding.hxx>
#include <odb/sqlite/sqlite-types.hxx>
#include <odb/sqlite/query.hxx>
namespace odb
{
// TripAttemptResult
//
template <typename A>
struct query_columns< ::models::TripAttemptResult, id_sqlite, A >
{
// id
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
id_type_;
static const id_type_ id;
// result
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
result_type_;
static const result_type_ result;
// retryReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
retryReason_type_;
static const retryReason_type_ retryReason;
// governmentSuspensionReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
governmentSuspensionReason_type_;
static const governmentSuspensionReason_type_ governmentSuspensionReason;
// governmentTerminationReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
governmentTerminationReason_type_;
static const governmentTerminationReason_type_ governmentTerminationReason;
// complianceSuspensionReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
complianceSuspensionReason_type_;
static const complianceSuspensionReason_type_ complianceSuspensionReason;
// complianceTerminationReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
complianceTerminationReason_type_;
static const complianceTerminationReason_type_ complianceTerminationReason;
// policySuspensionReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
policySuspensionReason_type_;
static const policySuspensionReason_type_ policySuspensionReason;
// policyTerminationReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
policyTerminationReason_type_;
static const policyTerminationReason_type_ policyTerminationReason;
// cancelationReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
cancelationReason_type_;
static const cancelationReason_type_ cancelationReason;
// failureReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
failureReason_type_;
static const failureReason_type_ failureReason;
// details
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
details_type_;
static const details_type_ details;
};
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::id_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
id (A::table_name, "\"id\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::result_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
result (A::table_name, "\"result\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::retryReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
retryReason (A::table_name, "\"retryReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::governmentSuspensionReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
governmentSuspensionReason (A::table_name, "\"governmentSuspensionReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::governmentTerminationReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
governmentTerminationReason (A::table_name, "\"governmentTerminationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::complianceSuspensionReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
complianceSuspensionReason (A::table_name, "\"complianceSuspensionReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::complianceTerminationReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
complianceTerminationReason (A::table_name, "\"complianceTerminationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::policySuspensionReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
policySuspensionReason (A::table_name, "\"policySuspensionReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::policyTerminationReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
policyTerminationReason (A::table_name, "\"policyTerminationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::cancelationReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
cancelationReason (A::table_name, "\"cancelationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::failureReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
failureReason (A::table_name, "\"failureReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::details_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
details (A::table_name, "\"details\"", 0);
template <typename A>
struct pointer_query_columns< ::models::TripAttemptResult, id_sqlite, A >:
query_columns< ::models::TripAttemptResult, id_sqlite, A >
{
};
template <>
class access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:
public access::object_traits< ::models::TripAttemptResult >
{
public:
struct id_image_type
{
details::buffer id_value;
std::size_t id_size;
bool id_null;
std::size_t version;
};
struct image_type
{
// id
//
details::buffer id_value;
std::size_t id_size;
bool id_null;
// result
//
details::buffer result_value;
std::size_t result_size;
bool result_null;
// retryReason
//
details::buffer retryReason_value;
std::size_t retryReason_size;
bool retryReason_null;
// governmentSuspensionReason
//
details::buffer governmentSuspensionReason_value;
std::size_t governmentSuspensionReason_size;
bool governmentSuspensionReason_null;
// governmentTerminationReason
//
details::buffer governmentTerminationReason_value;
std::size_t governmentTerminationReason_size;
bool governmentTerminationReason_null;
// complianceSuspensionReason
//
details::buffer complianceSuspensionReason_value;
std::size_t complianceSuspensionReason_size;
bool complianceSuspensionReason_null;
// complianceTerminationReason
//
details::buffer complianceTerminationReason_value;
std::size_t complianceTerminationReason_size;
bool complianceTerminationReason_null;
// policySuspensionReason
//
details::buffer policySuspensionReason_value;
std::size_t policySuspensionReason_size;
bool policySuspensionReason_null;
// policyTerminationReason
//
details::buffer policyTerminationReason_value;
std::size_t policyTerminationReason_size;
bool policyTerminationReason_null;
// cancelationReason
//
details::buffer cancelationReason_value;
std::size_t cancelationReason_size;
bool cancelationReason_null;
// failureReason
//
details::buffer failureReason_value;
std::size_t failureReason_size;
bool failureReason_null;
// details
//
details::buffer details_value;
std::size_t details_size;
bool details_null;
std::size_t version;
};
struct extra_statement_cache_type;
using object_traits<object_type>::id;
static id_type
id (const image_type&);
static bool
grow (image_type&,
bool*);
static void
bind (sqlite::bind*,
image_type&,
sqlite::statement_kind);
static void
bind (sqlite::bind*, id_image_type&);
static bool
init (image_type&,
const object_type&,
sqlite::statement_kind);
static void
init (object_type&,
const image_type&,
database*);
static void
init (id_image_type&, const id_type&);
typedef sqlite::object_statements<object_type> statements_type;
typedef sqlite::query_base query_base_type;
static const std::size_t column_count = 12UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 0UL;
static const std::size_t managed_optimistic_column_count = 0UL;
static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;
static const bool versioned = false;
static const char persist_statement[];
static const char find_statement[];
static const char update_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];
static const char table_name[];
static void
persist (database&, const object_type&);
static pointer_type
find (database&, const id_type&);
static bool
find (database&, const id_type&, object_type&);
static bool
reload (database&, object_type&);
static void
update (database&, const object_type&);
static void
erase (database&, const id_type&);
static void
erase (database&, const object_type&);
static result<object_type>
query (database&, const query_base_type&);
static unsigned long long
erase_query (database&, const query_base_type&);
public:
static bool
find_ (statements_type&,
const id_type*);
static void
load_ (statements_type&,
object_type&,
bool reload);
};
template <>
class access::object_traits_impl< ::models::TripAttemptResult, id_common >:
public access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >
{
};
// TripAttemptResult
//
}
#include "TripAttemptResult-odb.ixx"
#include <odb/post.hxx>
#endif // TRIP_ATTEMPT_RESULT_ODB_HXX
@@ -0,0 +1,61 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
namespace odb
{
// TripAttemptResult
//
inline
access::object_traits< ::models::TripAttemptResult >::id_type
access::object_traits< ::models::TripAttemptResult >::
id (const object_type& o)
{
return o.id;
}
inline
void access::object_traits< ::models::TripAttemptResult >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
inline
void access::object_traits< ::models::TripAttemptResult >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}
namespace odb
{
// TripAttemptResult
//
inline
void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}
inline
void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}
@@ -0,0 +1,23 @@
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="sqlite" version="1">
<changeset version="2">
<add-table name="TripAttemptResult" kind="object">
<column name="id" type="TEXT" null="false"/>
<column name="result" type="TEXT" null="false"/>
<column name="retryReason" type="TEXT" null="false"/>
<column name="governmentSuspensionReason" type="TEXT" null="false"/>
<column name="governmentTerminationReason" type="TEXT" null="false"/>
<column name="complianceSuspensionReason" type="TEXT" null="false"/>
<column name="complianceTerminationReason" type="TEXT" null="false"/>
<column name="policySuspensionReason" type="TEXT" null="false"/>
<column name="policyTerminationReason" type="TEXT" null="false"/>
<column name="cancelationReason" type="TEXT" null="false"/>
<column name="failureReason" type="TEXT" null="false"/>
<column name="details" type="TEXT" null="false"/>
<primary-key>
<column name="id"/>
</primary-key>
</add-table>
</changeset>
<model version="1"/>
</changelog>
@@ -0,0 +1,8 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
UPDATE "schema_version"
SET "migration" = FALSE
WHERE "name" = '';
@@ -0,0 +1,15 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
CREATE TABLE "Agent" (
"id" TEXT NOT NULL PRIMARY KEY,
"role" TEXT NOT NULL,
"persistent" BOOLEAN NOT NULL,
"displayName" TEXT NOT NULL,
"trustScore" INTEGER NOT NULL);
UPDATE "schema_version"
SET "version" = 2, "migration" = TRUE
WHERE "name" = '';
@@ -0,0 +1,864 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#include <odb/pre.hxx>
#include "Agent-odb.hxx"
#include <cassert>
#include <cstring> // std::memcpy
#include <odb/pgsql/traits.hxx>
#include <odb/pgsql/database.hxx>
#include <odb/pgsql/transaction.hxx>
#include <odb/pgsql/connection.hxx>
#include <odb/pgsql/statement.hxx>
#include <odb/pgsql/statement-cache.hxx>
#include <odb/pgsql/simple-object-statements.hxx>
#include <odb/pgsql/container-statements.hxx>
#include <odb/pgsql/exceptions.hxx>
#include <odb/pgsql/simple-object-result.hxx>
namespace odb
{
// Agent
//
const char access::object_traits_impl< ::models::Agent, id_pgsql >::
persist_statement_name[] = "persist_models_Agent";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::
find_statement_name[] = "find_models_Agent";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::
update_statement_name[] = "update_models_Agent";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::
erase_statement_name[] = "erase_models_Agent";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::
query_statement_name[] = "query_models_Agent";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::
erase_query_statement_name[] = "erase_query_models_Agent";
const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >::
persist_statement_types[] =
{
pgsql::text_oid,
pgsql::text_oid,
pgsql::bool_oid,
pgsql::text_oid,
pgsql::int4_oid
};
const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >::
find_statement_types[] =
{
pgsql::text_oid
};
const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >::
update_statement_types[] =
{
pgsql::text_oid,
pgsql::bool_oid,
pgsql::text_oid,
pgsql::int4_oid,
pgsql::text_oid
};
struct access::object_traits_impl< ::models::Agent, id_pgsql >::extra_statement_cache_type
{
extra_statement_cache_type (
pgsql::connection&,
image_type&,
id_image_type&,
pgsql::binding&,
pgsql::binding&,
pgsql::native_binding&,
const unsigned int*)
{
}
};
access::object_traits_impl< ::models::Agent, id_pgsql >::id_type
access::object_traits_impl< ::models::Agent, id_pgsql >::
id (const image_type& i)
{
pgsql::database* db (0);
ODB_POTENTIALLY_UNUSED (db);
id_type id;
{
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
id,
i.id_value,
i.id_size,
i.id_null);
}
return id;
}
bool access::object_traits_impl< ::models::Agent, id_pgsql >::
grow (image_type& i,
bool* t)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (t);
bool grew (false);
// id
//
if (t[0UL])
{
i.id_value.capacity (i.id_size);
grew = true;
}
// role
//
if (t[1UL])
{
i.role_value.capacity (i.role_size);
grew = true;
}
// persistent
//
t[2UL] = 0;
// displayName
//
if (t[3UL])
{
i.displayName_value.capacity (i.displayName_size);
grew = true;
}
// trustScore
//
t[4UL] = 0;
return grew;
}
void access::object_traits_impl< ::models::Agent, id_pgsql >::
bind (pgsql::bind* b,
image_type& i,
pgsql::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (sk);
using namespace pgsql;
std::size_t n (0);
// id
//
if (sk != statement_update)
{
b[n].type = pgsql::bind::text;
b[n].buffer = i.id_value.data ();
b[n].capacity = i.id_value.capacity ();
b[n].size = &i.id_size;
b[n].is_null = &i.id_null;
n++;
}
// role
//
b[n].type = pgsql::bind::text;
b[n].buffer = i.role_value.data ();
b[n].capacity = i.role_value.capacity ();
b[n].size = &i.role_size;
b[n].is_null = &i.role_null;
n++;
// persistent
//
b[n].type = pgsql::bind::boolean_;
b[n].buffer = &i.persistent_value;
b[n].is_null = &i.persistent_null;
n++;
// displayName
//
b[n].type = pgsql::bind::text;
b[n].buffer = i.displayName_value.data ();
b[n].capacity = i.displayName_value.capacity ();
b[n].size = &i.displayName_size;
b[n].is_null = &i.displayName_null;
n++;
// trustScore
//
b[n].type = pgsql::bind::integer;
b[n].buffer = &i.trustScore_value;
b[n].is_null = &i.trustScore_null;
n++;
}
void access::object_traits_impl< ::models::Agent, id_pgsql >::
bind (pgsql::bind* b, id_image_type& i)
{
std::size_t n (0);
b[n].type = pgsql::bind::text;
b[n].buffer = i.id_value.data ();
b[n].capacity = i.id_value.capacity ();
b[n].size = &i.id_size;
b[n].is_null = &i.id_null;
}
bool access::object_traits_impl< ::models::Agent, id_pgsql >::
init (image_type& i,
const object_type& o,
pgsql::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (sk);
using namespace pgsql;
bool grew (false);
// id
//
if (sk == statement_insert)
{
::std::string const& v =
o.id;
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.id_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.id_value,
size,
is_null,
v);
i.id_null = is_null;
i.id_size = size;
grew = grew || (cap != i.id_value.capacity ());
}
// role
//
{
::std::string const& v =
o.role;
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.role_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.role_value,
size,
is_null,
v);
i.role_null = is_null;
i.role_size = size;
grew = grew || (cap != i.role_value.capacity ());
}
// persistent
//
{
bool const& v =
o.persistent;
bool is_null (false);
pgsql::value_traits<
bool,
pgsql::id_boolean >::set_image (
i.persistent_value, is_null, v);
i.persistent_null = is_null;
}
// displayName
//
{
::std::string const& v =
o.displayName;
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.displayName_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.displayName_value,
size,
is_null,
v);
i.displayName_null = is_null;
i.displayName_size = size;
grew = grew || (cap != i.displayName_value.capacity ());
}
// trustScore
//
{
::int32_t const& v =
o.trustScore;
bool is_null (false);
pgsql::value_traits<
::int32_t,
pgsql::id_integer >::set_image (
i.trustScore_value, is_null, v);
i.trustScore_null = is_null;
}
return grew;
}
void access::object_traits_impl< ::models::Agent, id_pgsql >::
init (object_type& o,
const image_type& i,
database* db)
{
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (db);
// id
//
{
::std::string& v =
o.id;
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
v,
i.id_value,
i.id_size,
i.id_null);
}
// role
//
{
::std::string& v =
o.role;
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
v,
i.role_value,
i.role_size,
i.role_null);
}
// persistent
//
{
bool& v =
o.persistent;
pgsql::value_traits<
bool,
pgsql::id_boolean >::set_value (
v,
i.persistent_value,
i.persistent_null);
}
// displayName
//
{
::std::string& v =
o.displayName;
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
v,
i.displayName_value,
i.displayName_size,
i.displayName_null);
}
// trustScore
//
{
::int32_t& v =
o.trustScore;
pgsql::value_traits<
::int32_t,
pgsql::id_integer >::set_value (
v,
i.trustScore_value,
i.trustScore_null);
}
}
void access::object_traits_impl< ::models::Agent, id_pgsql >::
init (id_image_type& i, const id_type& id)
{
bool grew (false);
{
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.id_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.id_value,
size,
is_null,
id);
i.id_null = is_null;
i.id_size = size;
grew = grew || (cap != i.id_value.capacity ());
}
if (grew)
i.version++;
}
const char access::object_traits_impl< ::models::Agent, id_pgsql >::persist_statement[] =
"INSERT INTO \"Agent\" "
"(\"id\", "
"\"role\", "
"\"persistent\", "
"\"displayName\", "
"\"trustScore\") "
"VALUES "
"($1, $2, $3, $4, $5)";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::find_statement[] =
"SELECT "
"\"Agent\".\"id\", "
"\"Agent\".\"role\", "
"\"Agent\".\"persistent\", "
"\"Agent\".\"displayName\", "
"\"Agent\".\"trustScore\" "
"FROM \"Agent\" "
"WHERE \"Agent\".\"id\"=$1";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::update_statement[] =
"UPDATE \"Agent\" "
"SET "
"\"role\"=$1, "
"\"persistent\"=$2, "
"\"displayName\"=$3, "
"\"trustScore\"=$4 "
"WHERE \"id\"=$5";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::erase_statement[] =
"DELETE FROM \"Agent\" "
"WHERE \"id\"=$1";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::query_statement[] =
"SELECT "
"\"Agent\".\"id\", "
"\"Agent\".\"role\", "
"\"Agent\".\"persistent\", "
"\"Agent\".\"displayName\", "
"\"Agent\".\"trustScore\" "
"FROM \"Agent\"";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::erase_query_statement[] =
"DELETE FROM \"Agent\"";
const char access::object_traits_impl< ::models::Agent, id_pgsql >::table_name[] =
"\"Agent\"";
void access::object_traits_impl< ::models::Agent, id_pgsql >::
persist (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
callback (db,
obj,
callback_event::pre_persist);
image_type& im (sts.image ());
binding& imb (sts.insert_image_binding ());
if (init (im, obj, statement_insert))
im.version++;
if (im.version != sts.insert_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_insert);
sts.insert_image_version (im.version);
imb.version++;
}
insert_statement& st (sts.persist_statement ());
if (!st.execute ())
throw object_already_persistent ();
callback (db,
obj,
callback_event::post_persist);
}
void access::object_traits_impl< ::models::Agent, id_pgsql >::
update (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace pgsql;
using pgsql::update_statement;
callback (db, obj, callback_event::pre_update);
pgsql::transaction& tr (pgsql::transaction::current ());
pgsql::connection& conn (tr.connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
const id_type& id (
obj.id);
id_image_type& idi (sts.id_image ());
init (idi, id);
image_type& im (sts.image ());
if (init (im, obj, statement_update))
im.version++;
bool u (false);
binding& imb (sts.update_image_binding ());
if (im.version != sts.update_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_update);
sts.update_image_version (im.version);
imb.version++;
u = true;
}
binding& idb (sts.id_image_binding ());
if (idi.version != sts.update_id_image_version () ||
idb.version == 0)
{
if (idi.version != sts.id_image_version () ||
idb.version == 0)
{
bind (idb.bind, idi);
sts.id_image_version (idi.version);
idb.version++;
}
sts.update_id_image_version (idi.version);
if (!u)
imb.version++;
}
update_statement& st (sts.update_statement ());
if (st.execute () == 0)
throw object_not_persistent ();
callback (db, obj, callback_event::post_update);
pointer_cache_traits::update (db, obj);
}
void access::object_traits_impl< ::models::Agent, id_pgsql >::
erase (database& db, const id_type& id)
{
using namespace pgsql;
ODB_POTENTIALLY_UNUSED (db);
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
id_image_type& i (sts.id_image ());
init (i, id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
if (sts.erase_statement ().execute () != 1)
throw object_not_persistent ();
pointer_cache_traits::erase (db, id);
}
access::object_traits_impl< ::models::Agent, id_pgsql >::pointer_type
access::object_traits_impl< ::models::Agent, id_pgsql >::
find (database& db, const id_type& id)
{
using namespace pgsql;
{
pointer_type p (pointer_cache_traits::find (db, id));
if (!pointer_traits::null_ptr (p))
return p;
}
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (l.locked ())
{
if (!find_ (sts, &id))
return pointer_type ();
}
pointer_type p (
access::object_factory<object_type, pointer_type>::create ());
pointer_traits::guard pg (p);
pointer_cache_traits::insert_guard ig (
pointer_cache_traits::insert (db, id, p));
object_type& obj (pointer_traits::get_ref (p));
if (l.locked ())
{
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
pointer_cache_traits::load (ig.position ());
}
else
sts.delay_load (id, obj, ig.position ());
ig.release ();
pg.release ();
return p;
}
bool access::object_traits_impl< ::models::Agent, id_pgsql >::
find (database& db, const id_type& id, object_type& obj)
{
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
reference_cache_traits::position_type pos (
reference_cache_traits::insert (db, id, obj));
reference_cache_traits::insert_guard ig (pos);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
reference_cache_traits::load (pos);
ig.release ();
return true;
}
bool access::object_traits_impl< ::models::Agent, id_pgsql >::
reload (database& db, object_type& obj)
{
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
const id_type& id (
obj.id);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, true);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
return true;
}
bool access::object_traits_impl< ::models::Agent, id_pgsql >::
find_ (statements_type& sts,
const id_type* id)
{
using namespace pgsql;
id_image_type& i (sts.id_image ());
init (i, *id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
select_statement& st (sts.find_statement ());
st.execute ();
auto_result ar (st);
select_statement::result r (st.fetch ());
if (r == select_statement::truncated)
{
if (grow (im, sts.select_image_truncated ()))
im.version++;
if (im.version != sts.select_image_version ())
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
st.refetch ();
}
}
return r != select_statement::no_data;
}
result< access::object_traits_impl< ::models::Agent, id_pgsql >::object_type >
access::object_traits_impl< ::models::Agent, id_pgsql >::
query (database&, const query_base_type& q)
{
using namespace pgsql;
using odb::details::shared;
using odb::details::shared_ptr;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
std::string text (query_statement);
if (!q.empty ())
{
text += " ";
text += q.clause ();
}
q.init_parameters ();
shared_ptr<select_statement> st (
new (shared) select_statement (
sts.connection (),
query_statement_name,
text,
false,
true,
q.parameter_types (),
q.parameter_count (),
q.parameters_binding (),
imb));
st->execute ();
st->deallocate ();
shared_ptr< odb::object_result_impl<object_type> > r (
new (shared) pgsql::object_result_impl<object_type> (
q, st, sts, 0));
return result<object_type> (r);
}
unsigned long long access::object_traits_impl< ::models::Agent, id_pgsql >::
erase_query (database&, const query_base_type& q)
{
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
std::string text (erase_query_statement);
if (!q.empty ())
{
text += ' ';
text += q.clause ();
}
q.init_parameters ();
delete_statement st (
conn,
erase_query_statement_name,
text,
q.parameter_types (),
q.parameter_count (),
q.parameters_binding ());
return st.execute ();
}
}
#include <odb/post.hxx>
@@ -0,0 +1,353 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef AGENT_ODB_HXX
#define AGENT_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "Agent.h"
#include <memory>
#include <cstddef>
#include <utility>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// Agent
//
template <>
struct class_traits< ::models::Agent >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::models::Agent >
{
public:
typedef ::models::Agent object_type;
typedef ::models::Agent* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;
static const bool polymorphic = false;
typedef ::std::string id_type;
static const bool auto_id = false;
static const bool abstract = false;
static id_type
id (const object_type&);
typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;
typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;
static void
callback (database&, object_type&, callback_event);
static void
callback (database&, const object_type&, callback_event);
};
}
#include <odb/details/buffer.hxx>
#include <odb/pgsql/version.hxx>
#include <odb/pgsql/forward.hxx>
#include <odb/pgsql/binding.hxx>
#include <odb/pgsql/pgsql-types.hxx>
#include <odb/pgsql/query.hxx>
namespace odb
{
// Agent
//
template <typename A>
struct query_columns< ::models::Agent, id_pgsql, A >
{
// id
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
id_type_;
static const id_type_ id;
// role
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
role_type_;
static const role_type_ role;
// persistent
//
typedef
pgsql::query_column<
pgsql::value_traits<
bool,
pgsql::id_boolean >::query_type,
pgsql::id_boolean >
persistent_type_;
static const persistent_type_ persistent;
// displayName
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
displayName_type_;
static const displayName_type_ displayName;
// trustScore
//
typedef
pgsql::query_column<
pgsql::value_traits<
::int32_t,
pgsql::id_integer >::query_type,
pgsql::id_integer >
trustScore_type_;
static const trustScore_type_ trustScore;
};
template <typename A>
const typename query_columns< ::models::Agent, id_pgsql, A >::id_type_
query_columns< ::models::Agent, id_pgsql, A >::
id (A::table_name, "\"id\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_pgsql, A >::role_type_
query_columns< ::models::Agent, id_pgsql, A >::
role (A::table_name, "\"role\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_pgsql, A >::persistent_type_
query_columns< ::models::Agent, id_pgsql, A >::
persistent (A::table_name, "\"persistent\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_pgsql, A >::displayName_type_
query_columns< ::models::Agent, id_pgsql, A >::
displayName (A::table_name, "\"displayName\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_pgsql, A >::trustScore_type_
query_columns< ::models::Agent, id_pgsql, A >::
trustScore (A::table_name, "\"trustScore\"", 0);
template <typename A>
struct pointer_query_columns< ::models::Agent, id_pgsql, A >:
query_columns< ::models::Agent, id_pgsql, A >
{
};
template <>
class access::object_traits_impl< ::models::Agent, id_pgsql >:
public access::object_traits< ::models::Agent >
{
public:
struct id_image_type
{
details::buffer id_value;
std::size_t id_size;
bool id_null;
std::size_t version;
};
struct image_type
{
// id
//
details::buffer id_value;
std::size_t id_size;
bool id_null;
// role
//
details::buffer role_value;
std::size_t role_size;
bool role_null;
// persistent
//
bool persistent_value;
bool persistent_null;
// displayName
//
details::buffer displayName_value;
std::size_t displayName_size;
bool displayName_null;
// trustScore
//
int trustScore_value;
bool trustScore_null;
std::size_t version;
};
struct extra_statement_cache_type;
using object_traits<object_type>::id;
static id_type
id (const image_type&);
static bool
grow (image_type&,
bool*);
static void
bind (pgsql::bind*,
image_type&,
pgsql::statement_kind);
static void
bind (pgsql::bind*, id_image_type&);
static bool
init (image_type&,
const object_type&,
pgsql::statement_kind);
static void
init (object_type&,
const image_type&,
database*);
static void
init (id_image_type&, const id_type&);
typedef pgsql::object_statements<object_type> statements_type;
typedef pgsql::query_base query_base_type;
static const std::size_t column_count = 5UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 0UL;
static const std::size_t managed_optimistic_column_count = 0UL;
static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;
static const bool versioned = false;
static const char persist_statement[];
static const char find_statement[];
static const char update_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];
static const char table_name[];
static void
persist (database&, const object_type&);
static pointer_type
find (database&, const id_type&);
static bool
find (database&, const id_type&, object_type&);
static bool
reload (database&, object_type&);
static void
update (database&, const object_type&);
static void
erase (database&, const id_type&);
static void
erase (database&, const object_type&);
static result<object_type>
query (database&, const query_base_type&);
static unsigned long long
erase_query (database&, const query_base_type&);
static const char persist_statement_name[];
static const char find_statement_name[];
static const char update_statement_name[];
static const char erase_statement_name[];
static const char query_statement_name[];
static const char erase_query_statement_name[];
static const unsigned int persist_statement_types[];
static const unsigned int find_statement_types[];
static const unsigned int update_statement_types[];
public:
static bool
find_ (statements_type&,
const id_type*);
static void
load_ (statements_type&,
object_type&,
bool reload);
};
template <>
class access::object_traits_impl< ::models::Agent, id_common >:
public access::object_traits_impl< ::models::Agent, id_pgsql >
{
};
// Agent
//
}
#include "Agent-odb.ixx"
#include <odb/post.hxx>
#endif // AGENT_ODB_HXX
@@ -0,0 +1,61 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
namespace odb
{
// Agent
//
inline
access::object_traits< ::models::Agent >::id_type
access::object_traits< ::models::Agent >::
id (const object_type& o)
{
return o.id;
}
inline
void access::object_traits< ::models::Agent >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
inline
void access::object_traits< ::models::Agent >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}
namespace odb
{
// Agent
//
inline
void access::object_traits_impl< ::models::Agent, id_pgsql >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}
inline
void access::object_traits_impl< ::models::Agent, id_pgsql >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}
@@ -0,0 +1,24 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
DROP TABLE IF EXISTS "Agent" CASCADE;
DROP TABLE IF EXISTS "schema_version";
CREATE TABLE "Agent" (
"id" TEXT NOT NULL PRIMARY KEY,
"role" TEXT NOT NULL,
"persistent" BOOLEAN NOT NULL,
"displayName" TEXT NOT NULL,
"trustScore" INTEGER NOT NULL);
CREATE TABLE "schema_version" (
"name" TEXT NOT NULL PRIMARY KEY,
"version" BIGINT NOT NULL,
"migration" BOOLEAN NOT NULL);
INSERT INTO "schema_version" (
"name", "version", "migration")
VALUES ('', 2, FALSE);
@@ -0,0 +1,8 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
UPDATE "schema_version"
SET "migration" = FALSE
WHERE "name" = '';
@@ -0,0 +1,13 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
CREATE TABLE "GovernmentAddress" (
"id" TEXT NOT NULL PRIMARY KEY,
"addressLabel" TEXT NOT NULL,
"regionLookupKey" TEXT NOT NULL);
UPDATE "schema_version"
SET "version" = 2, "migration" = TRUE
WHERE "name" = '';
@@ -0,0 +1,774 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#include <odb/pre.hxx>
#include "GovernmentAddress-odb.hxx"
#include <cassert>
#include <cstring> // std::memcpy
#include <odb/pgsql/traits.hxx>
#include <odb/pgsql/database.hxx>
#include <odb/pgsql/transaction.hxx>
#include <odb/pgsql/connection.hxx>
#include <odb/pgsql/statement.hxx>
#include <odb/pgsql/statement-cache.hxx>
#include <odb/pgsql/simple-object-statements.hxx>
#include <odb/pgsql/container-statements.hxx>
#include <odb/pgsql/exceptions.hxx>
#include <odb/pgsql/simple-object-result.hxx>
namespace odb
{
// GovernmentAddress
//
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
persist_statement_name[] = "persist_models_GovernmentAddress";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
find_statement_name[] = "find_models_GovernmentAddress";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
update_statement_name[] = "update_models_GovernmentAddress";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
erase_statement_name[] = "erase_models_GovernmentAddress";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
query_statement_name[] = "query_models_GovernmentAddress";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
erase_query_statement_name[] = "erase_query_models_GovernmentAddress";
const unsigned int access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
persist_statement_types[] =
{
pgsql::text_oid,
pgsql::text_oid,
pgsql::text_oid
};
const unsigned int access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
find_statement_types[] =
{
pgsql::text_oid
};
const unsigned int access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
update_statement_types[] =
{
pgsql::text_oid,
pgsql::text_oid,
pgsql::text_oid
};
struct access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::extra_statement_cache_type
{
extra_statement_cache_type (
pgsql::connection&,
image_type&,
id_image_type&,
pgsql::binding&,
pgsql::binding&,
pgsql::native_binding&,
const unsigned int*)
{
}
};
access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::id_type
access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
id (const image_type& i)
{
pgsql::database* db (0);
ODB_POTENTIALLY_UNUSED (db);
id_type id;
{
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
id,
i.id_value,
i.id_size,
i.id_null);
}
return id;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
grow (image_type& i,
bool* t)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (t);
bool grew (false);
// id
//
if (t[0UL])
{
i.id_value.capacity (i.id_size);
grew = true;
}
// addressLabel
//
if (t[1UL])
{
i.addressLabel_value.capacity (i.addressLabel_size);
grew = true;
}
// regionLookupKey
//
if (t[2UL])
{
i.regionLookupKey_value.capacity (i.regionLookupKey_size);
grew = true;
}
return grew;
}
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
bind (pgsql::bind* b,
image_type& i,
pgsql::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (sk);
using namespace pgsql;
std::size_t n (0);
// id
//
if (sk != statement_update)
{
b[n].type = pgsql::bind::text;
b[n].buffer = i.id_value.data ();
b[n].capacity = i.id_value.capacity ();
b[n].size = &i.id_size;
b[n].is_null = &i.id_null;
n++;
}
// addressLabel
//
b[n].type = pgsql::bind::text;
b[n].buffer = i.addressLabel_value.data ();
b[n].capacity = i.addressLabel_value.capacity ();
b[n].size = &i.addressLabel_size;
b[n].is_null = &i.addressLabel_null;
n++;
// regionLookupKey
//
b[n].type = pgsql::bind::text;
b[n].buffer = i.regionLookupKey_value.data ();
b[n].capacity = i.regionLookupKey_value.capacity ();
b[n].size = &i.regionLookupKey_size;
b[n].is_null = &i.regionLookupKey_null;
n++;
}
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
bind (pgsql::bind* b, id_image_type& i)
{
std::size_t n (0);
b[n].type = pgsql::bind::text;
b[n].buffer = i.id_value.data ();
b[n].capacity = i.id_value.capacity ();
b[n].size = &i.id_size;
b[n].is_null = &i.id_null;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
init (image_type& i,
const object_type& o,
pgsql::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (sk);
using namespace pgsql;
bool grew (false);
// id
//
if (sk == statement_insert)
{
::std::string const& v =
o.id;
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.id_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.id_value,
size,
is_null,
v);
i.id_null = is_null;
i.id_size = size;
grew = grew || (cap != i.id_value.capacity ());
}
// addressLabel
//
{
::std::string const& v =
o.addressLabel;
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.addressLabel_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.addressLabel_value,
size,
is_null,
v);
i.addressLabel_null = is_null;
i.addressLabel_size = size;
grew = grew || (cap != i.addressLabel_value.capacity ());
}
// regionLookupKey
//
{
::std::string const& v =
o.regionLookupKey;
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.regionLookupKey_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.regionLookupKey_value,
size,
is_null,
v);
i.regionLookupKey_null = is_null;
i.regionLookupKey_size = size;
grew = grew || (cap != i.regionLookupKey_value.capacity ());
}
return grew;
}
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
init (object_type& o,
const image_type& i,
database* db)
{
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (db);
// id
//
{
::std::string& v =
o.id;
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
v,
i.id_value,
i.id_size,
i.id_null);
}
// addressLabel
//
{
::std::string& v =
o.addressLabel;
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
v,
i.addressLabel_value,
i.addressLabel_size,
i.addressLabel_null);
}
// regionLookupKey
//
{
::std::string& v =
o.regionLookupKey;
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_value (
v,
i.regionLookupKey_value,
i.regionLookupKey_size,
i.regionLookupKey_null);
}
}
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
init (id_image_type& i, const id_type& id)
{
bool grew (false);
{
bool is_null (false);
std::size_t size (0);
std::size_t cap (i.id_value.capacity ());
pgsql::value_traits<
::std::string,
pgsql::id_string >::set_image (
i.id_value,
size,
is_null,
id);
i.id_null = is_null;
i.id_size = size;
grew = grew || (cap != i.id_value.capacity ());
}
if (grew)
i.version++;
}
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::persist_statement[] =
"INSERT INTO \"GovernmentAddress\" "
"(\"id\", "
"\"addressLabel\", "
"\"regionLookupKey\") "
"VALUES "
"($1, $2, $3)";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::find_statement[] =
"SELECT "
"\"GovernmentAddress\".\"id\", "
"\"GovernmentAddress\".\"addressLabel\", "
"\"GovernmentAddress\".\"regionLookupKey\" "
"FROM \"GovernmentAddress\" "
"WHERE \"GovernmentAddress\".\"id\"=$1";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::update_statement[] =
"UPDATE \"GovernmentAddress\" "
"SET "
"\"addressLabel\"=$1, "
"\"regionLookupKey\"=$2 "
"WHERE \"id\"=$3";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::erase_statement[] =
"DELETE FROM \"GovernmentAddress\" "
"WHERE \"id\"=$1";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::query_statement[] =
"SELECT "
"\"GovernmentAddress\".\"id\", "
"\"GovernmentAddress\".\"addressLabel\", "
"\"GovernmentAddress\".\"regionLookupKey\" "
"FROM \"GovernmentAddress\"";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::erase_query_statement[] =
"DELETE FROM \"GovernmentAddress\"";
const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::table_name[] =
"\"GovernmentAddress\"";
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
persist (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
callback (db,
obj,
callback_event::pre_persist);
image_type& im (sts.image ());
binding& imb (sts.insert_image_binding ());
if (init (im, obj, statement_insert))
im.version++;
if (im.version != sts.insert_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_insert);
sts.insert_image_version (im.version);
imb.version++;
}
insert_statement& st (sts.persist_statement ());
if (!st.execute ())
throw object_already_persistent ();
callback (db,
obj,
callback_event::post_persist);
}
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
update (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace pgsql;
using pgsql::update_statement;
callback (db, obj, callback_event::pre_update);
pgsql::transaction& tr (pgsql::transaction::current ());
pgsql::connection& conn (tr.connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
const id_type& id (
obj.id);
id_image_type& idi (sts.id_image ());
init (idi, id);
image_type& im (sts.image ());
if (init (im, obj, statement_update))
im.version++;
bool u (false);
binding& imb (sts.update_image_binding ());
if (im.version != sts.update_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_update);
sts.update_image_version (im.version);
imb.version++;
u = true;
}
binding& idb (sts.id_image_binding ());
if (idi.version != sts.update_id_image_version () ||
idb.version == 0)
{
if (idi.version != sts.id_image_version () ||
idb.version == 0)
{
bind (idb.bind, idi);
sts.id_image_version (idi.version);
idb.version++;
}
sts.update_id_image_version (idi.version);
if (!u)
imb.version++;
}
update_statement& st (sts.update_statement ());
if (st.execute () == 0)
throw object_not_persistent ();
callback (db, obj, callback_event::post_update);
pointer_cache_traits::update (db, obj);
}
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
erase (database& db, const id_type& id)
{
using namespace pgsql;
ODB_POTENTIALLY_UNUSED (db);
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
id_image_type& i (sts.id_image ());
init (i, id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
if (sts.erase_statement ().execute () != 1)
throw object_not_persistent ();
pointer_cache_traits::erase (db, id);
}
access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::pointer_type
access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
find (database& db, const id_type& id)
{
using namespace pgsql;
{
pointer_type p (pointer_cache_traits::find (db, id));
if (!pointer_traits::null_ptr (p))
return p;
}
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (l.locked ())
{
if (!find_ (sts, &id))
return pointer_type ();
}
pointer_type p (
access::object_factory<object_type, pointer_type>::create ());
pointer_traits::guard pg (p);
pointer_cache_traits::insert_guard ig (
pointer_cache_traits::insert (db, id, p));
object_type& obj (pointer_traits::get_ref (p));
if (l.locked ())
{
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
pointer_cache_traits::load (ig.position ());
}
else
sts.delay_load (id, obj, ig.position ());
ig.release ();
pg.release ();
return p;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
find (database& db, const id_type& id, object_type& obj)
{
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
reference_cache_traits::position_type pos (
reference_cache_traits::insert (db, id, obj));
reference_cache_traits::insert_guard ig (pos);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
reference_cache_traits::load (pos);
ig.release ();
return true;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
reload (database& db, object_type& obj)
{
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
const id_type& id (
obj.id);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, true);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
return true;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
find_ (statements_type& sts,
const id_type* id)
{
using namespace pgsql;
id_image_type& i (sts.id_image ());
init (i, *id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
select_statement& st (sts.find_statement ());
st.execute ();
auto_result ar (st);
select_statement::result r (st.fetch ());
if (r == select_statement::truncated)
{
if (grow (im, sts.select_image_truncated ()))
im.version++;
if (im.version != sts.select_image_version ())
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
st.refetch ();
}
}
return r != select_statement::no_data;
}
result< access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::object_type >
access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
query (database&, const query_base_type& q)
{
using namespace pgsql;
using odb::details::shared;
using odb::details::shared_ptr;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
std::string text (query_statement);
if (!q.empty ())
{
text += " ";
text += q.clause ();
}
q.init_parameters ();
shared_ptr<select_statement> st (
new (shared) select_statement (
sts.connection (),
query_statement_name,
text,
false,
true,
q.parameter_types (),
q.parameter_count (),
q.parameters_binding (),
imb));
st->execute ();
st->deallocate ();
shared_ptr< odb::object_result_impl<object_type> > r (
new (shared) pgsql::object_result_impl<object_type> (
q, st, sts, 0));
return result<object_type> (r);
}
unsigned long long access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
erase_query (database&, const query_base_type& q)
{
using namespace pgsql;
pgsql::connection& conn (
pgsql::transaction::current ().connection ());
std::string text (erase_query_statement);
if (!q.empty ())
{
text += ' ';
text += q.clause ();
}
q.init_parameters ();
delete_statement st (
conn,
erase_query_statement_name,
text,
q.parameter_types (),
q.parameter_count (),
q.parameters_binding ());
return st.execute ();
}
}
#include <odb/post.hxx>
@@ -0,0 +1,309 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef GOVERNMENT_ADDRESS_ODB_HXX
#define GOVERNMENT_ADDRESS_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "GovernmentAddress.h"
#include <memory>
#include <cstddef>
#include <utility>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// GovernmentAddress
//
template <>
struct class_traits< ::models::GovernmentAddress >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::models::GovernmentAddress >
{
public:
typedef ::models::GovernmentAddress object_type;
typedef ::models::GovernmentAddress* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;
static const bool polymorphic = false;
typedef ::std::string id_type;
static const bool auto_id = false;
static const bool abstract = false;
static id_type
id (const object_type&);
typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;
typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;
static void
callback (database&, object_type&, callback_event);
static void
callback (database&, const object_type&, callback_event);
};
}
#include <odb/details/buffer.hxx>
#include <odb/pgsql/version.hxx>
#include <odb/pgsql/forward.hxx>
#include <odb/pgsql/binding.hxx>
#include <odb/pgsql/pgsql-types.hxx>
#include <odb/pgsql/query.hxx>
namespace odb
{
// GovernmentAddress
//
template <typename A>
struct query_columns< ::models::GovernmentAddress, id_pgsql, A >
{
// id
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
id_type_;
static const id_type_ id;
// addressLabel
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
addressLabel_type_;
static const addressLabel_type_ addressLabel;
// regionLookupKey
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
regionLookupKey_type_;
static const regionLookupKey_type_ regionLookupKey;
};
template <typename A>
const typename query_columns< ::models::GovernmentAddress, id_pgsql, A >::id_type_
query_columns< ::models::GovernmentAddress, id_pgsql, A >::
id (A::table_name, "\"id\"", 0);
template <typename A>
const typename query_columns< ::models::GovernmentAddress, id_pgsql, A >::addressLabel_type_
query_columns< ::models::GovernmentAddress, id_pgsql, A >::
addressLabel (A::table_name, "\"addressLabel\"", 0);
template <typename A>
const typename query_columns< ::models::GovernmentAddress, id_pgsql, A >::regionLookupKey_type_
query_columns< ::models::GovernmentAddress, id_pgsql, A >::
regionLookupKey (A::table_name, "\"regionLookupKey\"", 0);
template <typename A>
struct pointer_query_columns< ::models::GovernmentAddress, id_pgsql, A >:
query_columns< ::models::GovernmentAddress, id_pgsql, A >
{
};
template <>
class access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:
public access::object_traits< ::models::GovernmentAddress >
{
public:
struct id_image_type
{
details::buffer id_value;
std::size_t id_size;
bool id_null;
std::size_t version;
};
struct image_type
{
// id
//
details::buffer id_value;
std::size_t id_size;
bool id_null;
// addressLabel
//
details::buffer addressLabel_value;
std::size_t addressLabel_size;
bool addressLabel_null;
// regionLookupKey
//
details::buffer regionLookupKey_value;
std::size_t regionLookupKey_size;
bool regionLookupKey_null;
std::size_t version;
};
struct extra_statement_cache_type;
using object_traits<object_type>::id;
static id_type
id (const image_type&);
static bool
grow (image_type&,
bool*);
static void
bind (pgsql::bind*,
image_type&,
pgsql::statement_kind);
static void
bind (pgsql::bind*, id_image_type&);
static bool
init (image_type&,
const object_type&,
pgsql::statement_kind);
static void
init (object_type&,
const image_type&,
database*);
static void
init (id_image_type&, const id_type&);
typedef pgsql::object_statements<object_type> statements_type;
typedef pgsql::query_base query_base_type;
static const std::size_t column_count = 3UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 0UL;
static const std::size_t managed_optimistic_column_count = 0UL;
static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;
static const bool versioned = false;
static const char persist_statement[];
static const char find_statement[];
static const char update_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];
static const char table_name[];
static void
persist (database&, const object_type&);
static pointer_type
find (database&, const id_type&);
static bool
find (database&, const id_type&, object_type&);
static bool
reload (database&, object_type&);
static void
update (database&, const object_type&);
static void
erase (database&, const id_type&);
static void
erase (database&, const object_type&);
static result<object_type>
query (database&, const query_base_type&);
static unsigned long long
erase_query (database&, const query_base_type&);
static const char persist_statement_name[];
static const char find_statement_name[];
static const char update_statement_name[];
static const char erase_statement_name[];
static const char query_statement_name[];
static const char erase_query_statement_name[];
static const unsigned int persist_statement_types[];
static const unsigned int find_statement_types[];
static const unsigned int update_statement_types[];
public:
static bool
find_ (statements_type&,
const id_type*);
static void
load_ (statements_type&,
object_type&,
bool reload);
};
template <>
class access::object_traits_impl< ::models::GovernmentAddress, id_common >:
public access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >
{
};
// GovernmentAddress
//
}
#include "GovernmentAddress-odb.ixx"
#include <odb/post.hxx>
#endif // GOVERNMENT_ADDRESS_ODB_HXX
@@ -0,0 +1,61 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
namespace odb
{
// GovernmentAddress
//
inline
access::object_traits< ::models::GovernmentAddress >::id_type
access::object_traits< ::models::GovernmentAddress >::
id (const object_type& o)
{
return o.id;
}
inline
void access::object_traits< ::models::GovernmentAddress >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
inline
void access::object_traits< ::models::GovernmentAddress >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}
namespace odb
{
// GovernmentAddress
//
inline
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}
inline
void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}
@@ -0,0 +1,22 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
DROP TABLE IF EXISTS "GovernmentAddress" CASCADE;
DROP TABLE IF EXISTS "schema_version";
CREATE TABLE "GovernmentAddress" (
"id" TEXT NOT NULL PRIMARY KEY,
"addressLabel" TEXT NOT NULL,
"regionLookupKey" TEXT NOT NULL);
CREATE TABLE "schema_version" (
"name" TEXT NOT NULL PRIMARY KEY,
"version" BIGINT NOT NULL,
"migration" BOOLEAN NOT NULL);
INSERT INTO "schema_version" (
"name", "version", "migration")
VALUES ('', 2, FALSE);
@@ -0,0 +1,8 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
UPDATE "schema_version"
SET "migration" = FALSE
WHERE "name" = '';
@@ -0,0 +1,22 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
CREATE TABLE "TripAttemptResult" (
"id" TEXT NOT NULL PRIMARY KEY,
"result" TEXT NOT NULL,
"retryReason" TEXT NOT NULL,
"governmentSuspensionReason" TEXT NOT NULL,
"governmentTerminationReason" TEXT NOT NULL,
"complianceSuspensionReason" TEXT NOT NULL,
"complianceTerminationReason" TEXT NOT NULL,
"policySuspensionReason" TEXT NOT NULL,
"policyTerminationReason" TEXT NOT NULL,
"cancelationReason" TEXT NOT NULL,
"failureReason" TEXT NOT NULL,
"details" TEXT NOT NULL);
UPDATE "schema_version"
SET "version" = 2, "migration" = TRUE
WHERE "name" = '';
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,516 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef TRIP_ATTEMPT_RESULT_ODB_HXX
#define TRIP_ATTEMPT_RESULT_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "TripAttemptResult.h"
#include <memory>
#include <cstddef>
#include <utility>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// TripAttemptResult
//
template <>
struct class_traits< ::models::TripAttemptResult >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::models::TripAttemptResult >
{
public:
typedef ::models::TripAttemptResult object_type;
typedef ::models::TripAttemptResult* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;
static const bool polymorphic = false;
typedef ::std::string id_type;
static const bool auto_id = false;
static const bool abstract = false;
static id_type
id (const object_type&);
typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;
typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;
static void
callback (database&, object_type&, callback_event);
static void
callback (database&, const object_type&, callback_event);
};
}
#include <odb/details/buffer.hxx>
#include <odb/pgsql/version.hxx>
#include <odb/pgsql/forward.hxx>
#include <odb/pgsql/binding.hxx>
#include <odb/pgsql/pgsql-types.hxx>
#include <odb/pgsql/query.hxx>
namespace odb
{
// TripAttemptResult
//
template <typename A>
struct query_columns< ::models::TripAttemptResult, id_pgsql, A >
{
// id
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
id_type_;
static const id_type_ id;
// result
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
result_type_;
static const result_type_ result;
// retryReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
retryReason_type_;
static const retryReason_type_ retryReason;
// governmentSuspensionReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
governmentSuspensionReason_type_;
static const governmentSuspensionReason_type_ governmentSuspensionReason;
// governmentTerminationReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
governmentTerminationReason_type_;
static const governmentTerminationReason_type_ governmentTerminationReason;
// complianceSuspensionReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
complianceSuspensionReason_type_;
static const complianceSuspensionReason_type_ complianceSuspensionReason;
// complianceTerminationReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
complianceTerminationReason_type_;
static const complianceTerminationReason_type_ complianceTerminationReason;
// policySuspensionReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
policySuspensionReason_type_;
static const policySuspensionReason_type_ policySuspensionReason;
// policyTerminationReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
policyTerminationReason_type_;
static const policyTerminationReason_type_ policyTerminationReason;
// cancelationReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
cancelationReason_type_;
static const cancelationReason_type_ cancelationReason;
// failureReason
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
failureReason_type_;
static const failureReason_type_ failureReason;
// details
//
typedef
pgsql::query_column<
pgsql::value_traits<
::std::string,
pgsql::id_string >::query_type,
pgsql::id_string >
details_type_;
static const details_type_ details;
};
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::id_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
id (A::table_name, "\"id\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::result_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
result (A::table_name, "\"result\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::retryReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
retryReason (A::table_name, "\"retryReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::governmentSuspensionReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
governmentSuspensionReason (A::table_name, "\"governmentSuspensionReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::governmentTerminationReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
governmentTerminationReason (A::table_name, "\"governmentTerminationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::complianceSuspensionReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
complianceSuspensionReason (A::table_name, "\"complianceSuspensionReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::complianceTerminationReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
complianceTerminationReason (A::table_name, "\"complianceTerminationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::policySuspensionReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
policySuspensionReason (A::table_name, "\"policySuspensionReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::policyTerminationReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
policyTerminationReason (A::table_name, "\"policyTerminationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::cancelationReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
cancelationReason (A::table_name, "\"cancelationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::failureReason_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
failureReason (A::table_name, "\"failureReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::details_type_
query_columns< ::models::TripAttemptResult, id_pgsql, A >::
details (A::table_name, "\"details\"", 0);
template <typename A>
struct pointer_query_columns< ::models::TripAttemptResult, id_pgsql, A >:
query_columns< ::models::TripAttemptResult, id_pgsql, A >
{
};
template <>
class access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:
public access::object_traits< ::models::TripAttemptResult >
{
public:
struct id_image_type
{
details::buffer id_value;
std::size_t id_size;
bool id_null;
std::size_t version;
};
struct image_type
{
// id
//
details::buffer id_value;
std::size_t id_size;
bool id_null;
// result
//
details::buffer result_value;
std::size_t result_size;
bool result_null;
// retryReason
//
details::buffer retryReason_value;
std::size_t retryReason_size;
bool retryReason_null;
// governmentSuspensionReason
//
details::buffer governmentSuspensionReason_value;
std::size_t governmentSuspensionReason_size;
bool governmentSuspensionReason_null;
// governmentTerminationReason
//
details::buffer governmentTerminationReason_value;
std::size_t governmentTerminationReason_size;
bool governmentTerminationReason_null;
// complianceSuspensionReason
//
details::buffer complianceSuspensionReason_value;
std::size_t complianceSuspensionReason_size;
bool complianceSuspensionReason_null;
// complianceTerminationReason
//
details::buffer complianceTerminationReason_value;
std::size_t complianceTerminationReason_size;
bool complianceTerminationReason_null;
// policySuspensionReason
//
details::buffer policySuspensionReason_value;
std::size_t policySuspensionReason_size;
bool policySuspensionReason_null;
// policyTerminationReason
//
details::buffer policyTerminationReason_value;
std::size_t policyTerminationReason_size;
bool policyTerminationReason_null;
// cancelationReason
//
details::buffer cancelationReason_value;
std::size_t cancelationReason_size;
bool cancelationReason_null;
// failureReason
//
details::buffer failureReason_value;
std::size_t failureReason_size;
bool failureReason_null;
// details
//
details::buffer details_value;
std::size_t details_size;
bool details_null;
std::size_t version;
};
struct extra_statement_cache_type;
using object_traits<object_type>::id;
static id_type
id (const image_type&);
static bool
grow (image_type&,
bool*);
static void
bind (pgsql::bind*,
image_type&,
pgsql::statement_kind);
static void
bind (pgsql::bind*, id_image_type&);
static bool
init (image_type&,
const object_type&,
pgsql::statement_kind);
static void
init (object_type&,
const image_type&,
database*);
static void
init (id_image_type&, const id_type&);
typedef pgsql::object_statements<object_type> statements_type;
typedef pgsql::query_base query_base_type;
static const std::size_t column_count = 12UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 0UL;
static const std::size_t managed_optimistic_column_count = 0UL;
static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;
static const bool versioned = false;
static const char persist_statement[];
static const char find_statement[];
static const char update_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];
static const char table_name[];
static void
persist (database&, const object_type&);
static pointer_type
find (database&, const id_type&);
static bool
find (database&, const id_type&, object_type&);
static bool
reload (database&, object_type&);
static void
update (database&, const object_type&);
static void
erase (database&, const id_type&);
static void
erase (database&, const object_type&);
static result<object_type>
query (database&, const query_base_type&);
static unsigned long long
erase_query (database&, const query_base_type&);
static const char persist_statement_name[];
static const char find_statement_name[];
static const char update_statement_name[];
static const char erase_statement_name[];
static const char query_statement_name[];
static const char erase_query_statement_name[];
static const unsigned int persist_statement_types[];
static const unsigned int find_statement_types[];
static const unsigned int update_statement_types[];
public:
static bool
find_ (statements_type&,
const id_type*);
static void
load_ (statements_type&,
object_type&,
bool reload);
};
template <>
class access::object_traits_impl< ::models::TripAttemptResult, id_common >:
public access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >
{
};
// TripAttemptResult
//
}
#include "TripAttemptResult-odb.ixx"
#include <odb/post.hxx>
#endif // TRIP_ATTEMPT_RESULT_ODB_HXX
@@ -0,0 +1,61 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
namespace odb
{
// TripAttemptResult
//
inline
access::object_traits< ::models::TripAttemptResult >::id_type
access::object_traits< ::models::TripAttemptResult >::
id (const object_type& o)
{
return o.id;
}
inline
void access::object_traits< ::models::TripAttemptResult >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
inline
void access::object_traits< ::models::TripAttemptResult >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}
namespace odb
{
// TripAttemptResult
//
inline
void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}
inline
void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}
@@ -0,0 +1,31 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
DROP TABLE IF EXISTS "TripAttemptResult" CASCADE;
DROP TABLE IF EXISTS "schema_version";
CREATE TABLE "TripAttemptResult" (
"id" TEXT NOT NULL PRIMARY KEY,
"result" TEXT NOT NULL,
"retryReason" TEXT NOT NULL,
"governmentSuspensionReason" TEXT NOT NULL,
"governmentTerminationReason" TEXT NOT NULL,
"complianceSuspensionReason" TEXT NOT NULL,
"complianceTerminationReason" TEXT NOT NULL,
"policySuspensionReason" TEXT NOT NULL,
"policyTerminationReason" TEXT NOT NULL,
"cancelationReason" TEXT NOT NULL,
"failureReason" TEXT NOT NULL,
"details" TEXT NOT NULL);
CREATE TABLE "schema_version" (
"name" TEXT NOT NULL PRIMARY KEY,
"version" BIGINT NOT NULL,
"migration" BOOLEAN NOT NULL);
INSERT INTO "schema_version" (
"name", "version", "migration")
VALUES ('', 2, FALSE);
@@ -0,0 +1,8 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
UPDATE "schema_version"
SET "migration" = 0
WHERE "name" = '';
@@ -0,0 +1,15 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
CREATE TABLE "Agent" (
"id" TEXT NOT NULL PRIMARY KEY,
"role" TEXT NOT NULL,
"persistent" INTEGER NOT NULL,
"displayName" TEXT NOT NULL,
"trustScore" INTEGER NOT NULL);
UPDATE "schema_version"
SET "version" = 2, "migration" = 1
WHERE "name" = '';
@@ -0,0 +1,815 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#include <odb/pre.hxx>
#include "Agent-odb.hxx"
#include <cassert>
#include <cstring> // std::memcpy
#include <odb/sqlite/traits.hxx>
#include <odb/sqlite/database.hxx>
#include <odb/sqlite/transaction.hxx>
#include <odb/sqlite/connection.hxx>
#include <odb/sqlite/statement.hxx>
#include <odb/sqlite/statement-cache.hxx>
#include <odb/sqlite/simple-object-statements.hxx>
#include <odb/sqlite/container-statements.hxx>
#include <odb/sqlite/exceptions.hxx>
#include <odb/sqlite/simple-object-result.hxx>
namespace odb
{
// Agent
//
struct access::object_traits_impl< ::models::Agent, id_sqlite >::extra_statement_cache_type
{
extra_statement_cache_type (
sqlite::connection&,
image_type&,
id_image_type&,
sqlite::binding&,
sqlite::binding&)
{
}
};
access::object_traits_impl< ::models::Agent, id_sqlite >::id_type
access::object_traits_impl< ::models::Agent, id_sqlite >::
id (const image_type& i)
{
sqlite::database* db (0);
ODB_POTENTIALLY_UNUSED (db);
id_type id;
{
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
id,
i.id_value,
i.id_size,
i.id_null);
}
return id;
}
bool access::object_traits_impl< ::models::Agent, id_sqlite >::
grow (image_type& i,
bool* t)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (t);
bool grew (false);
// id
//
if (t[0UL])
{
i.id_value.capacity (i.id_size);
grew = true;
}
// role
//
if (t[1UL])
{
i.role_value.capacity (i.role_size);
grew = true;
}
// persistent
//
t[2UL] = false;
// displayName
//
if (t[3UL])
{
i.displayName_value.capacity (i.displayName_size);
grew = true;
}
// trustScore
//
t[4UL] = false;
return grew;
}
void access::object_traits_impl< ::models::Agent, id_sqlite >::
bind (sqlite::bind* b,
image_type& i,
sqlite::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (sk);
using namespace sqlite;
std::size_t n (0);
// id
//
if (sk != statement_update)
{
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.id_value.data ();
b[n].size = &i.id_size;
b[n].capacity = i.id_value.capacity ();
b[n].is_null = &i.id_null;
n++;
}
// role
//
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.role_value.data ();
b[n].size = &i.role_size;
b[n].capacity = i.role_value.capacity ();
b[n].is_null = &i.role_null;
n++;
// persistent
//
b[n].type = sqlite::bind::integer;
b[n].buffer = &i.persistent_value;
b[n].is_null = &i.persistent_null;
n++;
// displayName
//
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.displayName_value.data ();
b[n].size = &i.displayName_size;
b[n].capacity = i.displayName_value.capacity ();
b[n].is_null = &i.displayName_null;
n++;
// trustScore
//
b[n].type = sqlite::bind::integer;
b[n].buffer = &i.trustScore_value;
b[n].is_null = &i.trustScore_null;
n++;
}
void access::object_traits_impl< ::models::Agent, id_sqlite >::
bind (sqlite::bind* b, id_image_type& i)
{
std::size_t n (0);
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.id_value.data ();
b[n].size = &i.id_size;
b[n].capacity = i.id_value.capacity ();
b[n].is_null = &i.id_null;
}
bool access::object_traits_impl< ::models::Agent, id_sqlite >::
init (image_type& i,
const object_type& o,
sqlite::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (sk);
using namespace sqlite;
bool grew (false);
// id
//
if (sk == statement_insert)
{
::std::string const& v =
o.id;
bool is_null (false);
std::size_t cap (i.id_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.id_value,
i.id_size,
is_null,
v);
i.id_null = is_null;
grew = grew || (cap != i.id_value.capacity ());
}
// role
//
{
::std::string const& v =
o.role;
bool is_null (false);
std::size_t cap (i.role_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.role_value,
i.role_size,
is_null,
v);
i.role_null = is_null;
grew = grew || (cap != i.role_value.capacity ());
}
// persistent
//
{
bool const& v =
o.persistent;
bool is_null (false);
sqlite::value_traits<
bool,
sqlite::id_integer >::set_image (
i.persistent_value,
is_null,
v);
i.persistent_null = is_null;
}
// displayName
//
{
::std::string const& v =
o.displayName;
bool is_null (false);
std::size_t cap (i.displayName_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.displayName_value,
i.displayName_size,
is_null,
v);
i.displayName_null = is_null;
grew = grew || (cap != i.displayName_value.capacity ());
}
// trustScore
//
{
::int32_t const& v =
o.trustScore;
bool is_null (false);
sqlite::value_traits<
::int32_t,
sqlite::id_integer >::set_image (
i.trustScore_value,
is_null,
v);
i.trustScore_null = is_null;
}
return grew;
}
void access::object_traits_impl< ::models::Agent, id_sqlite >::
init (object_type& o,
const image_type& i,
database* db)
{
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (db);
// id
//
{
::std::string& v =
o.id;
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
v,
i.id_value,
i.id_size,
i.id_null);
}
// role
//
{
::std::string& v =
o.role;
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
v,
i.role_value,
i.role_size,
i.role_null);
}
// persistent
//
{
bool& v =
o.persistent;
sqlite::value_traits<
bool,
sqlite::id_integer >::set_value (
v,
i.persistent_value,
i.persistent_null);
}
// displayName
//
{
::std::string& v =
o.displayName;
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
v,
i.displayName_value,
i.displayName_size,
i.displayName_null);
}
// trustScore
//
{
::int32_t& v =
o.trustScore;
sqlite::value_traits<
::int32_t,
sqlite::id_integer >::set_value (
v,
i.trustScore_value,
i.trustScore_null);
}
}
void access::object_traits_impl< ::models::Agent, id_sqlite >::
init (id_image_type& i, const id_type& id)
{
bool grew (false);
{
bool is_null (false);
std::size_t cap (i.id_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.id_value,
i.id_size,
is_null,
id);
i.id_null = is_null;
grew = grew || (cap != i.id_value.capacity ());
}
if (grew)
i.version++;
}
const char access::object_traits_impl< ::models::Agent, id_sqlite >::persist_statement[] =
"INSERT INTO \"Agent\" "
"(\"id\", "
"\"role\", "
"\"persistent\", "
"\"displayName\", "
"\"trustScore\") "
"VALUES "
"(?, ?, ?, ?, ?)";
const char access::object_traits_impl< ::models::Agent, id_sqlite >::find_statement[] =
"SELECT "
"\"Agent\".\"id\", "
"\"Agent\".\"role\", "
"\"Agent\".\"persistent\", "
"\"Agent\".\"displayName\", "
"\"Agent\".\"trustScore\" "
"FROM \"Agent\" "
"WHERE \"Agent\".\"id\"=?";
const char access::object_traits_impl< ::models::Agent, id_sqlite >::update_statement[] =
"UPDATE \"Agent\" "
"SET "
"\"role\"=?, "
"\"persistent\"=?, "
"\"displayName\"=?, "
"\"trustScore\"=? "
"WHERE \"id\"=?";
const char access::object_traits_impl< ::models::Agent, id_sqlite >::erase_statement[] =
"DELETE FROM \"Agent\" "
"WHERE \"id\"=?";
const char access::object_traits_impl< ::models::Agent, id_sqlite >::query_statement[] =
"SELECT "
"\"Agent\".\"id\", "
"\"Agent\".\"role\", "
"\"Agent\".\"persistent\", "
"\"Agent\".\"displayName\", "
"\"Agent\".\"trustScore\" "
"FROM \"Agent\"";
const char access::object_traits_impl< ::models::Agent, id_sqlite >::erase_query_statement[] =
"DELETE FROM \"Agent\"";
const char access::object_traits_impl< ::models::Agent, id_sqlite >::table_name[] =
"\"Agent\"";
void access::object_traits_impl< ::models::Agent, id_sqlite >::
persist (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
callback (db,
obj,
callback_event::pre_persist);
image_type& im (sts.image ());
binding& imb (sts.insert_image_binding ());
if (init (im, obj, statement_insert))
im.version++;
if (im.version != sts.insert_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_insert);
sts.insert_image_version (im.version);
imb.version++;
}
insert_statement& st (sts.persist_statement ());
if (!st.execute ())
throw object_already_persistent ();
callback (db,
obj,
callback_event::post_persist);
}
void access::object_traits_impl< ::models::Agent, id_sqlite >::
update (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace sqlite;
using sqlite::update_statement;
callback (db, obj, callback_event::pre_update);
sqlite::transaction& tr (sqlite::transaction::current ());
sqlite::connection& conn (tr.connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
const id_type& id (
obj.id);
id_image_type& idi (sts.id_image ());
init (idi, id);
image_type& im (sts.image ());
if (init (im, obj, statement_update))
im.version++;
bool u (false);
binding& imb (sts.update_image_binding ());
if (im.version != sts.update_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_update);
sts.update_image_version (im.version);
imb.version++;
u = true;
}
binding& idb (sts.id_image_binding ());
if (idi.version != sts.update_id_image_version () ||
idb.version == 0)
{
if (idi.version != sts.id_image_version () ||
idb.version == 0)
{
bind (idb.bind, idi);
sts.id_image_version (idi.version);
idb.version++;
}
sts.update_id_image_version (idi.version);
if (!u)
imb.version++;
}
update_statement& st (sts.update_statement ());
if (st.execute () == 0)
throw object_not_persistent ();
callback (db, obj, callback_event::post_update);
pointer_cache_traits::update (db, obj);
}
void access::object_traits_impl< ::models::Agent, id_sqlite >::
erase (database& db, const id_type& id)
{
using namespace sqlite;
ODB_POTENTIALLY_UNUSED (db);
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
id_image_type& i (sts.id_image ());
init (i, id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
if (sts.erase_statement ().execute () != 1)
throw object_not_persistent ();
pointer_cache_traits::erase (db, id);
}
access::object_traits_impl< ::models::Agent, id_sqlite >::pointer_type
access::object_traits_impl< ::models::Agent, id_sqlite >::
find (database& db, const id_type& id)
{
using namespace sqlite;
{
pointer_type p (pointer_cache_traits::find (db, id));
if (!pointer_traits::null_ptr (p))
return p;
}
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (l.locked ())
{
if (!find_ (sts, &id))
return pointer_type ();
}
pointer_type p (
access::object_factory<object_type, pointer_type>::create ());
pointer_traits::guard pg (p);
pointer_cache_traits::insert_guard ig (
pointer_cache_traits::insert (db, id, p));
object_type& obj (pointer_traits::get_ref (p));
if (l.locked ())
{
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
pointer_cache_traits::load (ig.position ());
}
else
sts.delay_load (id, obj, ig.position ());
ig.release ();
pg.release ();
return p;
}
bool access::object_traits_impl< ::models::Agent, id_sqlite >::
find (database& db, const id_type& id, object_type& obj)
{
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
reference_cache_traits::position_type pos (
reference_cache_traits::insert (db, id, obj));
reference_cache_traits::insert_guard ig (pos);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
reference_cache_traits::load (pos);
ig.release ();
return true;
}
bool access::object_traits_impl< ::models::Agent, id_sqlite >::
reload (database& db, object_type& obj)
{
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
const id_type& id (
obj.id);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, true);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
return true;
}
bool access::object_traits_impl< ::models::Agent, id_sqlite >::
find_ (statements_type& sts,
const id_type* id)
{
using namespace sqlite;
id_image_type& i (sts.id_image ());
init (i, *id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
select_statement& st (sts.find_statement ());
st.execute ();
auto_result ar (st);
select_statement::result r (st.fetch ());
if (r == select_statement::truncated)
{
if (grow (im, sts.select_image_truncated ()))
im.version++;
if (im.version != sts.select_image_version ())
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
st.refetch ();
}
}
return r != select_statement::no_data;
}
result< access::object_traits_impl< ::models::Agent, id_sqlite >::object_type >
access::object_traits_impl< ::models::Agent, id_sqlite >::
query (database&, const query_base_type& q)
{
using namespace sqlite;
using odb::details::shared;
using odb::details::shared_ptr;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
std::string text (query_statement);
if (!q.empty ())
{
text += " ";
text += q.clause ();
}
q.init_parameters ();
shared_ptr<select_statement> st (
new (shared) select_statement (
conn,
text,
false,
true,
q.parameters_binding (),
imb));
st->execute ();
shared_ptr< odb::object_result_impl<object_type> > r (
new (shared) sqlite::object_result_impl<object_type> (
q, st, sts, 0));
return result<object_type> (r);
}
unsigned long long access::object_traits_impl< ::models::Agent, id_sqlite >::
erase_query (database&, const query_base_type& q)
{
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
std::string text (erase_query_statement);
if (!q.empty ())
{
text += ' ';
text += q.clause ();
}
q.init_parameters ();
delete_statement st (
conn,
text,
q.parameters_binding ());
return st.execute ();
}
}
#include <odb/post.hxx>
@@ -0,0 +1,342 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef AGENT_ODB_HXX
#define AGENT_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "Agent.h"
#include <memory>
#include <cstddef>
#include <utility>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// Agent
//
template <>
struct class_traits< ::models::Agent >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::models::Agent >
{
public:
typedef ::models::Agent object_type;
typedef ::models::Agent* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;
static const bool polymorphic = false;
typedef ::std::string id_type;
static const bool auto_id = false;
static const bool abstract = false;
static id_type
id (const object_type&);
typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;
typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;
static void
callback (database&, object_type&, callback_event);
static void
callback (database&, const object_type&, callback_event);
};
}
#include <odb/details/buffer.hxx>
#include <odb/sqlite/version.hxx>
#include <odb/sqlite/forward.hxx>
#include <odb/sqlite/binding.hxx>
#include <odb/sqlite/sqlite-types.hxx>
#include <odb/sqlite/query.hxx>
namespace odb
{
// Agent
//
template <typename A>
struct query_columns< ::models::Agent, id_sqlite, A >
{
// id
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
id_type_;
static const id_type_ id;
// role
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
role_type_;
static const role_type_ role;
// persistent
//
typedef
sqlite::query_column<
sqlite::value_traits<
bool,
sqlite::id_integer >::query_type,
sqlite::id_integer >
persistent_type_;
static const persistent_type_ persistent;
// displayName
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
displayName_type_;
static const displayName_type_ displayName;
// trustScore
//
typedef
sqlite::query_column<
sqlite::value_traits<
::int32_t,
sqlite::id_integer >::query_type,
sqlite::id_integer >
trustScore_type_;
static const trustScore_type_ trustScore;
};
template <typename A>
const typename query_columns< ::models::Agent, id_sqlite, A >::id_type_
query_columns< ::models::Agent, id_sqlite, A >::
id (A::table_name, "\"id\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_sqlite, A >::role_type_
query_columns< ::models::Agent, id_sqlite, A >::
role (A::table_name, "\"role\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_sqlite, A >::persistent_type_
query_columns< ::models::Agent, id_sqlite, A >::
persistent (A::table_name, "\"persistent\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_sqlite, A >::displayName_type_
query_columns< ::models::Agent, id_sqlite, A >::
displayName (A::table_name, "\"displayName\"", 0);
template <typename A>
const typename query_columns< ::models::Agent, id_sqlite, A >::trustScore_type_
query_columns< ::models::Agent, id_sqlite, A >::
trustScore (A::table_name, "\"trustScore\"", 0);
template <typename A>
struct pointer_query_columns< ::models::Agent, id_sqlite, A >:
query_columns< ::models::Agent, id_sqlite, A >
{
};
template <>
class access::object_traits_impl< ::models::Agent, id_sqlite >:
public access::object_traits< ::models::Agent >
{
public:
struct id_image_type
{
details::buffer id_value;
std::size_t id_size;
bool id_null;
std::size_t version;
};
struct image_type
{
// id
//
details::buffer id_value;
std::size_t id_size;
bool id_null;
// role
//
details::buffer role_value;
std::size_t role_size;
bool role_null;
// persistent
//
long long persistent_value;
bool persistent_null;
// displayName
//
details::buffer displayName_value;
std::size_t displayName_size;
bool displayName_null;
// trustScore
//
long long trustScore_value;
bool trustScore_null;
std::size_t version;
};
struct extra_statement_cache_type;
using object_traits<object_type>::id;
static id_type
id (const image_type&);
static bool
grow (image_type&,
bool*);
static void
bind (sqlite::bind*,
image_type&,
sqlite::statement_kind);
static void
bind (sqlite::bind*, id_image_type&);
static bool
init (image_type&,
const object_type&,
sqlite::statement_kind);
static void
init (object_type&,
const image_type&,
database*);
static void
init (id_image_type&, const id_type&);
typedef sqlite::object_statements<object_type> statements_type;
typedef sqlite::query_base query_base_type;
static const std::size_t column_count = 5UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 0UL;
static const std::size_t managed_optimistic_column_count = 0UL;
static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;
static const bool versioned = false;
static const char persist_statement[];
static const char find_statement[];
static const char update_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];
static const char table_name[];
static void
persist (database&, const object_type&);
static pointer_type
find (database&, const id_type&);
static bool
find (database&, const id_type&, object_type&);
static bool
reload (database&, object_type&);
static void
update (database&, const object_type&);
static void
erase (database&, const id_type&);
static void
erase (database&, const object_type&);
static result<object_type>
query (database&, const query_base_type&);
static unsigned long long
erase_query (database&, const query_base_type&);
public:
static bool
find_ (statements_type&,
const id_type*);
static void
load_ (statements_type&,
object_type&,
bool reload);
};
template <>
class access::object_traits_impl< ::models::Agent, id_common >:
public access::object_traits_impl< ::models::Agent, id_sqlite >
{
};
// Agent
//
}
#include "Agent-odb.ixx"
#include <odb/post.hxx>
#endif // AGENT_ODB_HXX
@@ -0,0 +1,61 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
namespace odb
{
// Agent
//
inline
access::object_traits< ::models::Agent >::id_type
access::object_traits< ::models::Agent >::
id (const object_type& o)
{
return o.id;
}
inline
void access::object_traits< ::models::Agent >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
inline
void access::object_traits< ::models::Agent >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}
namespace odb
{
// Agent
//
inline
void access::object_traits_impl< ::models::Agent, id_sqlite >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}
inline
void access::object_traits_impl< ::models::Agent, id_sqlite >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}
@@ -0,0 +1,25 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
DROP TABLE IF EXISTS "Agent";
CREATE TABLE IF NOT EXISTS "schema_version" (
"name" TEXT NOT NULL PRIMARY KEY,
"version" INTEGER NOT NULL,
"migration" INTEGER NOT NULL);
DELETE FROM "schema_version"
WHERE "name" = '';
CREATE TABLE "Agent" (
"id" TEXT NOT NULL PRIMARY KEY,
"role" TEXT NOT NULL,
"persistent" INTEGER NOT NULL,
"displayName" TEXT NOT NULL,
"trustScore" INTEGER NOT NULL);
INSERT OR IGNORE INTO "schema_version" (
"name", "version", "migration")
VALUES ('', 2, 0);
@@ -0,0 +1,8 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
UPDATE "schema_version"
SET "migration" = 0
WHERE "name" = '';
@@ -0,0 +1,13 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
CREATE TABLE "GovernmentAddress" (
"id" TEXT NOT NULL PRIMARY KEY,
"addressLabel" TEXT NOT NULL,
"regionLookupKey" TEXT NOT NULL);
UPDATE "schema_version"
SET "version" = 2, "migration" = 1
WHERE "name" = '';
@@ -0,0 +1,725 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#include <odb/pre.hxx>
#include "GovernmentAddress-odb.hxx"
#include <cassert>
#include <cstring> // std::memcpy
#include <odb/sqlite/traits.hxx>
#include <odb/sqlite/database.hxx>
#include <odb/sqlite/transaction.hxx>
#include <odb/sqlite/connection.hxx>
#include <odb/sqlite/statement.hxx>
#include <odb/sqlite/statement-cache.hxx>
#include <odb/sqlite/simple-object-statements.hxx>
#include <odb/sqlite/container-statements.hxx>
#include <odb/sqlite/exceptions.hxx>
#include <odb/sqlite/simple-object-result.hxx>
namespace odb
{
// GovernmentAddress
//
struct access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::extra_statement_cache_type
{
extra_statement_cache_type (
sqlite::connection&,
image_type&,
id_image_type&,
sqlite::binding&,
sqlite::binding&)
{
}
};
access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::id_type
access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
id (const image_type& i)
{
sqlite::database* db (0);
ODB_POTENTIALLY_UNUSED (db);
id_type id;
{
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
id,
i.id_value,
i.id_size,
i.id_null);
}
return id;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
grow (image_type& i,
bool* t)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (t);
bool grew (false);
// id
//
if (t[0UL])
{
i.id_value.capacity (i.id_size);
grew = true;
}
// addressLabel
//
if (t[1UL])
{
i.addressLabel_value.capacity (i.addressLabel_size);
grew = true;
}
// regionLookupKey
//
if (t[2UL])
{
i.regionLookupKey_value.capacity (i.regionLookupKey_size);
grew = true;
}
return grew;
}
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
bind (sqlite::bind* b,
image_type& i,
sqlite::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (sk);
using namespace sqlite;
std::size_t n (0);
// id
//
if (sk != statement_update)
{
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.id_value.data ();
b[n].size = &i.id_size;
b[n].capacity = i.id_value.capacity ();
b[n].is_null = &i.id_null;
n++;
}
// addressLabel
//
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.addressLabel_value.data ();
b[n].size = &i.addressLabel_size;
b[n].capacity = i.addressLabel_value.capacity ();
b[n].is_null = &i.addressLabel_null;
n++;
// regionLookupKey
//
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.regionLookupKey_value.data ();
b[n].size = &i.regionLookupKey_size;
b[n].capacity = i.regionLookupKey_value.capacity ();
b[n].is_null = &i.regionLookupKey_null;
n++;
}
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
bind (sqlite::bind* b, id_image_type& i)
{
std::size_t n (0);
b[n].type = sqlite::image_traits<
::std::string,
sqlite::id_text>::bind_value;
b[n].buffer = i.id_value.data ();
b[n].size = &i.id_size;
b[n].capacity = i.id_value.capacity ();
b[n].is_null = &i.id_null;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
init (image_type& i,
const object_type& o,
sqlite::statement_kind sk)
{
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (sk);
using namespace sqlite;
bool grew (false);
// id
//
if (sk == statement_insert)
{
::std::string const& v =
o.id;
bool is_null (false);
std::size_t cap (i.id_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.id_value,
i.id_size,
is_null,
v);
i.id_null = is_null;
grew = grew || (cap != i.id_value.capacity ());
}
// addressLabel
//
{
::std::string const& v =
o.addressLabel;
bool is_null (false);
std::size_t cap (i.addressLabel_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.addressLabel_value,
i.addressLabel_size,
is_null,
v);
i.addressLabel_null = is_null;
grew = grew || (cap != i.addressLabel_value.capacity ());
}
// regionLookupKey
//
{
::std::string const& v =
o.regionLookupKey;
bool is_null (false);
std::size_t cap (i.regionLookupKey_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.regionLookupKey_value,
i.regionLookupKey_size,
is_null,
v);
i.regionLookupKey_null = is_null;
grew = grew || (cap != i.regionLookupKey_value.capacity ());
}
return grew;
}
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
init (object_type& o,
const image_type& i,
database* db)
{
ODB_POTENTIALLY_UNUSED (o);
ODB_POTENTIALLY_UNUSED (i);
ODB_POTENTIALLY_UNUSED (db);
// id
//
{
::std::string& v =
o.id;
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
v,
i.id_value,
i.id_size,
i.id_null);
}
// addressLabel
//
{
::std::string& v =
o.addressLabel;
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
v,
i.addressLabel_value,
i.addressLabel_size,
i.addressLabel_null);
}
// regionLookupKey
//
{
::std::string& v =
o.regionLookupKey;
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_value (
v,
i.regionLookupKey_value,
i.regionLookupKey_size,
i.regionLookupKey_null);
}
}
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
init (id_image_type& i, const id_type& id)
{
bool grew (false);
{
bool is_null (false);
std::size_t cap (i.id_value.capacity ());
sqlite::value_traits<
::std::string,
sqlite::id_text >::set_image (
i.id_value,
i.id_size,
is_null,
id);
i.id_null = is_null;
grew = grew || (cap != i.id_value.capacity ());
}
if (grew)
i.version++;
}
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::persist_statement[] =
"INSERT INTO \"GovernmentAddress\" "
"(\"id\", "
"\"addressLabel\", "
"\"regionLookupKey\") "
"VALUES "
"(?, ?, ?)";
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::find_statement[] =
"SELECT "
"\"GovernmentAddress\".\"id\", "
"\"GovernmentAddress\".\"addressLabel\", "
"\"GovernmentAddress\".\"regionLookupKey\" "
"FROM \"GovernmentAddress\" "
"WHERE \"GovernmentAddress\".\"id\"=?";
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::update_statement[] =
"UPDATE \"GovernmentAddress\" "
"SET "
"\"addressLabel\"=?, "
"\"regionLookupKey\"=? "
"WHERE \"id\"=?";
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::erase_statement[] =
"DELETE FROM \"GovernmentAddress\" "
"WHERE \"id\"=?";
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::query_statement[] =
"SELECT "
"\"GovernmentAddress\".\"id\", "
"\"GovernmentAddress\".\"addressLabel\", "
"\"GovernmentAddress\".\"regionLookupKey\" "
"FROM \"GovernmentAddress\"";
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::erase_query_statement[] =
"DELETE FROM \"GovernmentAddress\"";
const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::table_name[] =
"\"GovernmentAddress\"";
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
persist (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
callback (db,
obj,
callback_event::pre_persist);
image_type& im (sts.image ());
binding& imb (sts.insert_image_binding ());
if (init (im, obj, statement_insert))
im.version++;
if (im.version != sts.insert_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_insert);
sts.insert_image_version (im.version);
imb.version++;
}
insert_statement& st (sts.persist_statement ());
if (!st.execute ())
throw object_already_persistent ();
callback (db,
obj,
callback_event::post_persist);
}
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
update (database& db, const object_type& obj)
{
ODB_POTENTIALLY_UNUSED (db);
using namespace sqlite;
using sqlite::update_statement;
callback (db, obj, callback_event::pre_update);
sqlite::transaction& tr (sqlite::transaction::current ());
sqlite::connection& conn (tr.connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
const id_type& id (
obj.id);
id_image_type& idi (sts.id_image ());
init (idi, id);
image_type& im (sts.image ());
if (init (im, obj, statement_update))
im.version++;
bool u (false);
binding& imb (sts.update_image_binding ());
if (im.version != sts.update_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_update);
sts.update_image_version (im.version);
imb.version++;
u = true;
}
binding& idb (sts.id_image_binding ());
if (idi.version != sts.update_id_image_version () ||
idb.version == 0)
{
if (idi.version != sts.id_image_version () ||
idb.version == 0)
{
bind (idb.bind, idi);
sts.id_image_version (idi.version);
idb.version++;
}
sts.update_id_image_version (idi.version);
if (!u)
imb.version++;
}
update_statement& st (sts.update_statement ());
if (st.execute () == 0)
throw object_not_persistent ();
callback (db, obj, callback_event::post_update);
pointer_cache_traits::update (db, obj);
}
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
erase (database& db, const id_type& id)
{
using namespace sqlite;
ODB_POTENTIALLY_UNUSED (db);
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
id_image_type& i (sts.id_image ());
init (i, id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
if (sts.erase_statement ().execute () != 1)
throw object_not_persistent ();
pointer_cache_traits::erase (db, id);
}
access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::pointer_type
access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
find (database& db, const id_type& id)
{
using namespace sqlite;
{
pointer_type p (pointer_cache_traits::find (db, id));
if (!pointer_traits::null_ptr (p))
return p;
}
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (l.locked ())
{
if (!find_ (sts, &id))
return pointer_type ();
}
pointer_type p (
access::object_factory<object_type, pointer_type>::create ());
pointer_traits::guard pg (p);
pointer_cache_traits::insert_guard ig (
pointer_cache_traits::insert (db, id, p));
object_type& obj (pointer_traits::get_ref (p));
if (l.locked ())
{
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
pointer_cache_traits::load (ig.position ());
}
else
sts.delay_load (id, obj, ig.position ());
ig.release ();
pg.release ();
return p;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
find (database& db, const id_type& id, object_type& obj)
{
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
reference_cache_traits::position_type pos (
reference_cache_traits::insert (db, id, obj));
reference_cache_traits::insert_guard ig (pos);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, false);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
reference_cache_traits::load (pos);
ig.release ();
return true;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
reload (database& db, object_type& obj)
{
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
statements_type::auto_lock l (sts);
const id_type& id (
obj.id);
if (!find_ (sts, &id))
return false;
select_statement& st (sts.find_statement ());
ODB_POTENTIALLY_UNUSED (st);
callback (db, obj, callback_event::pre_load);
init (obj, sts.image (), &db);
load_ (sts, obj, true);
sts.load_delayed (0);
l.unlock ();
callback (db, obj, callback_event::post_load);
return true;
}
bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
find_ (statements_type& sts,
const id_type* id)
{
using namespace sqlite;
id_image_type& i (sts.id_image ());
init (i, *id);
binding& idb (sts.id_image_binding ());
if (i.version != sts.id_image_version () || idb.version == 0)
{
bind (idb.bind, i);
sts.id_image_version (i.version);
idb.version++;
}
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
select_statement& st (sts.find_statement ());
st.execute ();
auto_result ar (st);
select_statement::result r (st.fetch ());
if (r == select_statement::truncated)
{
if (grow (im, sts.select_image_truncated ()))
im.version++;
if (im.version != sts.select_image_version ())
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
st.refetch ();
}
}
return r != select_statement::no_data;
}
result< access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::object_type >
access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
query (database&, const query_base_type& q)
{
using namespace sqlite;
using odb::details::shared;
using odb::details::shared_ptr;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
statements_type& sts (
conn.statement_cache ().find_object<object_type> ());
image_type& im (sts.image ());
binding& imb (sts.select_image_binding ());
if (im.version != sts.select_image_version () ||
imb.version == 0)
{
bind (imb.bind, im, statement_select);
sts.select_image_version (im.version);
imb.version++;
}
std::string text (query_statement);
if (!q.empty ())
{
text += " ";
text += q.clause ();
}
q.init_parameters ();
shared_ptr<select_statement> st (
new (shared) select_statement (
conn,
text,
false,
true,
q.parameters_binding (),
imb));
st->execute ();
shared_ptr< odb::object_result_impl<object_type> > r (
new (shared) sqlite::object_result_impl<object_type> (
q, st, sts, 0));
return result<object_type> (r);
}
unsigned long long access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
erase_query (database&, const query_base_type& q)
{
using namespace sqlite;
sqlite::connection& conn (
sqlite::transaction::current ().connection ());
std::string text (erase_query_statement);
if (!q.empty ())
{
text += ' ';
text += q.clause ();
}
q.init_parameters ();
delete_statement st (
conn,
text,
q.parameters_binding ());
return st.execute ();
}
}
#include <odb/post.hxx>
@@ -0,0 +1,298 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef GOVERNMENT_ADDRESS_ODB_HXX
#define GOVERNMENT_ADDRESS_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "GovernmentAddress.h"
#include <memory>
#include <cstddef>
#include <utility>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// GovernmentAddress
//
template <>
struct class_traits< ::models::GovernmentAddress >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::models::GovernmentAddress >
{
public:
typedef ::models::GovernmentAddress object_type;
typedef ::models::GovernmentAddress* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;
static const bool polymorphic = false;
typedef ::std::string id_type;
static const bool auto_id = false;
static const bool abstract = false;
static id_type
id (const object_type&);
typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;
typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;
static void
callback (database&, object_type&, callback_event);
static void
callback (database&, const object_type&, callback_event);
};
}
#include <odb/details/buffer.hxx>
#include <odb/sqlite/version.hxx>
#include <odb/sqlite/forward.hxx>
#include <odb/sqlite/binding.hxx>
#include <odb/sqlite/sqlite-types.hxx>
#include <odb/sqlite/query.hxx>
namespace odb
{
// GovernmentAddress
//
template <typename A>
struct query_columns< ::models::GovernmentAddress, id_sqlite, A >
{
// id
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
id_type_;
static const id_type_ id;
// addressLabel
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
addressLabel_type_;
static const addressLabel_type_ addressLabel;
// regionLookupKey
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
regionLookupKey_type_;
static const regionLookupKey_type_ regionLookupKey;
};
template <typename A>
const typename query_columns< ::models::GovernmentAddress, id_sqlite, A >::id_type_
query_columns< ::models::GovernmentAddress, id_sqlite, A >::
id (A::table_name, "\"id\"", 0);
template <typename A>
const typename query_columns< ::models::GovernmentAddress, id_sqlite, A >::addressLabel_type_
query_columns< ::models::GovernmentAddress, id_sqlite, A >::
addressLabel (A::table_name, "\"addressLabel\"", 0);
template <typename A>
const typename query_columns< ::models::GovernmentAddress, id_sqlite, A >::regionLookupKey_type_
query_columns< ::models::GovernmentAddress, id_sqlite, A >::
regionLookupKey (A::table_name, "\"regionLookupKey\"", 0);
template <typename A>
struct pointer_query_columns< ::models::GovernmentAddress, id_sqlite, A >:
query_columns< ::models::GovernmentAddress, id_sqlite, A >
{
};
template <>
class access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:
public access::object_traits< ::models::GovernmentAddress >
{
public:
struct id_image_type
{
details::buffer id_value;
std::size_t id_size;
bool id_null;
std::size_t version;
};
struct image_type
{
// id
//
details::buffer id_value;
std::size_t id_size;
bool id_null;
// addressLabel
//
details::buffer addressLabel_value;
std::size_t addressLabel_size;
bool addressLabel_null;
// regionLookupKey
//
details::buffer regionLookupKey_value;
std::size_t regionLookupKey_size;
bool regionLookupKey_null;
std::size_t version;
};
struct extra_statement_cache_type;
using object_traits<object_type>::id;
static id_type
id (const image_type&);
static bool
grow (image_type&,
bool*);
static void
bind (sqlite::bind*,
image_type&,
sqlite::statement_kind);
static void
bind (sqlite::bind*, id_image_type&);
static bool
init (image_type&,
const object_type&,
sqlite::statement_kind);
static void
init (object_type&,
const image_type&,
database*);
static void
init (id_image_type&, const id_type&);
typedef sqlite::object_statements<object_type> statements_type;
typedef sqlite::query_base query_base_type;
static const std::size_t column_count = 3UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 0UL;
static const std::size_t managed_optimistic_column_count = 0UL;
static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;
static const bool versioned = false;
static const char persist_statement[];
static const char find_statement[];
static const char update_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];
static const char table_name[];
static void
persist (database&, const object_type&);
static pointer_type
find (database&, const id_type&);
static bool
find (database&, const id_type&, object_type&);
static bool
reload (database&, object_type&);
static void
update (database&, const object_type&);
static void
erase (database&, const id_type&);
static void
erase (database&, const object_type&);
static result<object_type>
query (database&, const query_base_type&);
static unsigned long long
erase_query (database&, const query_base_type&);
public:
static bool
find_ (statements_type&,
const id_type*);
static void
load_ (statements_type&,
object_type&,
bool reload);
};
template <>
class access::object_traits_impl< ::models::GovernmentAddress, id_common >:
public access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >
{
};
// GovernmentAddress
//
}
#include "GovernmentAddress-odb.ixx"
#include <odb/post.hxx>
#endif // GOVERNMENT_ADDRESS_ODB_HXX
@@ -0,0 +1,61 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
namespace odb
{
// GovernmentAddress
//
inline
access::object_traits< ::models::GovernmentAddress >::id_type
access::object_traits< ::models::GovernmentAddress >::
id (const object_type& o)
{
return o.id;
}
inline
void access::object_traits< ::models::GovernmentAddress >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
inline
void access::object_traits< ::models::GovernmentAddress >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}
namespace odb
{
// GovernmentAddress
//
inline
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}
inline
void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}
@@ -0,0 +1,23 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
DROP TABLE IF EXISTS "GovernmentAddress";
CREATE TABLE IF NOT EXISTS "schema_version" (
"name" TEXT NOT NULL PRIMARY KEY,
"version" INTEGER NOT NULL,
"migration" INTEGER NOT NULL);
DELETE FROM "schema_version"
WHERE "name" = '';
CREATE TABLE "GovernmentAddress" (
"id" TEXT NOT NULL PRIMARY KEY,
"addressLabel" TEXT NOT NULL,
"regionLookupKey" TEXT NOT NULL);
INSERT OR IGNORE INTO "schema_version" (
"name", "version", "migration")
VALUES ('', 2, 0);
@@ -0,0 +1,8 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
UPDATE "schema_version"
SET "migration" = 0
WHERE "name" = '';
@@ -0,0 +1,22 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
CREATE TABLE "TripAttemptResult" (
"id" TEXT NOT NULL PRIMARY KEY,
"result" TEXT NOT NULL,
"retryReason" TEXT NOT NULL,
"governmentSuspensionReason" TEXT NOT NULL,
"governmentTerminationReason" TEXT NOT NULL,
"complianceSuspensionReason" TEXT NOT NULL,
"complianceTerminationReason" TEXT NOT NULL,
"policySuspensionReason" TEXT NOT NULL,
"policyTerminationReason" TEXT NOT NULL,
"cancelationReason" TEXT NOT NULL,
"failureReason" TEXT NOT NULL,
"details" TEXT NOT NULL);
UPDATE "schema_version"
SET "version" = 2, "migration" = 1
WHERE "name" = '';
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,505 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef TRIP_ATTEMPT_RESULT_ODB_HXX
#define TRIP_ATTEMPT_RESULT_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20400UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "TripAttemptResult.h"
#include <memory>
#include <cstddef>
#include <utility>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// TripAttemptResult
//
template <>
struct class_traits< ::models::TripAttemptResult >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::models::TripAttemptResult >
{
public:
typedef ::models::TripAttemptResult object_type;
typedef ::models::TripAttemptResult* pointer_type;
typedef odb::pointer_traits<pointer_type> pointer_traits;
static const bool polymorphic = false;
typedef ::std::string id_type;
static const bool auto_id = false;
static const bool abstract = false;
static id_type
id (const object_type&);
typedef
no_op_pointer_cache_traits<pointer_type>
pointer_cache_traits;
typedef
no_op_reference_cache_traits<object_type>
reference_cache_traits;
static void
callback (database&, object_type&, callback_event);
static void
callback (database&, const object_type&, callback_event);
};
}
#include <odb/details/buffer.hxx>
#include <odb/sqlite/version.hxx>
#include <odb/sqlite/forward.hxx>
#include <odb/sqlite/binding.hxx>
#include <odb/sqlite/sqlite-types.hxx>
#include <odb/sqlite/query.hxx>
namespace odb
{
// TripAttemptResult
//
template <typename A>
struct query_columns< ::models::TripAttemptResult, id_sqlite, A >
{
// id
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
id_type_;
static const id_type_ id;
// result
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
result_type_;
static const result_type_ result;
// retryReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
retryReason_type_;
static const retryReason_type_ retryReason;
// governmentSuspensionReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
governmentSuspensionReason_type_;
static const governmentSuspensionReason_type_ governmentSuspensionReason;
// governmentTerminationReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
governmentTerminationReason_type_;
static const governmentTerminationReason_type_ governmentTerminationReason;
// complianceSuspensionReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
complianceSuspensionReason_type_;
static const complianceSuspensionReason_type_ complianceSuspensionReason;
// complianceTerminationReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
complianceTerminationReason_type_;
static const complianceTerminationReason_type_ complianceTerminationReason;
// policySuspensionReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
policySuspensionReason_type_;
static const policySuspensionReason_type_ policySuspensionReason;
// policyTerminationReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
policyTerminationReason_type_;
static const policyTerminationReason_type_ policyTerminationReason;
// cancelationReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
cancelationReason_type_;
static const cancelationReason_type_ cancelationReason;
// failureReason
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
failureReason_type_;
static const failureReason_type_ failureReason;
// details
//
typedef
sqlite::query_column<
sqlite::value_traits<
::std::string,
sqlite::id_text >::query_type,
sqlite::id_text >
details_type_;
static const details_type_ details;
};
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::id_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
id (A::table_name, "\"id\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::result_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
result (A::table_name, "\"result\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::retryReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
retryReason (A::table_name, "\"retryReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::governmentSuspensionReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
governmentSuspensionReason (A::table_name, "\"governmentSuspensionReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::governmentTerminationReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
governmentTerminationReason (A::table_name, "\"governmentTerminationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::complianceSuspensionReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
complianceSuspensionReason (A::table_name, "\"complianceSuspensionReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::complianceTerminationReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
complianceTerminationReason (A::table_name, "\"complianceTerminationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::policySuspensionReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
policySuspensionReason (A::table_name, "\"policySuspensionReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::policyTerminationReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
policyTerminationReason (A::table_name, "\"policyTerminationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::cancelationReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
cancelationReason (A::table_name, "\"cancelationReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::failureReason_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
failureReason (A::table_name, "\"failureReason\"", 0);
template <typename A>
const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::details_type_
query_columns< ::models::TripAttemptResult, id_sqlite, A >::
details (A::table_name, "\"details\"", 0);
template <typename A>
struct pointer_query_columns< ::models::TripAttemptResult, id_sqlite, A >:
query_columns< ::models::TripAttemptResult, id_sqlite, A >
{
};
template <>
class access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:
public access::object_traits< ::models::TripAttemptResult >
{
public:
struct id_image_type
{
details::buffer id_value;
std::size_t id_size;
bool id_null;
std::size_t version;
};
struct image_type
{
// id
//
details::buffer id_value;
std::size_t id_size;
bool id_null;
// result
//
details::buffer result_value;
std::size_t result_size;
bool result_null;
// retryReason
//
details::buffer retryReason_value;
std::size_t retryReason_size;
bool retryReason_null;
// governmentSuspensionReason
//
details::buffer governmentSuspensionReason_value;
std::size_t governmentSuspensionReason_size;
bool governmentSuspensionReason_null;
// governmentTerminationReason
//
details::buffer governmentTerminationReason_value;
std::size_t governmentTerminationReason_size;
bool governmentTerminationReason_null;
// complianceSuspensionReason
//
details::buffer complianceSuspensionReason_value;
std::size_t complianceSuspensionReason_size;
bool complianceSuspensionReason_null;
// complianceTerminationReason
//
details::buffer complianceTerminationReason_value;
std::size_t complianceTerminationReason_size;
bool complianceTerminationReason_null;
// policySuspensionReason
//
details::buffer policySuspensionReason_value;
std::size_t policySuspensionReason_size;
bool policySuspensionReason_null;
// policyTerminationReason
//
details::buffer policyTerminationReason_value;
std::size_t policyTerminationReason_size;
bool policyTerminationReason_null;
// cancelationReason
//
details::buffer cancelationReason_value;
std::size_t cancelationReason_size;
bool cancelationReason_null;
// failureReason
//
details::buffer failureReason_value;
std::size_t failureReason_size;
bool failureReason_null;
// details
//
details::buffer details_value;
std::size_t details_size;
bool details_null;
std::size_t version;
};
struct extra_statement_cache_type;
using object_traits<object_type>::id;
static id_type
id (const image_type&);
static bool
grow (image_type&,
bool*);
static void
bind (sqlite::bind*,
image_type&,
sqlite::statement_kind);
static void
bind (sqlite::bind*, id_image_type&);
static bool
init (image_type&,
const object_type&,
sqlite::statement_kind);
static void
init (object_type&,
const image_type&,
database*);
static void
init (id_image_type&, const id_type&);
typedef sqlite::object_statements<object_type> statements_type;
typedef sqlite::query_base query_base_type;
static const std::size_t column_count = 12UL;
static const std::size_t id_column_count = 1UL;
static const std::size_t inverse_column_count = 0UL;
static const std::size_t readonly_column_count = 0UL;
static const std::size_t managed_optimistic_column_count = 0UL;
static const std::size_t separate_load_column_count = 0UL;
static const std::size_t separate_update_column_count = 0UL;
static const bool versioned = false;
static const char persist_statement[];
static const char find_statement[];
static const char update_statement[];
static const char erase_statement[];
static const char query_statement[];
static const char erase_query_statement[];
static const char table_name[];
static void
persist (database&, const object_type&);
static pointer_type
find (database&, const id_type&);
static bool
find (database&, const id_type&, object_type&);
static bool
reload (database&, object_type&);
static void
update (database&, const object_type&);
static void
erase (database&, const id_type&);
static void
erase (database&, const object_type&);
static result<object_type>
query (database&, const query_base_type&);
static unsigned long long
erase_query (database&, const query_base_type&);
public:
static bool
find_ (statements_type&,
const id_type*);
static void
load_ (statements_type&,
object_type&,
bool reload);
};
template <>
class access::object_traits_impl< ::models::TripAttemptResult, id_common >:
public access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >
{
};
// TripAttemptResult
//
}
#include "TripAttemptResult-odb.ixx"
#include <odb/post.hxx>
#endif // TRIP_ATTEMPT_RESULT_ODB_HXX
@@ -0,0 +1,61 @@
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
namespace odb
{
// TripAttemptResult
//
inline
access::object_traits< ::models::TripAttemptResult >::id_type
access::object_traits< ::models::TripAttemptResult >::
id (const object_type& o)
{
return o.id;
}
inline
void access::object_traits< ::models::TripAttemptResult >::
callback (database& db, object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
inline
void access::object_traits< ::models::TripAttemptResult >::
callback (database& db, const object_type& x, callback_event e)
{
ODB_POTENTIALLY_UNUSED (db);
ODB_POTENTIALLY_UNUSED (x);
ODB_POTENTIALLY_UNUSED (e);
}
}
namespace odb
{
// TripAttemptResult
//
inline
void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::
erase (database& db, const object_type& obj)
{
callback (db, obj, callback_event::pre_erase);
erase (db, id (obj));
callback (db, obj, callback_event::post_erase);
}
inline
void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::
load_ (statements_type& sts,
object_type& obj,
bool)
{
ODB_POTENTIALLY_UNUSED (sts);
ODB_POTENTIALLY_UNUSED (obj);
}
}
@@ -0,0 +1,32 @@
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
DROP TABLE IF EXISTS "TripAttemptResult";
CREATE TABLE IF NOT EXISTS "schema_version" (
"name" TEXT NOT NULL PRIMARY KEY,
"version" INTEGER NOT NULL,
"migration" INTEGER NOT NULL);
DELETE FROM "schema_version"
WHERE "name" = '';
CREATE TABLE "TripAttemptResult" (
"id" TEXT NOT NULL PRIMARY KEY,
"result" TEXT NOT NULL,
"retryReason" TEXT NOT NULL,
"governmentSuspensionReason" TEXT NOT NULL,
"governmentTerminationReason" TEXT NOT NULL,
"complianceSuspensionReason" TEXT NOT NULL,
"complianceTerminationReason" TEXT NOT NULL,
"policySuspensionReason" TEXT NOT NULL,
"policyTerminationReason" TEXT NOT NULL,
"cancelationReason" TEXT NOT NULL,
"failureReason" TEXT NOT NULL,
"details" TEXT NOT NULL);
INSERT OR IGNORE INTO "schema_version" (
"name", "version", "migration")
VALUES ('', 2, 0);
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
@@ -0,0 +1,10 @@
.openapi-generator-ignore
docs/Agent.md
docs/GovernmentAddress.md
docs/TripAttemptResult.md
index.ts
models/Agent.ts
models/GovernmentAddress.ts
models/TripAttemptResult.ts
models/index.ts
runtime.ts
@@ -0,0 +1 @@
7.20.0
@@ -0,0 +1,42 @@
# Agent
## Properties
Name | Type
------------ | -------------
`id` | string
`role` | string
`persistent` | boolean
`displayName` | string
`trustScore` | number
## Example
```typescript
import type { Agent } from ''
// TODO: Update the object below with actual values
const example = {
"id": null,
"role": null,
"persistent": null,
"displayName": null,
"trustScore": null,
} satisfies Agent
console.log(example)
// Convert the instance to a JSON string
const exampleJSON: string = JSON.stringify(example)
console.log(exampleJSON)
// Parse the JSON string back to an object
const exampleParsed = JSON.parse(exampleJSON) as Agent
console.log(exampleParsed)
```
[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)
@@ -0,0 +1,38 @@
# GovernmentAddress
## Properties
Name | Type
------------ | -------------
`id` | string
`addressLabel` | string
`regionLookupKey` | string
## Example
```typescript
import type { GovernmentAddress } from ''
// TODO: Update the object below with actual values
const example = {
"id": null,
"addressLabel": null,
"regionLookupKey": null,
} satisfies GovernmentAddress
console.log(example)
// Convert the instance to a JSON string
const exampleJSON: string = JSON.stringify(example)
console.log(exampleJSON)
// Parse the JSON string back to an object
const exampleParsed = JSON.parse(exampleJSON) as GovernmentAddress
console.log(exampleParsed)
```
[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)

Some files were not shown because too many files have changed in this diff Show More