-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MINOR: Updated README and separated sections into own markdown files in
own docs dir.
- Loading branch information
Showing
3 changed files
with
76 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Configuration | ||
|
||
As the [README](../../README.md) suggests, you can put the module into `postgres` (The default) or `mysql` mode, but only `postgres` works at this time. You can | ||
do this via standard SS config in your project's `mysite/_config/config.yml` file thus: | ||
|
||
JSONText: | ||
backend: postgres | ||
|
||
|
||
Note: The module default is to use `postgres` which is also the only backend that will work at the moment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Usage | ||
|
||
The module can be put into `mysql` or `postgres` query mode using SS config thus: | ||
|
||
|
||
JSONText: | ||
backend: mysql | ||
|
||
You can also stipulate what format you want your query results back as; JSON or Array, thus: | ||
|
||
// JSON | ||
$field = JSONText\Fields\JSONText::create('MyJSON'); | ||
$field->setValue('{"a": {"b":{"c": "foo"}}}'); | ||
$field->setReturnType('json'); | ||
|
||
// Array | ||
$field = JSONText\Fields\JSONText::create('MyJSON'); | ||
$field->setValue('{"a": {"b":{"c": "foo"}}}'); | ||
$field->setReturnType('array'); | ||
|
||
## Examples | ||
|
||
In the examples below, if you pass invalid queries or malformed JSON (where applicable) an exception is thrown. | ||
|
||
|
||
class MyDataObject extends DataObject | ||
{ | ||
|
||
private static $db = [ | ||
'MyJSON' => 'JSONText' | ||
]; | ||
|
||
/* | ||
* Returns the first key=>value pair found in the source JSON | ||
*/ | ||
public function getFirstJSONVal() | ||
{ | ||
return $this->dbObject('MyJSON')->first(); | ||
} | ||
|
||
/* | ||
* Returns the last key=>value pair found in the source JSON | ||
*/ | ||
public function getLastJSONVal() | ||
{ | ||
return $this->dbObject('MyJSON')->last(); | ||
} | ||
|
||
/* | ||
* Returns the Nth key=>value pair found in the source JSON (Top-level only) | ||
* For nested hashes use the int matcher ("->") or string matcher ("->>"). | ||
*/ | ||
public function getNthJSONVal($n) | ||
{ |