-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathREADME
126 lines (89 loc) · 3.17 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
NAME
DBIx::ObjectMapper - An implementation of the Data Mapper pattern
(object-relational mapper).
SYNOPSIS
Create a engine and a mapper object.
use DBIx::ObjectMapper;
use DBIx::ObjectMapper::Engine::DBI;
my $engine = DBIx::ObjectMapper::Engine::DBI->new({
dsn => 'dbi:SQLite:',
username => undef,
password => undef,
});
my $mapper = DBIx::ObjectMapper->new( engine => $engine );
Create a ordinary perl class.
package My::User;
use base qw(Class::Accessor::Fast);
__PACKAGE__->mk_accessors(qw(id name));
1;
Get/Define metadata of the table.
my $user_meta = $mapper->metadata->table( 'user' => 'autoload' );
# or
use DBIx::ObjectMapper::Metadata::Sugar qw(:all);
my $user_meta = $mapper->metadata->table(
'user' => [
Col( id => Int(), PrimaryKey ),
Col( name => String(128), NotNull ),
]
);
Map the table metadata to the ordinary class.
$mapper->maps( $user_meta => 'My::User' );
Create session. And add My::User object to session object.
my $session = $mapper->begin_session;
my $user = My::User->new({ id => 1, name => 'name1' });
$session->add($user);
When the $session is destroyed, the session object send a insert query
to the database.
Get a My::User Object.
my $session = $mapper->begin_session;
my $user = $session->get( 'My::User' => 1 );
$user->id;
$user->name;
DESCRIPTION
DBIx::ObjectMapper is a implementation of the Data Mapper pattern. And
abstraction layer for database access.
Concepts and interfaces of this module borrowed from SQLAlchemy.
<http://www.sqlalchemy.org/>
METHODS
new(%args)
engine
DBIx::ObjectMapper::Engine
metadata
By default DBIx::ObjectMapper::Metadata. Set a
DBIx::ObjectMapper::Metadata based object if you want.
mapping_class
By default DBIx::ObjectMapper::Mapper. Set a
DBIx::ObjectMapper::Mapper based object if you want.
session_class
By default DBIx::ObjectMapper::Session. Set a
DBIx::ObjectMapper::Session based class if you want.
session_attr
Set a hash reference of counstructor parameters of
DBIx::ObjectMapper::Session. When you call the begin_session
method, you get a DBIx::ObjectMapper::Session object that this
option is set up.
begin_session(%session_option)
Gets a session object instance, and begins session. See the
DBIx::ObjectMapper::Session for more information.
maps(%map_config)
Sets a configuration of mapping. See the DBIx::ObjectMapper::Mapper for
more information.
relation( $relation_type => \%relation_config )
DBIx::ObjectMapper::Relation
metadata()
Returns the metadata object.
engine()
Returns the engine object.
mapping_class()
Returns the mapping_class.
session_class()
Returns the session_class.
AUTHOR
Eisuke Oishi
CONTRIBUTORS
nekokak: Atsushi Kobayashi
COPYRIGHT
Copyright 2010 Eisuke Oishi
LICENSE
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.