Pcore-SQLite
view release on metacpan or search on metacpan
lib/Pcore/Handle/sqlite.pm view on Meta::CPAN
const our $SQLITE_OPEN_RW => SQLITE_OPEN_READWRITE | SQLITE_OPEN_SHAREDCACHE;
const our $SQLITE_OPEN_RWC => SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE;
const our $SQLITE_OPEN => {
ro => $SQLITE_OPEN_RO,
rw => $SQLITE_OPEN_RW,
rwc => $SQLITE_OPEN_RWC,
};
has mode => 'rwc'; # ( is => 'ro', isa => Enum [ keys $SQLITE_OPEN->%* ] );
has busy_timeout => 1_000 * 3; # ( is => 'ro', isa => PositiveOrZeroInt ); # milliseconds, set to 0 to disable timeout, default - 3 seconds
# SQLITE PRAGMAS
has temp_store => 'MEMORY'; # ( is => 'ro', isa => Enum [qw[FILE MEMORY]] );
has journal_mode => 'WAL'; # ( is => 'ro', isa => Enum [qw[DELETE TRUNCATE PERSIST MEMORY WAL OFF]] ); # WAL is the best
has synchronous => 'OFF'; # ( is => 'ro', isa => Enum [qw[FULL NORMAL OFF]] ); # OFF - data integrity on app failure, NORMAL - data integrity on app and OS failures, FULL - full data integrity on app or OS failures, slower
has cache_size => -1_048_576; # ( is => 'ro', isa => Int ); # 0+ - pages, -kilobytes, default 1G
has foreign_keys => 1; # ( is => 'ro', isa => Bool );
has is_sqlite => 1; # ( is => 'ro', isa => Bool, default => 1, init_arg => undef );
has h => (); # ( is => 'ro', isa => Object, init_arg => undef );
lib/Pcore/Handle/sqlite.pm view on Meta::CPAN
my $dbh = DBI->connect( "dbi:SQLite:dbname=$dbname", q[], q[], $attr );
$dbh->do('PRAGMA encoding = "UTF-8"');
$dbh->do( 'PRAGMA temp_store = ' . $self->{temp_store} );
$dbh->do( 'PRAGMA journal_mode = ' . $self->{journal_mode} );
$dbh->do( 'PRAGMA synchronous = ' . $self->{synchronous} );
$dbh->do( 'PRAGMA cache_size = ' . $self->{cache_size} );
$dbh->do( 'PRAGMA foreign_keys = ' . $self->{foreign_keys} );
$dbh->sqlite_busy_timeout( $self->{busy_timeout} );
# create custom functions
$dbh->sqlite_create_function( 'uuid_generate_v1mc', 0, sub { return uuid_v1mc_str } );
$dbh->sqlite_create_function( 'uuid_generate_v4', 0, sub { return uuid_v4_str } );
$dbh->sqlite_create_function( 'gen_random_uuid', 0, sub { return uuid_v4_str } );
$self->{on_connect}->($self) if $self->{on_connect};
$self->{h} = $dbh;
( run in 0.223 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )