Download the PHP package cuppett/cakephp-pg_utils without Composer
On this page you can find all versions of the php package cuppett/cakephp-pg_utils. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cuppett/cakephp-pg_utils
More information about cuppett/cakephp-pg_utils
Files in cuppett/cakephp-pg_utils
Package cakephp-pg_utils
Short Description CakePHP PostgreSQL Utilities
License MIT
Homepage https://github.com/cuppett/cakephp-pg_utils
Informations about the package cakephp-pg_utils
CakePHP PostgreSQL Utilities
PgUtils provides a small set of behaviors useful for working with Postgres datasources.
Requirements
The master branch has the following requirements:
- CakePHP 2.2.0 or greater.
- PHP 5.3.0 or greater.
Features
- Search behavior - Performing text searches on models. Allows sophisticated full text searches to be performed. Also includes a simplified query parser.
- JSON behavior - Retrieving and storing json datatypes. Values are exploded into associative arrays upon retrieval and collapsed back down on save.
- Array behavior - Retrieving and storing array datatypes. Values are exploded into arrays upon retrieval and collapsed back down on save
- Interval behavior - Retrieving and storing interval datatypes. PHP intervals are converted to ISO8601 format and stored into this special PostgreSQL datatype column.
Installation
- Clone/Copy the files in this directory into
app/Plugin/PgUtils
- Ensure the plugin is loaded in
app/Config/bootstrap.php
by callingCakePlugin::load('PgUtils');
-
To use the IntervalBehavior, you must ensure values are stored/retrieved using iso8601 via your database connection.
- Full text search requires a ts_vector column to be created and maintained. The simplest way is with a trigger.
Using Composer
Ensure require
is present in composer.json
. This will install the plugin into Plugin/AwsUtils
:
Examples
Using Interval/JSON/Array types in a model
If your database table contains interval, json or array types in their definition, you can configure behaviors to help translate them into more PHP-friendly types and values via the afterFind and beforeSave callbacks.
They are configured on the model by identifying the fields to convert. One potential enhancement would be to automatically detect these fields; however, it may be useful to not have all converted automatically as well.
Integrating the search column into your database.
The search behavior requires a ts_vector column to be defined. The column must be maintained separately of the behavior. Here is an example set of SQL to add & update the column when the database is updated:
You can add other columns & weights to the search; you can add a gist or gin index to the table/column to speed up the results; etc.
Using search from your application
In your Model class:
From your Controller:
Then you can display the results in your view like normal.
Potential searches include freeform text such as "cat and dog", "cat or dog", etc. The current set of operators are "and", "or", and "-" to exclude certain terms.
You can also prefix the term with a field name such as "name:cat". From the above setup examples, this will change the query such that only the "A" category will be searched for the term "cat".
Please see the topic Controlling Text Search in the PostgreSQL documentation for more information on these topics. I've tried to expose the most commonly desired knobs for my use cases, but I'm open to other suggestions.
Reporting issues
If you have a problem with PgUtils please open an issue on GitHub.