1Padre::DB::Snippets(3)User Contributed Perl DocumentationPadre::DB::Snippets(3)
2
3
4

NAME

6       Padre::DB::Snippets - Padre::DB class for the snippets table
7

DESCRIPTION

9       TO BE COMPLETED
10

METHODS

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

ACCESSORS

220   id
221         if ( $object->id ) {
222             print "Object has been inserted\n";
223         } else {
224             print "Object has not been inserted\n";
225         }
226
227       Returns true, or throws an exception on error.
228
229       REMAINING ACCESSORS TO BE COMPLETED
230

SQL

232       The snippets table was originally created with the following SQL
233       command.
234
235         CREATE TABLE snippets (
236             id INTEGER PRIMARY KEY,
237             mimetype VARCHAR(255),
238             category VARCHAR(255),
239             name VARCHAR(255),
240             snippet TEXT
241         )
242

SUPPORT

244       Padre::DB::Snippets is part of the Padre::DB API.
245
246       See the documentation for Padre::DB for more information.
247

AUTHOR

249       Adam Kennedy <adamk@cpan.org>
250
252       Copyright 2010 Adam Kennedy.
253
254       This program is free software; you can redistribute it and/or modify it
255       under the same terms as Perl itself.
256
257       The full text of the license can be found in the LICENSE file included
258       with this module.
259
260
261
262perl v5.30.1                      2020-01-30            Padre::DB::Snippets(3)
Impressum