Skip to content

yappo/p5-Nigiri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 <yappo {at} shibuya {dot} pl>

SEE ALSO

LICENSE

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages