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