Entry point of the query builder. Each of its methods starts an ActiveRecord::Query of one type (select, insert, update, delete, create, change, drop or truncate) on a table; the query is then set up through its own methods and run with ActiveRecord::Query#execute. Models and the schema statements are built on top of it, so it is only needed directly for tables that have no model. The class is used as it is, without creating objects of it.

It also creates and drops the database itself for the flux db:create and flux db:drop tasks, and makes the adapter work off its queue of deferred queries.

Based off mysql from Alex Grist.

Summary

Methods

Starts an ALTER TABLE query.
Starts a CREATE TABLE query.
Starts a DELETE query on a table.
Disconnects the active adapter from the database.
Starts a DROP TABLE query.
Drops the database named in the settings and disconnects the adapter afterward.
Starts an INSERT query on a table.
Starts a SELECT query on a table.
Creates the database named in the settings and disconnects the adapter afterward.
Starts a TRUNCATE TABLE query.
Starts an UPDATE query on a table.

Methods

ActiveRecord.Database:change(table_name)

shared packages/active_record/lib/database/database.lua:95

Starts an ALTER TABLE query. The returned query has a method for every column type of the current adapter, which adds a column of that type.

Parameters

  • table_name String

Returns

  • ActiveRecord::Query

See also

ActiveRecord.Database:create(table_name)

shared packages/active_record/lib/database/database.lua:86

Starts a CREATE TABLE query. The returned query has a method for every column type of the current adapter (query:string, query:integer, ...).

Parameters

  • table_name String

Returns

  • ActiveRecord::Query

See also

ActiveRecord.Database:delete(table_name)

shared packages/active_record/lib/database/database.lua:63

Starts a DELETE query on a table.

Parameters

  • table_name String

Returns

  • ActiveRecord::Query

ActiveRecord.Database:destroy(_settings)

shared packages/active_record/lib/database/database.lua:172

Disconnects the active adapter from the database.

Parameters

  • _settings Map optional, defaults to nil unused

ActiveRecord.Database:drop(table_name)

shared packages/active_record/lib/database/database.lua:70

Starts a DROP TABLE query.

Parameters

  • table_name String

Returns

  • ActiveRecord::Query

ActiveRecord.Database:drop_database(settings)

shared packages/active_record/lib/database/database.lua:150

Drops the database named in the settings and disconnects the adapter afterward. Connects to the 'template1' database to do so.

Parameters

  • settings Map database settings: host, user, port, password and database

ActiveRecord.Database:insert(table_name)

shared packages/active_record/lib/database/database.lua:43

Starts an INSERT query on a table.

local query = ActiveRecord.Database:insert('ar_metadata')
  query:insert('key', 'version')
  query:insert('value', 20190309120000)
query:execute()

Parameters

  • table_name String

Returns

  • ActiveRecord::Query

ActiveRecord.Database:select(table_name)

shared packages/active_record/lib/database/database.lua:30

Starts a SELECT query on a table. Query methods do not chain; configure the query and then run it with #execute.

local query = ActiveRecord.Database:select('ar_metadata')
  query:where('key', 'version')
  query:limit(1)
  query:callback(function(result, query_str, time)
    if istable(result) and #result > 0 then
      print(result[1].value)
    end
  end)
query:execute()

Parameters

  • table_name String

Returns

  • ActiveRecord::Query

ActiveRecord.Database:setup(settings)

shared packages/active_record/lib/database/database.lua:102

Creates the database named in the settings and disconnects the adapter afterward. Only PostgreSQL is supported; on MySQL instructions are printed instead.

Parameters

  • settings Map database settings: host, user, port, password and database

ActiveRecord.Database:truncate(table_name)

shared packages/active_record/lib/database/database.lua:77

Starts a TRUNCATE TABLE query.

Parameters

  • table_name String

Returns

  • ActiveRecord::Query

ActiveRecord.Database:update(table_name)

shared packages/active_record/lib/database/database.lua:56

Starts an UPDATE query on a table.

local query = ActiveRecord.Database:update('ar_metadata')
  query:where('key', 'version')
  query:update('value', 20190309120000)
query:execute()

Parameters

  • table_name String

Returns

  • ActiveRecord::Query

Defined in