Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Perl
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
t
xt
.gitignore
.shipit
Changes
MANIFEST.SKIP
Makefile.PL
README
README.mkdn

README.mkdn

NAME

Nigiri - micro ORM

SYNOPSIS

your sql schema in sqlite

CREATE TABLE user (
    id INTEGER NOT NULL PRIMARY KEY,
    name VARCHAR(255)
);
CREATE TABLE url (
    id INTEGER NOT NULL PRIMARY KEY,
    title VARCHAR(255),
    url   VARCHAR(255)
);
CREATE TABLE bookmark (
    id INTEGER NOT NULL PRIMARY KEY,
    user_id INT,
    url_id INT,
    UNIQUE (user_id, url_id)
);
CREATE INDEX url_id ON bookmark (url_id);

in perl code

use Nigiri;


my $nigiri = Nigiri->new('dbi:SQLite:dbname=example.db');


# insert user table
my $user = $nigiri->user->new;
$user->name('nekokak');
my $user_id = $user->save;


# insert url table
my $url = $nigiri->url->new;
$url->title('Google');
$url->url('http://goo.gl/e');
my $url_id = $url->save;


# insert bookmark table
my $bookmark = $nigiri->bookmark->new;
$bookmark->user_id($user_id);
$bookmark->url_id($url_id);
my $bookmark_id = $bookmark->save;


# insert syntax sugar
my $user_id = $nigiri->user->new(
    name => 'yappo',
)->save;


# lookup & update table
my $user = $nigiri->user->lookup(1);
$user->name('yappo');
$user->update;


# delete table
$user->delete;


# search
my $itr = $nigiri->user->search(
    'WHERE name = ? OR name = ? ORDER BY id DESC LIMIT 10',
    'nekokak', 'yappo'
);
while (my $row = $itr->next) {
    say $row->id, $row->name;
}

# transaction
do {
    my $txn = $nigiri->txn_scope;
    $row->save;
}; # rollback
do {
    my $txn = $nigiri->txn_scope;
    $row->save;
    $txn->commit;
};

using raw dbh

my ($count) = $nigiri->get_dbh->selectrow_array('SELECT COUNT(*) FROM user');

DESCRIPTION

Nigiri is

AUTHOR

Kazuhiro Osawa

SEE ALSO

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Something went wrong with that request. Please try again.