Download the PHP package friedolinfoerder/wp-activerecord without Composer
On this page you can find all versions of the php package friedolinfoerder/wp-activerecord. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download friedolinfoerder/wp-activerecord
More information about friedolinfoerder/wp-activerecord
Files in friedolinfoerder/wp-activerecord
Package wp-activerecord
Short Description An ActiveRecord implementation for WordPress
License MIT
Homepage https://github.com/friedolinfoerder/wp-activerecord
Informations about the package wp-activerecord
WordPress ActiveRecord
WordPress ActiveRecord implements the active record pattern to easily retrieve, update and delete rows of database tables without struggling with raw SQL query strings.
The goal of this library is to provide a small but yet powerful ORM for the CMS WordPress, which should be easy to implement. Therefore it only consists of two classes: ActiveRecord
and Query
:
- The
ActiveRecord
class maps rows to object instances and the columns to object properties. - The
Query
class provides a fluent interface to create sql queries.
Installation
Usage
You can use the library in your plugin or directly in your functions.php
file. All you have to do is to require the ActiveRecord
class and define your model classes (e.g. Slideshow
):
With this you can create new rows, update and save them like this:
API
- Class
ActiveRecord
- Static properties
- Property
$casts
- Property
- Static methods
- Method
create([$attributes])
- Method
delete_by_id($id)
- Method
get([$id])
- Method
get_{type}_by_{column}($value [, $...])
- Method
get_table_name()
- Method
insert($data)
- Method
query()
- Method
update($column [, $value])
- Method
wpdb()
- Method
- Instance methods
- Method
delete()
- Method
save()
- Method
- Event methods
- Method
save_pre($isNew)
- Method
save_post($isNew)
- Method
delete_pre()
- Method
delete_post()
- Method
- Static properties
- Class
Query
- Static methods
- Method
wpdb()
- Method
- Instance methods
- Method
select([$...])
- Method
delete()
- Method
update([$column [, $value]])
- Method
set($column [, $value])
- Method
insert($data)
- Method
where($column [, $type_or_value [, $value]])
- Method
and_where($column [, $type_or_value [, $value]])
- Method
or_where($column [, $type_or_value [, $value]])
- Method
group_by($column [, $order])
- Method
having($column [, $type_or_value [, $value]])
- Method
and_having($column [, $type_or_value [, $value]])
- Method
or_having($column [, $type_or_value [, $value]])
- Method
order_by($column [, $order])
- Method
limit($limit)
- Method
offset($offset)
- Method
join($table, $attribute, $foreign_attribute [, $type])
- Method
sql()
- Method
get_results()
- Method
get_row()
- Method
get_col()
- Method
get_var()
- Method
get()
- Method
get_one()
- Method
execute()
- Method
- Static methods
Class ActiveRecord
Static Properties
Property $casts
Cast row values to native types.
Example:
Static Methods
Method create([$attributes])
Create a model with an array of attributes
Example:
Method delete_by_id($id)
Delete a row by id
Example:
Method get([$id])
Get all model instances or a model instance by id
Example:
Method get_{type}_by_{column}($value [, $...])
Dynmamic finder method: Get a var, rows, results or model instances
Example:
Method get_table_name()
Get the table name
Example:
Method insert($data)
Insert one or multiple rows into the database
Example:
Method query()
Get a query instance
Example:
Method update($column [, $value])
Shortcut method for creating a query instance and calling update on it
Example:
Method wpdb()
Get the wpdb instance
Example:
Instance methods
Method delete()
Delete the model
Example:
Method save()
Save the model
Example:
Event methods
Method save_pre($isNew)
Called before saving the model
Example:
Method save_post($isNew)
Called after saving the model
Example:
Method delete_pre()
Called before deleting the model
Example:
Method delete_post()
Called after deleting the model
Example:
Class Query
Static Methods
Method wpdb()
Get the wpdb instance
Example:
Instance Methods
Select rows
Method select([$...])
Example:
Method delete()
Delete rows
Example:
Method update([$column [, $value]])
Update rows (Alias for \wp_activerecord\Query::set)
Example:
Method set($column [, $value])
Set columns, which should be updated
Example:
Method insert($data)
Insert rows
Example:
Method where($column [, $type_or_value [, $value]])
Add a where condition
Example:
Method and_where($column [, $type_or_value [, $value]])
Alias for where
.
Method or_where($column [, $type_or_value [, $value]])
Alias for where
, but adds a new group to the where clause, which will be added with the keyword OR
Method group_by($column [, $order])
Add a group by section
Example:
Method having($column [, $type_or_value [, $value]])
Add a having condition
Example:
Method and_having($column [, $type_or_value [, $value]])
Alias for having
.
Method or_having($column [, $type_or_value [, $value]])
Alias for having
, but adds a new group to the having clause, which will be added with the keyword OR
Method order_by($column [, $order])
Add a order by section
Example:
Method limit($limit)
Add a limit
Example:
Method offset($offset)
Add a offset
Example:
Method join($table, $attribute, $foreign_attribute [, $type])
Add a join condition
Example:
Method sql()
Create the final sql statement
Example:
Method get_results()
Get the results of the query
Example:
Method get_row()
Get the row of the query
Example:
Method get_col()
Get the column of the query
Example:
Method get_var()
Get the value of the query
Example:
Method get()
Get the results of the query as an array of model instances
Example:
Method get_one()
Get the results of the query as a model instances
Example:
Method execute()
Execute the query
Example:
License
This code is licensed under the MIT license.