1Padre::DB::History(3) User Contributed Perl DocumentationPadre::DB::History(3)
2
3
4
6 Padre::DB::History - Padre::DB class for the history table
7
9 TO BE COMPLETED
10
12 TO BE COMPLETED
13
15 base
16 # Returns 'Padre::DB'
17 my $namespace = Padre::DB::History->base;
18
19 Normally you will only need to work directly with a table class, and
20 only with one ORLite package.
21
22 However, if for some reason you need to work with multiple ORLite
23 packages at the same time without hardcoding the root namespace all the
24 time, you can determine the root namespace from an object or table
25 class with the "base" method.
26
27 table
28 # Returns 'history'
29 print Padre::DB::History->table;
30
31 While you should not need the name of table for any simple operations,
32 from time to time you may need it programatically. If you do need it,
33 you can use the "table" method to get the table name.
34
35 load
36 my $object = Padre::DB::History->load( $id );
37
38 If your table has single column primary key, a "load" method will be
39 generated in the class. If there is no primary key, the method is not
40 created.
41
42 The "load" method provides a shortcut mechanism for fetching a single
43 object based on the value of the primary key. However it should only be
44 used for cases where your code trusts the record to already exists.
45
46 It returns a "Padre::DB::History" object, or throws an exception if the
47 object does not exist.
48
49 select
50 # Get all objects in list context
51 my @list = Padre::DB::History->select;
52
53 # Get a subset of objects in scalar context
54 my $array_ref = Padre::DB::History->select(
55 'where id > ? order by id',
56 1000,
57 );
58
59 The "select" method executes a typical SQL "SELECT" query on the
60 history table.
61
62 It takes an optional argument of a SQL phrase to be added after the
63 "FROM history" section of the query, followed by variables to be bound
64 to the placeholders in the SQL phrase. Any SQL that is compatible with
65 SQLite can be used in the parameter.
66
67 Returns a list of Padre::DB::History objects when called in list
68 context, or a reference to an "ARRAY" of Padre::DB::History objects
69 when called in scalar context.
70
71 Throws an exception on error, typically directly from the DBI layer.
72
73 iterate
74 Padre::DB::History->iterate( sub {
75 print $_->id . "\n";
76 } );
77
78 The "iterate" method enables the processing of large tables one record
79 at a time without loading having to them all into memory in advance.
80
81 This plays well to the strength of SQLite, allowing it to do the work
82 of loading arbitrarily large stream of records from disk while
83 retaining the full power of Perl when processing the records.
84
85 The last argument to "iterate" must be a subroutine reference that will
86 be called for each element in the list, with the object provided in the
87 topic variable $_.
88
89 This makes the "iterate" code fragment above functionally equivalent to
90 the following, except with an O(1) memory cost instead of O(n).
91
92 foreach ( Padre::DB::History->select ) {
93 print $_->id . "\n";
94 }
95
96 You can filter the list via SQL in the same way you can with "select".
97
98 Padre::DB::History->iterate(
99 'order by ?', 'id',
100 sub {
101 print $_->id . "\n";
102 }
103 );
104
105 You can also use it in raw form from the root namespace for better
106 control. Using this form also allows for the use of arbitrarily
107 complex queries, including joins. Instead of being objects, rows are
108 provided as "ARRAY" references when used in this form.
109
110 Padre::DB->iterate(
111 'select name from history order by id',
112 sub {
113 print $_->[0] . "\n";
114 }
115 );
116
117 count
118 # How many objects are in the table
119 my $rows = Padre::DB::History->count;
120
121 # How many objects
122 my $small = Padre::DB::History->count(
123 'where id > ?',
124 1000,
125 );
126
127 The "count" method executes a "SELECT COUNT(*)" query on the history
128 table.
129
130 It takes an optional argument of a SQL phrase to be added after the
131 "FROM history" section of the query, followed by variables to be bound
132 to the placeholders in the SQL phrase. Any SQL that is compatible with
133 SQLite can be used in the parameter.
134
135 Returns the number of objects that match the condition.
136
137 Throws an exception on error, typically directly from the DBI layer.
138
139 new
140 TO BE COMPLETED
141
142 The "new" constructor is used to create a new abstract object that is
143 not (yet) written to the database.
144
145 Returns a new Padre::DB::History object.
146
147 create
148 my $object = Padre::DB::History->create(
149
150 id => 'value',
151
152 type => 'value',
153
154 name => 'value',
155
156 );
157
158 The "create" constructor is a one-step combination of "new" and
159 "insert" that takes the column parameters, creates a new
160 Padre::DB::History object, inserts the appropriate row into the history
161 table, and then returns the object.
162
163 If the primary key column "id" is not provided to the constructor (or
164 it is false) the object returned will have "id" set to the new unique
165 identifier.
166
167 Returns a new history object, or throws an exception on error,
168 typically from the DBI layer.
169
170 insert
171 $object->insert;
172
173 The "insert" method commits a new object (created with the "new"
174 method) into the database.
175
176 If a the primary key column "id" is not provided to the constructor (or
177 it is false) the object returned will have "id" set to the new unique
178 identifier.
179
180 Returns the object itself as a convenience, or throws an exception on
181 error, typically from the DBI layer.
182
183 delete
184 # Delete a single instantiated object
185 $object->delete;
186
187 # Delete multiple rows from the history table
188 Padre::DB::History->delete('where id > ?', 1000);
189
190 The "delete" method can be used in a class form and an instance form.
191
192 When used on an existing Padre::DB::History instance, the "delete"
193 method removes that specific instance from the "history", leaving the
194 object intact for you to deal with post-delete actions as you wish.
195
196 When used as a class method, it takes a compulsory argument of a SQL
197 phrase to be added after the "DELETE FROM history" section of the
198 query, followed by variables to be bound to the placeholders in the SQL
199 phrase. Any SQL that is compatible with SQLite can be used in the
200 parameter.
201
202 Returns true on success or throws an exception on error, or if you
203 attempt to call delete without a SQL condition phrase.
204
205 truncate
206 # Delete all records in the history table
207 Padre::DB::History->truncate;
208
209 To prevent the common and extremely dangerous error case where deletion
210 is called accidentally without providing a condition, the use of the
211 "delete" method without a specific condition is forbidden.
212
213 Instead, the distinct method "truncate" is provided to delete all
214 records in a table with specific intent.
215
216 Returns true, or throws an exception on error.
217
219 id
220 if ( $object->id ) {
221 print "Object has been inserted\n";
222 } else {
223 print "Object has not been inserted\n";
224 }
225
226 Returns true, or throws an exception on error.
227
228 REMAINING ACCESSORS TO BE COMPLETED
229
231 The history table was originally created with the following SQL
232 command.
233
234 CREATE TABLE history (
235 id INTEGER PRIMARY KEY,
236 type VARCHAR(255),
237 name VARCHAR(255)
238 )
239
241 Padre::DB::History is part of the Padre::DB API.
242
243 See the documentation for Padre::DB for more information.
244
246 Adam Kennedy <adamk@cpan.org>
247
249 Copyright 2008-2011 The Padre development team as listed in Padre.pm.
250
251 This program is free software; you can redistribute it and/or modify it
252 under the same terms as Perl itself.
253
254 The full text of the license can be found in the LICENSE file included
255 with this module.
256
257
258
259perl v5.28.0 2011-08-16 Padre::DB::History(3)