rasa-web/propel-postgres-json-behavior

使用Postgres JSON存储复杂数据。

dev-master 2017-04-09 08:51 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:36:29 UTC


README

Build Status Scrutinizer Quality Score Code Coverage

PostgreSQL JSON行为用于propel,此行为仅支持PostgreSQL 9.3及更高版本。

将行为添加到您的build.properties文件中

propel.behavior.postgres_json.class = path.to.vendor.rasa-web.propel-postgres-json-behavior.src.PostgresJsonBehavior

创建您的架构

<database name="json_behavior" defaultIdMethod="native">
    <table name="foo">
        <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
        <column name="name" type="VARCHAR" required="true" />
        <column name="json1" type="VARCHAR" required="true"/>
        <column name="json2" type="VARCHAR" required="true"/>

        <behavior name="postgres_json">
            <parameter name="column_names" value="json1,json2" />
	    <!-- throw exception on get{json}Path functions if the path is not available, 
	    default is false and the result is calculated base on the $default parameter of function -->
	    <parameter name="exception_on_not_found" value="false" />
        </behavior>
    </table>
</database>

构建您的模型,结果SQL中的类型自动更改为JSON。

//Base class
$object->getJson1(); // Get the json1 field in array format (not string)
// If the exception_on_not_found is true then there is an exception if key is not available
$object->getJson1Path("key1.subkey.subkey.lastkey", $default);// get the 'value' {"key":{"subkey":{"subkey":{"lastkey": "value"}}}}
$object->setJson1Path("path.to.key", $value)
// Query class
$objectQuery->filterByJson1Path("a.b.c", "value"); // search for {"a":{"b":{"c":"value"}}}