Skip to content

Commit

Permalink
MINOR: Update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
phptek committed Jun 15, 2016
1 parent 5934b11 commit 053ce8f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ I'm a reasonable man however, and am prepared for a discussion on it, if any wer
Note: This module's query API is based on a relatively simple JSON to array conversion principle.
It does *not* use Postgres' or MySQL's JSON operators at the ORM level. The aim however
is to allow dev's to use their preferred DB's syntax, and to this end you can set
the module into `mysql` or `postgres` mode using SS config, see [Configuration Docs](configuration.md).
the module into `mysql` or `postgres` mode using SS config, see [Configuration Docs](docs/en/configuration.md).

## Installation

Expand All @@ -42,6 +42,10 @@ the module into `mysql` or `postgres` mode using SS config, see [Configuration D

See: [Configuration Docs](docs/en/configuration.md).

## Usage

See: [Usage Docs](docs/en/usage.md).

## Stability

This is currently *alpha software*. At time of writing (June 2016) there is
Expand All @@ -61,10 +65,6 @@ See: [CONTRIBUTING.md](CONTRIBUTING.md).

Please include all details, no matter how small. If it were *your module*, what would you need to know from a bug/reature request? :-)

## Usage

See: [Usage Docs](docs/en/usage.md).

## TODO

* Lose the fugly way that data is queried via `$this->dbObject()`
Expand Down
44 changes: 33 additions & 11 deletions docs/en/usage.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# 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:
You can stipulate what format you want your query results back as via passing one of **json** or **array** to `setReturnType()`, thus:

// JSON
$field = JSONText\Fields\JSONText::create('MyJSON');
Expand All @@ -18,10 +12,7 @@ You can also stipulate what format you want your query results back as; JSON or
$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.

In the examples below, if you pass invalid queries or malformed JSON (where applicable) an instnce of `JSONTextException` is thrown.

class MyDataObject extends DataObject
{
Expand Down Expand Up @@ -52,3 +43,34 @@ In the examples below, if you pass invalid queries or malformed JSON (where appl
*/
public function getNthJSONVal($n)
{
return $this->dbObject('MyJSON')->nth($n);
}
/**
* Returns a key=>value pair based on a strict integer -> key match.
* If a string is passed, an empty array is returned.
*/
public function getNestedByIntKey($int)
{
return $this->dbObject('MyJSON')->query('->', $int);
}
/**
* Returns a key=>value pair based on a strict string -> key match.
* If an integer is passed, an empty array is returned.
*/
public function getNestedByStrKey($str)
{
return $this->dbObject('MyJSON')->query('->>', $str);
}
/**
* Returns a value based on a strict string/int match of the key-as-array
* Given source JSON ala: '{"a": {"b":{"c": "foo"}}}' will return '{"c": "foo"}'
*/
public function getByPathMatch('{"a":"b"}')
{
return $this->dbObject('MyJSON')->query('#>', '{"a":"b"}';
}
}

0 comments on commit 053ce8f

Please sign in to comment.