-
Notifications
You must be signed in to change notification settings - Fork 2
/
README
178 lines (134 loc) · 4.01 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
NAME
Data::Model - model interface which had more data sources unified, a.k.a
data/object mapper
SYNOPSIS
package Your::Model;
use base 'Data::Model';
use Data::Model::Schema;
use Data::Model::Driver::DBI;
my $dbfile = '/foo/bar.db';
my $driver = Data::Model::Driver::DBI->new(
dsn => "dbi:SQLite:dbname=$dbfile",
);
base_driver( $driver );
install_model user => schema {
key 'id';
columns qw/
id
name
/;
};
# create database file
unless (-f $dbfile) {
my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1, PrintError => 0 });
for my $sql (__PACKAGE__->as_sqls) {
$dbh->do( $sql );
}
$dbh->disconnect;
}
# in your script:
use Your::Model;
my $model = Your::Model->new;
# insert
my $row = $model->set(
user => {
id => 1,
}
);
my $row = $model->lookup( user => 1 );
$row->delete;
DESCRIPTION
Data::Model is can use as ORM which can be defined briefly.
There are few documents. It is due to be increased in the near future.
SCHEMA DEFINITION
One package can define two or more tables using DSL.
see Data::Model::Schema.
METHODS
new([ \%options ]);
my $model = Class->new;
lookup($target => $key)
my $row = $model->lookup( user => $id );
print $row->name;
lookup_multi($target => \@keylist)
my @row = $model->lookup_multi( user => [ $id1, $id2 ] );
print $row[0]->name;
print $row[1]->name;
get($target => $key [, \%options ])
my $iterator = $model->get( user => {
id => {
IN => [ $id1, $id2 ],
}
});
while (my $row = $iterator->next) {
print $row->name;
}
# or
while (my $row = <$iterator>) {
print $row->name;
}
# or
while (<$iterator>) {
print $_->name;
}
set($target => $key, => \%values [, \%options ])
$model->set( user => {
id => 3,
name => 'insert record',
});
if insert to table has auto increment then return $row object with fill
in key column by last_insert_id.
my $row = $model->set( user => {
name => 'insert record',
});
say $row->id; # show last_insert_id()
delete($target => $key [, \%options ])
$model->delete( user => 3 ); # id = 3 is deleted
ROW OBJECT METHODS
row object is provided by Data::Model::Row.
update
my $row = $model->lookup( user => $id );
$row->name('update record');
$row->update;
delete
my $row = $model->lookup( user => $id );
$row->delete;
TRANSACTION
see Data::Model::Transaction.
DATA DRIVERS
DBI
see Data::Model::Driver::DBI.
DBI::MasterSlave
master-slave composition for mysql.
see Data::Model::Driver::DBI::MasterSlave.
Cache
Cash of the result of a query.
see Data::Model::Driver::Cache::HASH, see
Data::Model::Driver::Cache::Memcached.
Memcached
memcached is used for data storage.
see Data::Model::Driver::Memcached.
Queue::Q4M
queuing manager for Q4M.
see Data::Model::Driver::Queue::Q4M.
Memory
on memory storage.
see Data::Model::Driver::Memory.
SEE ALSO
Data::Model::Row, Data::Model::Iterator
ACKNOWLEDGEMENTS
Benjamin Trott more idea given by Data::ObjectDriver
AUTHOR
Kazuhiro Osawa <yappo <at> shibuya <döt> pl>
REPOSITORY
git clone git://github.com/yappo/p5-Data-Model.git
Data::Model's Git repository is hosted at
<http://github.com/yappo/p5-Data-Model>. patches and collaborators are
welcome.
LICENSE
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
POD ERRORS
Hey! The above document had some coding errors, which are explained
below:
Around line 754:
Non-ASCII character seen before =encoding in '<döt>'. Assuming UTF-8