Pcore
view release on metacpan or search on metacpan
lib/Pcore/Handle/pgsql/DBH.pm view on Meta::CPAN
# write error
return $self->_on_fatal_error if !$self->{h};
}
return;
}
sub _execute ( $self, $query, $bind, $cb, %args ) {
if ( $self->{state} != $STATE_READY ) {
warn 'DBI: DBH is busy';
$cb->( undef, res [ 500, 'DBH is busy' ] );
return;
}
$self->{state} = $STATE_BUSY;
$self->{sth}->{cb} = $cb;
my $use_extended_query = defined $bind || defined $args{max_rows};
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'; # Enum [ keys $SQLITE_OPEN->%* ]
has busy_timeout => 1_000 * 3; # PositiveOrZeroInt ), milliseconds, set to 0 to disable timeout, default - 3 seconds
# SQLITE PRAGMAS
has temp_store => 'MEMORY'; # Enum [qw[FILE MEMORY]]
has journal_mode => 'WAL'; # Enum [qw[DELETE TRUNCATE PERSIST MEMORY WAL OFF]], WAL is the best
has synchronous => 'OFF'; # 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; # Int, 0+ - pages, -kilobytes, default 1G
has foreign_keys => 1; # Bool
# TODO
# has to_string => 999; # automaticaly stringify query if number of bind params greater than this threshold
lib/Pcore/Handle/sqlite.pm view on Meta::CPAN
my $dbh = DBI->connect( "dbi:SQLite:dbname=$dbname", $EMPTY, $EMPTY, $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, $SQLITE_BLOB ] } );
$dbh->sqlite_create_function( 'uuid_generate_v4', 0, sub { return [ uuid_v4_str, $SQLITE_BLOB ] } );
$dbh->sqlite_create_function( 'gen_random_uuid', 0, sub { return [ uuid_v4_str, $SQLITE_BLOB ] } );
$dbh->sqlite_create_function( 'time_hires', 0, sub { return Time::HiRes::time() } );
$dbh->sqlite_create_function( 'md5', 1, sub { return defined $_[0] ? [ md5_hex( encode_utf8 $_[0] ), $SQLITE_BLOB ] : undef } );
$self->{on_connect}->($self) if $self->{on_connect};
( run in 0.261 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )