Adapter for the SQLite database built into Garry's Mod (the sql library). It is the default: it is used when the database settings name the 'sqlite' or 'sqlite3' adapter, or none at all. It needs no connection and no binary module, every query blocks until it is done, and schema changes can be rolled back, so migrations run in a transaction. Foreign keys are enforced: the adapter turns their enforcement on when it connects, and it lasts as long as the connection, which Garry's Mod keeps open while the server runs. Primary keys are AUTOINCREMENT, so the id of a deleted row is never given to a new one.

Summary

Methods

Raises an error listing the rows that refer to rows that do not exist through a foreign key, if there are more of them than before.
Turns on the enforcement of foreign keys and calls the callback right away, since the SQLite database built into Garry's Mod needs no connection.
Stops enforcing foreign keys.
Enforces foreign keys.
Escapes a string with sql.SQLStr, which doubles its single quotes.
Counts the rows that refer to rows that do not exist through a foreign key.
Checks whether foreign keys are enforced right now.
Checks whether the adapter talks to an SQLite database.
Quotes an identifier such as a table or column name with double quotes, doubling the double quotes in it.
Runs a raw SQL query on the built-in SQLite database.
SQLite can roll back schema changes.
Turns doubled single quotes in a string read from the database back into single ones.

Methods

ActiveRecord.Adapters.Sqlite:check_foreign_keys(table_name, before)

shared packages/active_record/lib/adapters/sqlite.lua:116

Raises an error listing the rows that refer to rows that do not exist through a foreign key, if there are more of them than before.

Parameters

  • table_name String optional, defaults to nil only check the rows of this table
  • before Map optional, defaults to nil what #foreign_key_violations returned before; these rows are not reported

ActiveRecord.Adapters.Sqlite:connect(_settings, on_connected)

shared packages/active_record/lib/adapters/sqlite.lua:34

Turns on the enforcement of foreign keys and calls the callback right away, since the SQLite database built into Garry's Mod needs no connection. Rows that broke a foreign key before stay as they are; only the rows written from then on are checked.

Parameters

  • _settings Map database settings; unused
  • on_connected Function optional, defaults to nil called with the adapter

ActiveRecord.Adapters.Sqlite:disable_foreign_keys()

shared packages/active_record/lib/adapters/sqlite.lua:56

Stops enforcing foreign keys. SQLite ignores this inside of a transaction, so it has to be called before one is started.

Returns

  • Boolean whether the enforcement was on and has been turned off

ActiveRecord.Adapters.Sqlite:enable_foreign_keys()

shared packages/active_record/lib/adapters/sqlite.lua:65

Enforces foreign keys. SQLite ignores this inside of a transaction.

ActiveRecord.Adapters.Sqlite:escape(str)

shared packages/active_record/lib/adapters/sqlite.lua:162

Escapes a string with sql.SQLStr, which doubles its single quotes.

Parameters

  • str String

Returns

  • String escaped string without surrounding quotes

ActiveRecord.Adapters.Sqlite:foreign_key_violations(table_name)

shared packages/active_record/lib/adapters/sqlite.lua:107

Counts the rows that refer to rows that do not exist through a foreign key.

Parameters

  • table_name String optional, defaults to nil only count the rows of this table

Returns

  • Map numbers of such rows, keyed by the table, the referenced table and the foreign key

ActiveRecord.Adapters.Sqlite:foreign_keys_enabled()

shared packages/active_record/lib/adapters/sqlite.lua:47

Checks whether foreign keys are enforced right now.

Returns

  • Boolean

ActiveRecord.Adapters.Sqlite:is_sqlite()

shared packages/active_record/lib/adapters/sqlite.lua:149

Checks whether the adapter talks to an SQLite database.

Returns

  • Boolean always true

ActiveRecord.Adapters.Sqlite:quote_name(str)

shared packages/active_record/lib/adapters/sqlite.lua:170

Quotes an identifier such as a table or column name with double quotes, doubling the double quotes in it.

Parameters

  • str String

Returns

  • String

ActiveRecord.Adapters.Sqlite:raw_query(query, callback, query_type, bindings, error_callback)

shared packages/active_record/lib/adapters/sqlite.lua:197

Runs a raw SQL query on the built-in SQLite database. Always blocks until the query is done, regardless of the sync mode. A query that is given bindings, even an empty list of them, is run with sql.QueryTyped: numbers come back as numbers and NULL columns are left out of their rows. Without bindings it is run with sql.Query, which returns every value as a string, but takes several statements at once.

Parameters

  • query String SQL to run
  • callback Function optional, defaults to nil called with the result rows (a List of row Maps; nil if a query without bindings produced no rows), the query string, the time taken in seconds and the bindings. For 'insert' queries the result is a single row with the id of the new row instead
  • query_type String optional, defaults to nil lowercase query type, e.g. 'insert'
  • bindings List optional, defaults to nil values of the ? placeholders in the query. A query that is given bindings has to be a single statement
  • error_callback Function optional, defaults to nil called with the error text if the query fails

Returns

  • Any whatever the callback returns; nothing without a callback or on error

ActiveRecord.Adapters.Sqlite:supports_ddl_transactions()

shared packages/active_record/lib/adapters/sqlite.lua:155

SQLite can roll back schema changes.

Returns

  • Boolean always true

ActiveRecord.Adapters.Sqlite:unescape(str)

shared packages/active_record/lib/adapters/sqlite.lua:177

Turns doubled single quotes in a string read from the database back into single ones.

Parameters

  • str String

Returns

  • String

Defined in