DBIx::Oro::Driver::SQLite - SQLite driver for DBIx::Oro
use DBIx::Oro; # Create an SQLite Oro object my $oro = DBIx::Oro->new('file.sqlite'); # Attach new databases $oro->attach(blog => ':memory:'); # Check, if database was newly created if ($oro->created) { # Create table $oro->do( 'CREATE TABLE Person ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, age INTEGER )'); # Create Fulltext Search tables $oro->do( 'CREATE VIRTUAL TABLE Blog USING fts4(title, body)' ); }; # Insert values $oro->insert(Blog => { title => 'My Birthday', body => 'It was a wonderful party!' }); # Create snippet treatment function my $snippet = $oro->snippet( start => '<strong>', end => '</strong>', token => 10 ); my $birthday = $oro->load(Blog => [[ $snippet => 'snippet']] => { Blog => { match => 'birthday' } }); print $birthday->{snippet}; # My <strong>Birthday</strong>
DBIx::Oro::Driver::SQLite is an SQLite specific database driver for DBIx::Oro that provides further functionalities.
DBIx::Oro::Driver::SQLite is a development release! Do not rely on any API methods, especially on those marked as experimental.
DBIx::Oro::Driver::SQLite inherits all attributes from DBIx::Oro and implements the following new ones (with possibly overwriting inherited attributes).
if ($oro->created) { print "This is brand new!"; };
If the database was created on construction of the handle, this attribute is true. Otherwise it's false. In most cases, this is useful to create tables, triggers and indices for SQLite databases.
if ($oro->created) { $oro->txn( sub { # Create table $oro->do( 'CREATE TABLE Person ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, age INTEGER )' ) or return -1; # Create index $oro->do( 'CREATE INDEX age_i ON Person (age)' ) or return -1; }); };
my $file = $oro->file; $oro->file('myfile.sqlite');
The sqlite file of the database. This can be a filename (with a path prefix), :memory: for memory databases or the empty string for temporary files.
:memory:
print $oro->foreign_keys; $oro->foreign_keys(0);
DBIx::Oro::Driver::SQLite turns foreign keys on by default. To disable this, set foreign_keys to a false value, e.g. in the constructor.
foreign_keys
print $oro->autocommit; $oro->autocommit(200);
Run commit after a given number of insert, update, delete or merge operations. Accepts the number of silent operations till the commit is released. Will automatically commit on start. To release unstaged changes at the end, just reset autocommit, e.g. with autocommit(0).
insert
update
delete
merge
autocommit(0)
DBIx::Oro::Driver::SQLite inherits all methods from DBIx::Oro and implements the following new ones (with possibly overwriting inherited methods).
my $oro = DBIx::Oro->new('test.sqlite'); $oro = DBIx::Oro->new(':memory:'); $oro = DBIx::Oro->new(''); $oro = DBIx::Oro->new( file => 'test.sqlite', driver => 'SQLite', init => sub { shift->do( 'CREATE TABLE Person ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, age INTEGER )' ); } );
Creates a new SQLite database accessor object on the given filename or in memory, if the filename is :memory:. If the database file does not already exist, it is created. If the file is the empty string, a temporary database is created. A callback function called init will be triggered, if the database was newly created. This callback is wrapped inside a transaction. The first parameter of the callback function is the Oro object.
init
See new in DBIx::Oro for further information.
$oro->delete(Person => { id => 4, -secure => 1});
Deletes rows of a given table, that meet a given condition. See delete in DBIx::Oro for further information.
In addition to conditions, the deletion can have further parameters.
-secure
Forces a secure deletion by overwriting all data with 0.
0
The security parameter is EXPERIMENTAL and may change without warnings.
$oro->attach( another_db => 'users.sqlite' ); $oro->attach( another_db => ':memory:' ); $oro->attach( 'another_db' ); $oro->load( 'another_db.user' => { id => 4 } );
Attaches another database file to the connector. All tables of this database can then be queried with the same connector.
Accepts the database handle name and a database file name. If the file name is ':memory:' a new database is created in memory. If no file name is given, a temporary database is created. If the database file name does not exist, it returns undef.
The database handle can be used as a prefix for tables in queries. The default prefix for tables of the parent database is main..
main.
This method is EXPERIMENTAL and may change without warnings.
$oro->detach('another_db'); $oro->detach(@another_dbs);
Detaches attached databases from the connection.
Treatments can be used for the manipulation of select and load queries.
DBIx::Oro::Driver::SQLite implements the following treatment generators.
matchinfo
my $result = $oro->select( text => [[ $oro->matchinfo('nls') => 'matchinfo']] => { text => { match => 'default transaction' } }); # $result = [{ # matchinfo => { # l => [3, 3], # n => 3, # c => 2, # p => 2, # s => [2, 0] # } # }, { # matchinfo => { # l => [4, 3], # n => 3, # c => 2, # p => 2, # s => [1, 1] # } # }];
Creates a treatment for select or load that supports matchinfo information for fts3/fts4 tables. It accepts a format string containing the characters p, c, n, a, l, s, and x. See the SQLite manual for further information on these characters. The characters p and c will always be set. Returns the column value as a hash reference of the associated values.
p
c
n
a
l
s
x
offsets
my $result = $oro->load( text => [[ $oro->offsets => 'offset' ]] => { text => { match => 'world' } }); # $result = { # offset => [ # [0, 0, 6, 5], # [1, 0, 24, 5] # ] # };
Creates a treatment for select or load that supports offset information for fts3/fts4 tables. It accepts no parameters and returns the column value as an array reference containing multiple array references.
See the SQLite manual for further information.
snippet
my $snippet = $oro->snippet( start => '[', end => ']', ellipsis => '', token => 5, column => 1 ); my $result = $oro->load( text => [[ $snippet => 'excerpt' ]] => { text => { match => 'cold' } }); print $result->{excerpt}; # It was [cold] outside
Creates a treatment for select or load that supports snippets for fts3/fts4 tables. On creation it accepts the parameters start, end, ellipsis, token, and column.
start
end
ellipsis
token
column
The SQLite manual, especially the information regarding the fulltext search extensions.
DBI, DBD::SQLite.
https://github.com/Akron/DBIx-Oro
Copyright (C) 2011-2013, Nils Diewald.
This program is free software, you can redistribute it and/or modify it under the same terms as Perl.
To install DBIx::Oro, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Oro
CPAN shell
perl -MCPAN -e shell install DBIx::Oro
For more information on module installation, please visit the detailed CPAN module installation guide.