Newer Older
599 lines | 14.766kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
2
.\"
3
.\" Standard preamble:
4
.\" ========================================================================
5
.de Sh \" Subsection heading
6
.br
7
.if t .Sp
8
.ne 5
9
.PP
10
\fB\\$1\fR
11
.PP
12
..
13
.de Sp \" Vertical space (when we can't use .PP)
14
.if t .sp .5v
15
.if n .sp
16
..
17
.de Vb \" Begin verbatim text
18
.ft CW
19
.nf
20
.ne \\$1
21
..
22
.de Ve \" End verbatim text
23
.ft R
24
.fi
25
..
26
.\" Set up some character translations and predefined strings.  \*(-- will
27
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28
.\" double quote, and \*(R" will give a right double quote.  | will give a
29
.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
30
.\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
31
.\" expand to `' in nroff, nothing in troff, for use with C<>.
32
.tr \(*W-|\(bv\*(Tr
33
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34
.ie n \{\
35
.    ds -- \(*W-
36
.    ds PI pi
37
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
39
.    ds L" ""
40
.    ds R" ""
41
.    ds C` ""
42
.    ds C' ""
43
'br\}
44
.el\{\
45
.    ds -- \|\(em\|
46
.    ds PI \(*p
47
.    ds L" ``
48
.    ds R" ''
49
'br\}
50
.\"
51
.\" If the F register is turned on, we'll generate index entries on stderr for
52
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53
.\" entries marked with X<> in POD.  Of course, you'll have to process the
54
.\" output yourself in some meaningful fashion.
55
.if \nF \{\
56
.    de IX
57
.    tm Index:\\$1\t\\n%\t"\\$2"
58
..
59
.    nr % 0
60
.    rr F
61
.\}
62
.\"
63
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
64
.\" way too many mistakes in technical documents.
65
.hy 0
66
.if n .na
67
.\"
68
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70
.    \" fudge factors for nroff and troff
71
.if n \{\
72
.    ds #H 0
73
.    ds #V .8m
74
.    ds #F .3m
75
.    ds #[ \f1
76
.    ds #] \fP
77
.\}
78
.if t \{\
79
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80
.    ds #V .6m
81
.    ds #F 0
82
.    ds #[ \&
83
.    ds #] \&
84
.\}
85
.    \" simple accents for nroff and troff
86
.if n \{\
87
.    ds ' \&
88
.    ds ` \&
89
.    ds ^ \&
90
.    ds , \&
91
.    ds ~ ~
92
.    ds /
93
.\}
94
.if t \{\
95
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101
.\}
102
.    \" troff and (daisy-wheel) nroff accents
103
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110
.ds ae a\h'-(\w'a'u*4/10)'e
111
.ds Ae A\h'-(\w'A'u*4/10)'E
112
.    \" corrections for vroff
113
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115
.    \" for low resolution devices (crt and lpr)
116
.if \n(.H>23 .if \n(.V>19 \
117
\{\
118
.    ds : e
119
.    ds 8 ss
120
.    ds o a
121
.    ds d- d\h'-1'\(ga
122
.    ds D- D\h'-1'\(hy
123
.    ds th \o'bp'
124
.    ds Th \o'LP'
125
.    ds ae ae
126
.    ds Ae AE
127
.\}
128
.rm #[ #] #H #V #F C
129
.\" ========================================================================
130
.\"
131
.IX Title "DBIx::Custom 3"
132
.TH DBIx::Custom 3 "2009-11-16" "perl v5.8.8" "User Contributed Perl Documentation"
133
.SH "NAME"
134
DBIx::Custom \- Customizable simple DBI
135
.SH "VERSION"
136
.IX Header "VERSION"
137
Version 0.0501
138
.SH "CAUTION"
139
.IX Header "CAUTION"
140
This module is now experimental stage.
141
.PP
142
I want you to try this module
143
because I want this module stable, and not to damage your \s-1DB\s0 data by this module bug.
144
.PP
145
Please tell me bug if you find
146
.SH "SYNOPSIS"
147
.IX Header "SYNOPSIS"
148
.Vb 1
149
\&  my $dbi = DBIx::Custom->new;
150
.Ve
151
.PP
152
.Vb 2
153
\&  my $query = $dbi->create_query($template);
154
\&  $dbi->execute($query);
155
.Ve
156
.SH "CLASS-OBJECT ACCESSORS"
157
.IX Header "CLASS-OBJECT ACCESSORS"
158
.Sh "user"
159
.IX Subsection "user"
160
.Vb 3
161
\&    # Set and get database user name
162
\&    $self = $dbi->user($user);
163
\&    $user = $dbi->user;
164
.Ve
165
.PP
166
.Vb 2
167
\&    # Sample
168
\&    $dbi->user('taro');
169
.Ve
170
.Sh "password"
171
.IX Subsection "password"
172
.Vb 3
173
\&    # Set and get database password
174
\&    $self     = $dbi->password($password);
175
\&    $password = $dbi->password;
176
.Ve
177
.PP
178
.Vb 2
179
\&    # Sample
180
\&    $dbi->password('lkj&le`@s');
181
.Ve
182
.Sh "data_source"
183
.IX Subsection "data_source"
184
.Vb 3
185
\&    # Set and get database data source
186
\&    $self        = $dbi->data_source($data_soruce);
187
\&    $data_source = $dbi->data_source;
188
.Ve
189
.PP
190
.Vb 2
191
\&    # Sample(SQLite)
192
\&    $dbi->data_source(dbi:SQLite:dbname=$database);
193
.Ve
194
.PP
195
.Vb 2
196
\&    # Sample(MySQL);
197
\&    $dbi->data_source("dbi:mysql:dbname=$database");
198
.Ve
199
.PP
200
.Vb 2
201
\&    # Sample(PostgreSQL)
202
\&    $dbi->data_source("dbi:Pg:dbname=$database");
203
.Ve
204
.Sh "database"
205
.IX Subsection "database"
206
.Vb 3
207
\&    # Set and get database name
208
\&    $self     = $dbi->database($database);
209
\&    $database = $dbi->database;
210
.Ve
211
.PP
212
This method will be used in subclass connect method.
213
.Sh "dbi_options"
214
.IX Subsection "dbi_options"
215
.Vb 3
216
\&    # Set and get DBI option
217
\&    $self       = $dbi->dbi_options({$options => $value, ...});
218
\&    $dbi_options = $dbi->dbi_options;
219
.Ve
220
.PP
221
.Vb 2
222
\&    # Sample
223
\&    $dbi->dbi_options({PrintError => 0, RaiseError => 1});
224
.Ve
225
.PP
226
dbi_options is used when you connect database by using connect.
227
.Sh "prepare"
228
.IX Subsection "prepare"
229
.Vb 1
230
\&    $sth = $dbi->prepare($sql);
231
.Ve
232
.PP
233
This method is same as DBI::prepare
234
.Sh "do"
235
.IX Subsection "do"
236
.Vb 1
237
\&    $dbi->do($sql, @bind_values);
238
.Ve
239
.PP
240
This method is same as DBI::do
241
.Sh "sql_template"
242
.IX Subsection "sql_template"
243
.Vb 3
244
\&    # Set and get SQL::Template object
245
\&    $self         = $dbi->sql_template($sql_template);
246
\&    $sql_template = $dbi->sql_template;
247
.Ve
248
.PP
249
.Vb 2
250
\&    # Sample
251
\&    $dbi->sql_template(DBI::Cutom::SQL::Template->new);
252
.Ve
253
.Sh "filters"
254
.IX Subsection "filters"
255
.Vb 3
256
\&    # Set and get filters
257
\&    $self    = $dbi->filters($filters);
258
\&    $filters = $dbi->filters;
259
.Ve
260
.Sh "formats"
261
.IX Subsection "formats"
262
.Vb 3
263
\&    # Set and get formats
264
\&    $self    = $dbi->formats($formats);
265
\&    $formats = $dbi->formats;
266
.Ve
267
.Sh "bind_filter"
268
.IX Subsection "bind_filter"
269
.Vb 3
270
\&    # Set and get binding filter
271
\&    $self        = $dbi->bind_filter($bind_filter);
272
\&    $bind_filter = $dbi->bind_filter
273
.Ve
274
.PP
275
.Vb 2
276
\&    # Sample
277
\&    $dbi->bind_filter($self->filters->{default_bind_filter});
278
.Ve
279
.PP
280
you can get \s-1DBI\s0 database handle if you need.
281
.Sh "fetch_filter"
282
.IX Subsection "fetch_filter"
283
.Vb 3
284
\&    # Set and get Fetch filter
285
\&    $self         = $dbi->fetch_filter($fetch_filter);
286
\&    $fetch_filter = $dbi->fetch_filter;
287
.Ve
288
.PP
289
.Vb 2
290
\&    # Sample
291
\&    $dbi->fetch_filter($self->filters->{default_fetch_filter});
292
.Ve
293
.Sh "no_bind_filters"
294
.IX Subsection "no_bind_filters"
295
.Vb 3
296
\&    # Set and get no filter keys when binding
297
\&    $self            = $dbi->no_bind_filters($no_bind_filters);
298
\&    $no_bind_filters = $dbi->no_bind_filters;
299
.Ve
300
.Sh "no_fetch_filters"
301
.IX Subsection "no_fetch_filters"
302
.Vb 3
303
\&    # Set and get no filter keys when fetching
304
\&    $self             = $dbi->no_fetch_filters($no_fetch_filters);
305
\&    $no_fetch_filters = $dbi->no_fetch_filters;
306
.Ve
307
.Sh "result_class"
308
.IX Subsection "result_class"
309
.Vb 3
310
\&    # Set and get resultset class
311
\&    $self         = $dbi->result_class($result_class);
312
\&    $result_class = $dbi->result_class;
313
.Ve
314
.PP
315
.Vb 2
316
\&    # Sample
317
\&    $dbi->result_class('DBIx::Custom::Result');
318
.Ve
319
.Sh "dbh"
320
.IX Subsection "dbh"
321
.Vb 2
322
\&    # Get database handle
323
\&    $dbh = $self->dbh;
324
.Ve
325
.SH "METHODS"
326
.IX Header "METHODS"
327
.Sh "connect"
328
.IX Subsection "connect"
329
.Vb 2
330
\&    # Connect to database
331
\&    $self = $dbi->connect;
332
.Ve
333
.PP
334
.Vb 4
335
\&    # Sample
336
\&    $dbi = DBIx::Custom->new(user => 'taro', password => 'lji8(', 
337
\&                            data_soruce => "dbi:mysql:dbname=$database");
338
\&    $dbi->connect;
339
.Ve
340
.Sh "disconnect"
341
.IX Subsection "disconnect"
342
.Vb 2
343
\&    # Disconnect database
344
\&    $dbi->disconnect;
345
.Ve
346
.PP
347
If database is already disconnected, this method do noting.
348
.Sh "reconnect"
349
.IX Subsection "reconnect"
350
.Vb 2
351
\&    # Reconnect
352
\&    $dbi->reconnect;
353
.Ve
354
.Sh "connected"
355
.IX Subsection "connected"
356
.Vb 2
357
\&    # Check connected
358
\&    $dbi->connected
359
.Ve
360
.Sh "filter_off"
361
.IX Subsection "filter_off"
362
.Vb 2
363
\&    # bind_filter and fitch_filter off
364
\&    $self->filter_off;
365
.Ve
366
.PP
367
This is equeal to
368
.PP
369
.Vb 2
370
\&    $self->bind_filter(undef);
371
\&    $self->fetch_filter(undef);
372
.Ve
373
.Sh "add_filter"
374
.IX Subsection "add_filter"
375
.Vb 3
376
\&    # Add filter (hash ref or hash can be recieve)
377
\&    $self = $dbi->add_filter({$filter_name => $filter, ...});
378
\&    $self = $dbi->add_filter($filetr_name => $filter, ...);
379
.Ve
380
.PP
381
.Vb 19
382
\&    # Sample
383
\&    $dbi->add_filter(
384
\&        decode_utf8 => sub {
385
\&            my ($key, $value, $table, $column) = @_;
386
\&            return Encode::decode('UTF-8', $value);
387
\&        },
388
\&        datetime_to_string => sub {
389
\&            my ($key, $value, $table, $column) = @_;
390
\&            return $value->strftime('%Y-%m-%d %H:%M:%S')
391
\&        },
392
\&        default_bind_filter => sub {
393
\&            my ($key, $value, $table, $column) = @_;
394
\&            if (ref $value eq 'Time::Piece') {
395
\&                return $dbi->filters->{datetime_to_string}->($value);
396
\&            }
397
\&            else {
398
\&                return $dbi->filters->{decode_utf8}->($value);
399
\&            }
400
\&        },
401
.Ve
402
.PP
403
.Vb 18
404
\&        encode_utf8 => sub {
405
\&            my ($key, $value) = @_;
406
\&            return Encode::encode('UTF-8', $value);
407
\&        },
408
\&        string_to_datetime => sub {
409
\&            my ($key, $value) = @_;
410
\&            return DateTime::Format::MySQL->parse_datetime($value);
411
\&        },
412
\&        default_fetch_filter => sub {
413
\&            my ($key, $value, $type, $sth, $i) = @_;
414
\&            if ($type eq 'DATETIME') {
415
\&                return $dbi->filters->{string_to_datetime}->($value);
416
\&            }
417
\&            else {
418
\&                return $dbi->filters->{encode_utf8}->($value);
419
\&            }
420
\&        }
421
\&    );
422
.Ve
423
.PP
424
add_filter add filter to filters
425
.Sh "add_format"
426
.IX Subsection "add_format"
427
.Vb 1
428
\&    $dbi->add_format(date => '%Y:%m:%d');
429
.Ve
430
.Sh "create_query"
431
.IX Subsection "create_query"
432
.Vb 2
433
\&    # Create Query object from SQL template
434
\&    my $query = $dbi->create_query($template);
435
.Ve
436
.Sh "execute"
437
.IX Subsection "execute"
438
.Vb 3
439
\&    # Parse SQL template and execute SQL
440
\&    $result = $dbi->query($query, $params);
441
\&    $result = $dbi->query($template, $params); # Shorcut
442
.Ve
443
.PP
444
.Vb 3
445
\&    # Sample
446
\&    $result = $dbi->query("select * from authors where {= name} and {= age}", 
447
\&                          {author => 'taro', age => 19});
448
.Ve
449
.PP
450
.Vb 3
451
\&    while (my @row = $result->fetch) {
452
\&        # do something
453
\&    }
454
.Ve
455
.PP
456
See also DBIx::Custom::SQL::Template
457
.Sh "run_transaction"
458
.IX Subsection "run_transaction"
459
.Vb 4
460
\&    # Run transaction
461
\&    $dbi->run_transaction(sub {
462
\&        # do something
463
\&    });
464
.Ve
465
.PP
466
If transaction is success, commit is execute. 
467
If tranzation is died, rollback is execute.
468
.Sh "insert"
469
.IX Subsection "insert"
470
.Vb 2
471
\&    # Insert
472
\&    $dbi->insert($table, $insert_values);
473
.Ve
474
.PP
475
.Vb 2
476
\&    # Sample
477
\&    $dbi->insert('books', {title => 'Perl', author => 'Taro'});
478
.Ve
479
.Sh "update"
480
.IX Subsection "update"
481
.Vb 2
482
\&    # Update
483
\&    $dbi->update($table, $update_values, $where);
484
.Ve
485
.PP
486
.Vb 2
487
\&    # Sample
488
\&    $dbi->update('books', {title => 'Perl', author => 'Taro'}, {id => 5});
489
.Ve
490
.Sh "update_all"
491
.IX Subsection "update_all"
492
.Vb 2
493
\&    # Update all rows
494
\&    $dbi->update($table, $updat_values);
495
.Ve
496
.Sh "delete"
497
.IX Subsection "delete"
498
.Vb 2
499
\&    # Delete
500
\&    $dbi->delete($table, $where);
501
.Ve
502
.PP
503
.Vb 2
504
\&    # Sample
505
\&    $dbi->delete('Books', {id => 5});
506
.Ve
507
.Sh "delete_all"
508
.IX Subsection "delete_all"
509
.Vb 2
510
\&    # Delete all rows
511
\&    $dbi->delete_all($table);
512
.Ve
513
.Sh "last_insert_id"
514
.IX Subsection "last_insert_id"
515
.Vb 2
516
\&    # Get last insert id
517
\&    $last_insert_id = $dbi->last_insert_id;
518
.Ve
519
.PP
520
This method is same as \s-1DBI\s0 last_insert_id;
521
.Sh "select"
522
.IX Subsection "select"
523
.Vb 8
524
\&    # Select
525
\&    $dbi->select(
526
\&        $table,                # must be string or array;
527
\&        [@$columns],           # must be array reference. this is optional
528
\&        {%$where_params},      # must be hash reference.  this is optional
529
\&        $append_statement,     # must be string.          this is optional
530
\&        $query_edit_callback   # must be code reference.  this is optional
531
\&    );
532
.Ve
533
.PP
534
.Vb 13
535
\&    # Sample
536
\&    $dbi->select(
537
\&        'Books',
538
\&        ['title', 'author'],
539
\&        {id => 1},
540
\&        "for update",
541
\&        sub {
542
\&            my $query = shift;
543
\&            $query->bind_filter(sub {
544
\&                # ...
545
\&            });
546
\&        }
547
\&    );
548
.Ve
549
.PP
550
.Vb 7
551
\&    # The way to join multi tables
552
\&    $dbi->select(
553
\&        ['table1', 'table2'],
554
\&        ['table1.id as table1_id', 'title'],
555
\&        {table1.id => 1},
556
\&        "where table1.id = table2.id",
557
\&    );
558
.Ve
559
.SH "Class Accessors"
560
.IX Header "Class Accessors"
561
.Sh "query_cache_max"
562
.IX Subsection "query_cache_max"
563
.Vb 3
564
\&    # Max query cache count
565
\&    $class           = $class->query_cache_max($query_cache_max);
566
\&    $query_cache_max = $class->query_cache_max;
567
.Ve
568
.PP
569
.Vb 2
570
\&    # Sample
571
\&    DBIx::Custom->query_cache_max(50);
572
.Ve
573
.SH "CAUTION"
574
.IX Header "CAUTION"
575
DBIx::Custom have \s-1DIB\s0 object internal.
576
This module is work well in the following \s-1DBI\s0 condition.
577
.PP
578
.Vb 2
579
\&    1. AutoCommit is true
580
\&    2. RaiseError is true
581
.Ve
582
.PP
583
By default, Both AutoCommit and RaiseError is true.
584
You must not change these mode not to damage your data.
585
.PP
586
If you change these mode, 
587
you cannot get correct error message, 
588
or run_transaction may fail.
589
.SH "AUTHOR"
590
.IX Header "AUTHOR"
591
Yuki Kimoto, \f(CW\*(C`<kimoto.yuki at gmail.com>\*(C'\fR
592
.PP
593
Github <http://github.com/yuki\-kimoto>
594
.SH "COPYRIGHT & LICENSE"
595
.IX Header "COPYRIGHT & LICENSE"
596
Copyright 2009 Yuki Kimoto, all rights reserved.
597
.PP
598
This program is free software; you can redistribute it and/or modify it
599
under the same terms as Perl itself.