class
Prostore::Adapter::Postgres::Adapter
- Prostore::Adapter::Postgres::Adapter
- Prostore::Adapter::Base
- Reference
- Object
Overview
PostgreSQL adapter (ADR-0007).
Mirrors Adapter::SQLite::Adapter but emits Postgres-idiomatic DDL
and supports native ALTER TABLE extensions that SQLite lacks
(ALTER COLUMN SET NOT NULL, ALTER TABLE ADD CONSTRAINT FOREIGN KEY,
CREATE INDEX CONCURRENTLY).
Capability flags below tell the planner which operations the adapter can do natively. ApplyNotNull and AddForeignKey/DropForeignKey honor these and avoid the SQLite table-rebuild dance.
Defined in:
prostore/adapter/postgres/adapter.crConstructors
Instance Method Summary
-
#backup(dest : String) : Nil
Write a point-in-time backup to
dest(an absolute file path). -
#bookkeeping_id_column_def : String
Column DDL fragment for an auto-incrementing BIGINT primary key on the bookkeeping tables.
-
#insert_returning_id(executor : Executor, sql : String, args : Array) : Int64
Array-args overload for callers that build their argument list dynamically (e.g., the record-layer INSERT helper).
-
#insert_returning_id(executor : Executor, sql : String, *args) : Int64
INSERT a row and return its newly-assigned ID.
- #introspect_table(name : String, executor : Executor = @db) : LiveTable
- #introspect_table_names(executor : Executor = @db) : Array(String)
-
#like_operator : String
The operator for a case-insensitive substring match in a WHERE clause.
-
#placeholder(n : Int32) : String
The n-th positional parameter placeholder in the adapter's SQL syntax.
- #quote_ident(name : String) : String
- #quote_string(s : String) : String
- #render_create_index(table : String, index : Schema::Index) : String
- #render_create_table(definition : Schema::Definition, pk_lookup : Hash(String, Array(String))) : String
- #render_create_table(definition : Schema::Definition) : String
-
#session_setup(conn : DB::Connection) : Nil
No per-connection session setup required for Postgres beyond what crystal-pg sets up (utf8 client encoding, etc.).
-
#supports_add_constraint_not_valid? : Bool
Postgres supports ADD CONSTRAINT NOT VALID + VALIDATE CONSTRAINT for online FK addition.
-
#supports_alter_set_not_null? : Bool
Postgres supports native ALTER COLUMN SET NOT NULL.
-
#supports_concurrent_index? : Bool
CREATE INDEX CONCURRENTLY runs outside a transaction and avoids holding an exclusive lock — required for online index creation against large production tables.
Instance methods inherited from class Prostore::Adapter::Base
backup(dest : String) : Nil
backup,
bookkeeping_id_column_def : String
bookkeeping_id_column_def,
db : DB::Database
db,
insert_returning_id(executor : Executor, sql : String, args : Array) : Int64insert_returning_id(executor : Executor, sql : String, *args) : Int64 insert_returning_id, introspect_all(executor : Executor = @db) : Array(LiveTable) introspect_all, introspect_table(name : String, executor : Executor = @db) : LiveTable introspect_table, introspect_table_names(executor : Executor = @db) : Array(String) introspect_table_names, like_operator : String like_operator, placeholder(n : Int32) : String placeholder, placeholders(count : Int32) : String placeholders, quote_ident(name : String) : String quote_ident, quote_string(s : String) : String quote_string, render_create_index(table : String, index : Schema::Index) : String render_create_index, render_create_table(definition : Schema::Definition) : String render_create_table, session_setup(conn : DB::Connection) : Nil session_setup, supports_add_constraint_not_valid? : Bool supports_add_constraint_not_valid?, supports_alter_drop_column? : Bool supports_alter_drop_column?, supports_alter_set_not_null? : Bool supports_alter_set_not_null?, supports_concurrent_index? : Bool supports_concurrent_index?
Constructor methods inherited from class Prostore::Adapter::Base
new(db : DB::Database)
new
Constructor Detail
Instance Method Detail
Write a point-in-time backup to dest (an absolute file path).
SQLite uses VACUUM INTO; PostgreSQL shells out to pg_dump.
Column DDL fragment for an auto-incrementing BIGINT primary key on
the bookkeeping tables. SQLite emits INTEGER PRIMARY KEY AUTOINCREMENT
while Postgres emits BIGSERIAL PRIMARY KEY (or identity). Each
adapter overrides.
Array-args overload for callers that build their argument list dynamically (e.g., the record-layer INSERT helper).
INSERT a row and return its newly-assigned ID. SQLite uses
last_insert_rowid(); Postgres uses RETURNING id. The adapter
encapsulates the difference.
The operator for a case-insensitive substring match in a WHERE
clause. SQLite's LIKE is case-insensitive for ASCII by default;
PostgreSQL exposes ILIKE for the same purpose.
The n-th positional parameter placeholder in the adapter's SQL
syntax. SQLite uses ? (position-implicit). PostgreSQL uses
$1, $2, … (position-explicit). crystal-db does NOT translate
between them, so SQL strings shared by both adapters must build
placeholders via this method.
No per-connection session setup required for Postgres beyond what crystal-pg sets up (utf8 client encoding, etc.).
Postgres supports ADD CONSTRAINT NOT VALID + VALIDATE CONSTRAINT for online FK addition. Same caveat as concurrent_index — the planner can adopt this in a future revision.
CREATE INDEX CONCURRENTLY runs outside a transaction and avoids holding an exclusive lock — required for online index creation against large production tables. The Steps executor consults this flag to skip the transaction wrapper and route through the recovery-aware concurrent path.