1Padre::DB::HostConfig(3U)ser Contributed Perl DocumentatiPoandre::DB::HostConfig(3)
2
3
4
6 Padre::DB::HostConfig - Padre::DB class for the host_config table
7
9 TO BE COMPLETED
10
12 base
13 # Returns 'Padre::DB'
14 my $namespace = Padre::DB::HostConfig->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 'host_config'
26 print Padre::DB::HostConfig->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::HostConfig->load( $name );
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::HostConfig" 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::HostConfig->select;
49
50 # Get a subset of objects in scalar context
51 my $array_ref = Padre::DB::HostConfig->select(
52 'where name > ? order by name',
53 1000,
54 );
55
56 The "select" method executes a typical SQL "SELECT" query on the
57 host_config table.
58
59 It takes an optional argument of a SQL phrase to be added after the
60 "FROM host_config" section of the query, followed by variables to be
61 bound to the placeholders in the SQL phrase. Any SQL that is compatible
62 with SQLite can be used in the parameter.
63
64 Returns a list of Padre::DB::HostConfig objects when called in list
65 context, or a reference to an "ARRAY" of Padre::DB::HostConfig 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::HostConfig->iterate( sub {
72 print $_->name . "\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::HostConfig->select ) {
90 print $_->name . "\n";
91 }
92
93 You can filter the list via SQL in the same way you can with "select".
94
95 Padre::DB::HostConfig->iterate(
96 'order by ?', 'name',
97 sub {
98 print $_->name . "\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 host_config order by name',
109 sub {
110 print $_->[0] . "\n";
111 }
112 );
113
114 count
115 # How many objects are in the table
116 my $rows = Padre::DB::HostConfig->count;
117
118 # How many objects
119 my $small = Padre::DB::HostConfig->count(
120 'where name > ?',
121 1000,
122 );
123
124 The "count" method executes a "SELECT COUNT(*)" query on the
125 host_config table.
126
127 It takes an optional argument of a SQL phrase to be added after the
128 "FROM host_config" section of the query, followed by variables to be
129 bound to the placeholders in the SQL phrase. Any SQL that is compatible
130 with 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::HostConfig object.
143
144 create
145 my $object = Padre::DB::HostConfig->create(
146
147 name => 'value',
148
149 value => 'value',
150
151 );
152
153 The "create" constructor is a one-step combination of "new" and
154 "insert" that takes the column parameters, creates a new
155 Padre::DB::HostConfig object, inserts the appropriate row into the
156 host_config table, and then returns the object.
157
158 If the primary key column "name" is not provided to the constructor (or
159 it is false) the object returned will have "name" set to the new unique
160 identifier.
161
162 Returns a new host_config object, or throws an exception on error,
163 typically from the DBI layer.
164
165 insert
166 $object->insert;
167
168 The "insert" method commits a new object (created with the "new"
169 method) into the database.
170
171 If a the primary key column "name" is not provided to the constructor
172 (or it is false) the object returned will have "name" set to the new
173 unique identifier.
174
175 Returns the object itself as a convenience, or throws an exception on
176 error, typically from the DBI layer.
177
178 delete
179 # Delete a single instantiated object
180 $object->delete;
181
182 # Delete multiple rows from the host_config table
183 Padre::DB::HostConfig->delete('where name > ?', 1000);
184
185 The "delete" method can be used in a class form and an instance form.
186
187 When used on an existing Padre::DB::HostConfig instance, the "delete"
188 method removes that specific instance from the "host_config", leaving
189 the object intact for you to deal with post-delete actions as you wish.
190
191 When used as a class method, it takes a compulsory argument of a SQL
192 phrase to be added after the "DELETE FROM host_config" section of the
193 query, followed by variables to be bound to the placeholders in the SQL
194 phrase. Any SQL that is compatible with SQLite can be used in the
195 parameter.
196
197 Returns true on success or throws an exception on error, or if you
198 attempt to call delete without a SQL condition phrase.
199
200 truncate
201 # Delete all records in the host_config table
202 Padre::DB::HostConfig->truncate;
203
204 To prevent the common and extremely dangerous error case where deletion
205 is called accidentally without providing a condition, the use of the
206 "delete" method without a specific condition is forbidden.
207
208 Instead, the distinct method "truncate" is provided to delete all
209 records in a table with specific intent.
210
211 Returns true, or throws an exception on error.
212
214 name
215 if ( $object->name ) {
216 print "Object has been inserted\n";
217 } else {
218 print "Object has not been inserted\n";
219 }
220
221 Returns true, or throws an exception on error.
222
223 REMAINING ACCESSORS TO BE COMPLETED
224
226 The host_config table was originally created with the following SQL
227 command.
228
229 CREATE TABLE host_config (
230 name varchar(255) not null primary key,
231 value varchar(255) not null
232 )
233
235 Padre::DB::HostConfig is part of the Padre::DB API.
236
237 See the documentation for Padre::DB for more information.
238
240 Adam Kennedy <adamk@cpan.org>
241
243 Copyright 2008-2011 The Padre development team as listed in Padre.pm.
244
245 This program is free software; you can redistribute it and/or modify it
246 under the same terms as Perl itself.
247
248 The full text of the license can be found in the LICENSE file included
249 with this module.
250
251
252
253perl v5.32.0 2020-07-28 Padre::DB::HostConfig(3)