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