Adapter for PostgreSQL servers, built on the pg binary module (gmsv_pg). It is used
when the database settings name the 'pg' or 'postgresql' adapter. Queries run
asynchronously unless the adapter is in sync mode, bind parameters are numbered ($1,
$2 and so on), and insert queries get the id of the new row through RETURNING id.
Schema changes can be rolled back, so migrations run in a transaction. It is the only
adapter that flux db:create can create the database for.
Summary
Methods
Methods
ActiveRecord.Adapters.Pg:append_query_string(query, query_string, query_type)
shared packages/active_record/lib/adapters/pg.lua:225Appends 'RETURNING id' to insert queries, so that the id of the new row is passed
to the query callback. Queries into tables without an id column set without_id on
the query to go without it.
Parameters
- query ActiveRecord::Query
- query_string String generated SQL
- query_type String lowercase query type
Returns
- String the extended SQL for 'insert' queries, nil for other query types
ActiveRecord.Adapters.Pg:connect(config, on_connected)
shared packages/active_record/lib/adapters/pg.lua:50Connects to a PostgreSQL server through the 'pg' module and sets the connection encoding. Calls #on_connection_failed if the connection fails.
Parameters
- config Map database settings: host, user, password, database, port (5432 if omitted) and encoding ('UTF8' if omitted)
- on_connected Function optional, defaults to
nilcalled with the adapter once the connection is ready
ActiveRecord.Adapters.Pg:create_column(query, column, _args, _obj, type, _def)
shared packages/active_record/lib/adapters/pg.lua:212Makes the column the primary key of the table when a 'primary_key' column is created.
Parameters
- query ActiveRecord::Query query the column was added to
- column String column name
- _args Map unused
- _obj ActiveRecord::Query unused
- type String abstract column type
- _def String unused
Closes the PostgreSQL connection, if there is one.
Escapes a string using the PostgreSQL connection. Requires an established connection.
Parameters
- str String
Returns
- String
Loads the 'pg' binary module.
Checks whether the adapter talks to a PostgreSQL database.
Returns
- Boolean always true
Returns the placeholder of a bind parameter, which is numbered in PostgreSQL.
Parameters
- index Number position of the parameter in the list of bindings, starting at 1
Returns
- String '$1', '$2' and so on
Turns a string into an escaped SQL string literal using the PostgreSQL connection.
Parameters
- str String
Returns
- String
Quotes an identifier such as a table or column name using the PostgreSQL connection.
Parameters
- str String
Returns
- String
ActiveRecord.Adapters.Pg:raw_query(query, callback, query_type, bindings, error_callback)
shared packages/active_record/lib/adapters/pg.lua:132Runs a raw SQL query on the PostgreSQL server. In sync mode this blocks until the query is done; without a connection the query is put into the queue instead.
Parameters
- query String SQL to run
- callback Function optional, defaults to
nilcalled with the result rows (a List of row Maps), the query string, the time the query took in seconds and the bindings - query_type String optional, defaults to
nilunused - bindings List optional, defaults to
nilvalues of $1, $2 and so on in the query. A query that is given bindings has to be a single statement - error_callback Function optional, defaults to
nilcalled with the error text if the query fails
Returns
- Any whatever the callback returns in sync mode, nothing otherwise
ActiveRecord.Adapters.Pg:supports_ddl_transactions()
shared packages/active_record/lib/adapters/pg.lua:41PostgreSQL can roll back schema changes.
Returns
- Boolean always true
ActiveRecord.Adapters.Pg:wait_until(condition, timeout)
shared packages/active_record/lib/adapters/pg.lua:182Waits until a condition is met, delivering the results of the asynchronous queries in the meantime. A synchronous query of the pg module does not wait for the asynchronous queries that are queued before it, and the module delivers their results on the Think hook, which does not run while the server waits. Gives up after the timeout.
Parameters
- condition Function returns true once there is nothing more to wait for
- timeout Number optional, defaults to
10seconds after which to give up
Returns
- Boolean whether the condition is met