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
Methods
ActiveRecord.Adapters.Sqlite:check_foreign_keys(table_name, before)
shared packages/active_record/lib/adapters/sqlite.lua:116Raises 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
nilonly check the rows of this table - before Map optional, defaults to
nilwhat #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:34Turns 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
nilcalled with the adapter
ActiveRecord.Adapters.Sqlite:disable_foreign_keys()
shared packages/active_record/lib/adapters/sqlite.lua:56Stops 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:65Enforces foreign keys. SQLite ignores this inside of a transaction.
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:107Counts the rows that refer to rows that do not exist through a foreign key.
Parameters
- table_name String optional, defaults to
nilonly 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:47Checks whether foreign keys are enforced right now.
Returns
- Boolean
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:170Quotes 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:197Runs 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
nilcalled 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
nillowercase query type, e.g. 'insert' - bindings List optional, defaults to
nilvalues of the ? placeholders 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; nothing without a callback or on error
ActiveRecord.Adapters.Sqlite:supports_ddl_transactions()
shared packages/active_record/lib/adapters/sqlite.lua:155SQLite can roll back schema changes.
Returns
- Boolean always true
ActiveRecord.Adapters.Sqlite:unescape(str)
shared packages/active_record/lib/adapters/sqlite.lua:177Turns doubled single quotes in a string read from the database back into single ones.
Parameters
- str String
Returns
- String