DBIO::SQLite
SQLite driver for DBIO (fork of DBIx::Class::Storage::DBI::SQLite).
Supports
- desired-state deployment via test-deploy-and-compare (DBIO::SQLite::Deploy)
- native introspection (DBIO::SQLite::Introspect)
- native diff (DBIO::SQLite::Diff)
- native DDL generation (DBIO::SQLite::DDL)
Usage
package MyApp::DB;
use base 'DBIO::Schema';
__PACKAGE__->load_components('SQLite');
my $schema = MyApp::DB->connect('dbi:SQLite:myapp.db');
For in-memory testing:
my $schema = MyApp::DB->connect('dbi:SQLite::memory:');
DBIO core autodetects dbi:SQLite: DSNs and loads this storage automatically.
SQLite Features
Types
INTEGER- 64-bit signed integer (also used for PRIMARY KEY / AUTOINCREMENT)REAL- IEEE 754 64-bit floating pointTEXT- UTF-8 textBLOB- binary data (stored as-is)NUMERIC- affinity for integer/real/decimal
SQLite JSON (version 3.38+)
JSONtype withjson_extract,json_array,json_objectfunctions->and->>operators for JSON path extraction- Comparison operators work on JSON values
Full-Text Search (FTS5)
fts5virtual table support viaDBIO::SQLite::Result::FTS5MATCHoperator for full-text queries- BM25 ranking and relevance scoring
- Trigram tokenizers for fuzzy matching
Indexes
PRIMARY KEY- integer primary key is an alias for rowidUNIQUEconstraints create indexesINDEXED BYfor query-time index selection- Partial indexes via
WHEREclause (SQLite 3.8.0+) - Expression indexes via
GENERATED ALWAYS AScolumns
SQLite-Specific Features
INSERT OR IGNORE- skip on constraint violationINSERT OR REPLACE- replace existing row on conflictON CONFLICT ... DO NOTHING- conflict resolutionRETURNINGclause (SQLite 3.35+)UPSERT(INSERT ON CONFLICT) syntax- Multiple schemas via ATTACH DATABASE
- Transaction savepoints with nested transactions
VACUUMfor database maintenance
Introspection
sqlite_masterfor schema metadataPRAGMA table_info,PRAGMA index_list,PRAGMA foreign_key_listsqlite_sequencefor AUTOINCREMENT tracking
Deploy
DBIO::SQLite::Deploy orchestrates test-deploy-and-compare:
- Introspect live database via sqlite_master and PRAGMA (DBIO::SQLite::Introspect)
- Deploy desired schema to a temporary in-memory database (
:memory:) - Introspect the temporary database the same way
- Diff source vs target (DBIO::SQLite::Diff)
SQLite's :memory: database makes deploy testing extremely fast - no cleanup needed.
Install (install_ddl) creates fresh schema. Upgrade diffs live vs. desired.
Testing
export DBIO_TEST_SQLITE_DSN="dbi:SQLite::memory:"
prove -l t/
SQLite is ideal for testing because :memory: requires no server process.
Offline tests (t/00-load.t) run without any database.
Requirements
- Perl 5.36+
- DBD::SQLite
- DBIO core
See Also
DBIO::Introspect::Base, DBIO::Diff::Base, DBIO::Deploy