-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
134 lines (99 loc) · 2.81 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
This is Perl module DBIx::Thin. A lightweight ORMapper.
* CONCEPT
DBIx::Thin's conecept is very similar to DBIx::Skinny's, a simple ORMapper. You can write code other ORMappers when simple CRUD and if you execute a complex query, you can specify it directly by calling 'xxx_by_sql' method.
Although the basic idea is the same, there are some differences between DBIx::Skinny and DBIx::Thin. See perldoc for the differences.
* SYNOPSIS
#-----------------------#
# Your/Model.pm
#-----------------------#
package Your::Model;
use DBIx::Thin;
DBIx::Thin->setup(
dsn => 'DBI:SQLite:your_project.sqlite3',
username => '',
password => '',
);
DBIx::Thin->load_defined_schemas;
1;
#-----------------------#
# Your/Model/User.pm
# schema class for table 'user'
#-----------------------#
package Your::Model::User;
use DBIx::Thin::Schema;
use base qw(DBIx::Thin::Row);
install_table 'user' => schema {
primary_key 'id';
defaults string_is_utf8 => 1; # utf8 flag on
columns
id => { type => Integer },
name => { type => String },
email => { type => String, utf8 => 0 }; # utf8 flag off
};
1;
#-----------------------#
# Your/Model/Status.pm
# schema class for table 'status'
#-----------------------#
package Your::Model::Status;
use DBIx::Thin::Schema;
use base qw(DBIx::Thin::Row);
install_table 'status' => schema {
primary_key 'id',
defaults string_is_utf8 => 1;
columns
id => { type => Integer },
text => { type => String },
created_at => { type => Datetime },
};
1;
#-----------------------#
# in your script
#-----------------------#
use Your::Model;
### insert a record
my $row = Your::Model->create(
'user',
values => {
name => 'oinume',
email => 'oinume_at_gmail.com',
}
);
### select records
my $iterator = Your::Model->search(
'user',
where => { name => 'oinume' },
limit => 20,
);
while (my $row = $iterator->next) {
...
}
### update records
Your::Model->update(
'user',
values => { name => 'new_user' },
where => { name => 'oinume' }
);
### delete records
Your::Model->delete(
'user',
where => { name => 'new_user' }
);
### delete a record with primary key
Your::Model->delete_by_pk('user', 10);
* INSTALLATION
DBIx::Thin installation is straightforward. If your CPAN shell is set up,
you should just be able to do
% cpan DBIx::Thin
Download it, unpack it, then build it as per the usual:
% perl Makefile.PL
% make && make test
Then install it:
% make install
* DOCUMENTATION
DBIx::Thin documentation is available as in POD. So you can do:
% perldoc DBIx::Thin
to read the documentation online with your favorite pager.
* LICENSE
Same as Perl itself.
Kazuhiro Oinuma (id:oinume)