Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#! /usr/local/bin/perl | ||
use strict; | ||
use warnings; | ||
use lib qw(./lib); | ||
use Demo::DB; | ||
use Data::Dumper; | ||
|
||
my $db = Demo::DB->new; | ||
$db->connect({dsn => 'dbi:SQLite:./db/demo_user.db'}); | ||
|
||
$db->delete('user'); | ||
|
||
$db->bulk_insert('user', | ||
[ | ||
{ name => 'nekokak' }, | ||
{ name => 'kazuho' }, | ||
{ name => 'yappo' }, | ||
{ name => 'nekoya' }, | ||
{ name => 'oinume' }, | ||
] | ||
); | ||
|
||
my $itr = $db->search('user'); | ||
|
||
my @json = map { $_->to_json } $itr->all; | ||
warn Dumper \@json; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package Demo::DB; | ||
use DBIx::Skinny; | ||
|
||
package Demo::DB::Schema; | ||
use DBIx::Skinny::Schema; | ||
|
||
install_table user => schema { | ||
pk 'id'; | ||
columns qw/id name/; | ||
}; | ||
|
||
1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package Demo::DB::Row; | ||
use strict; | ||
use warnings; | ||
use base 'DBIx::Skinny::Row'; | ||
use JSON::XS qw/encode_json/; | ||
|
||
sub to_json { | ||
my $self = shift; | ||
encode_json($self->get_columns); | ||
} | ||
|
||
1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE user ( | ||
id INTEGER PRIMARY KEY AUTO_INCREMENT, | ||
name VARCHAR(255) NOT NULL, | ||
UNIQUE(name) | ||
); | ||
|