goldfinch/silverstripe-jsontext
Composer 安装命令:
composer require goldfinch/silverstripe-jsontext
包简介
JSON storage, querying and modification.
关键字:
README 文档
README
- SS5 compatible fork of phptek/silverstripe-jsontext
Exposes a complete API that allows developers to write-to, and query-from JSON in a dedicated DBField subclass.
In addition, if your project uses the silverstripe/cms package, then all SiteTree objects are automatically extended to allow multiple, arbitrary UI fields as declared in getCMSFields(), to write to a JSON object in a single database field.
Using JSONPath (Think XPath but for JSON) and the module's extensive API, developers can selectively target specific JSON keys for modification.
Requirements
SilverStripe 4
- Use ^2.0
- PHP >=5.6, <=7.1
SilverStripe 3
- Use ^1.0
- PHP >=5.4, <7.0
Features
- Store JSON "object-strings" in a JSON-specific
DBFieldsubclass. - Query stored JSON via simple accessors:
first(),last()&nth()or Postgres-like operators:->,->>&#>or even JSONPath expressions. - Selectively return query-results as
JSON,Arrayor cast to SilverStripe'sDBVarchar,DBInt,DBFloatorDBBooleanobjects. - Selectively update portions of stored JSON using JSONPath expressions.
- Selectively transform one or more CMS input fields, to write to a single JSON store.
Introduction
The module exposes a fully featured JSON query and update API allowing developers to use XPath-like queries via JSONPath or Postgres' JSON operators (with some differences, see below) to query and update JSON data.
Why?
Project scenarios where storing 10s of terse configuration parameters as Booleans and Ints in separate database columns just seems crazy.
When all you wanted was a simple key / value store but didn't want to muck about with the overhead of an RDBMS and a NOSQL DB.
That Postgres, MySQL, Oracle and MSSQL 2016 all have, or at time of writing, are planning to have, Database level JSON field-types. This module plugs the gap for users of RDBMS' without native JSON support, while offering the a convenient scaffold on top of which native JSON support could be built.
Postgres
In Postgres both the -> and ->> operators act as string and integer key matchers on a JSON array or JSON object respectively. The module
however treats both source types the same - they are after all both JSON so -> is used as an Integer Matcher and ->> as a String Matcher
regardless of the "type" of source JSON stored. The #> Path Matcher operator can act as an object or a text matcher, but the module wishes to simplify things and as such
the #> operator is just a simple path matcher.
Return types
Regardless of the type of query you can set what type you'd like the data returned in via the setReturnType() method on a query by query basis.
Legitimate types are:
- JSON
- Array
- SilverStripe
If using SilverStripe as the return type, the module will automatically cast the result(s) to one of SilverStripe's DBObject subtypes:
DBBooleanDBIntDBFloatDBVarchar
If there are multiple results from a query, the output will be an indexed array containing a single-value array for each result found.
The module also allows developers to selectively update all, or just parts of the source JSON, via JSONPath expressions passed
to an overloaded setValue() method.
See the usage docs for examples of JSONPath and Postgres querying and updating.
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 native JSON operators at or below the level of the ORM. 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.
Installation
#> composer require phptek/jsontext
Configuration
See: Configuration Docs.
Usage
See: Usage Docs.
Contributing
If you've been using Postgres or MySQL with its JSON functions for some time, I'm keen to hear from you. Some simple failing tests would be most welcome.
See: CONTRIBUTING.md.
Reporting an issue
Please include all details, no matter how small. If it were your module, what would you need to know from a bug/feature request? :-)
Credits
- Axel Anceau for his packaging-up of the pretty amazing JSONPath implementation by Stefan Goessner
- Stefan Goessner for the original work on JSONPath dating back to 2005!
Author
Russell Michell 2016-2018 russ@theruss.com
TODO
- Add missing
prepValueForDB()toJSONTextclass. - See official list of issues on GitHub.
Support Me
If you like what you see, support me! I accept Bitcoin:
|
|
| 3KxmqFeVWoigjvXZoLGnoNzvEwnDq3dZ8Q |
goldfinch/silverstripe-jsontext 适用场景与选型建议
goldfinch/silverstripe-jsontext 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.49k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「text」 「query」 「postgres」 「multi」 「silverstripe」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 goldfinch/silverstripe-jsontext 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 goldfinch/silverstripe-jsontext 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 goldfinch/silverstripe-jsontext 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
Query filtering in your frontend
Anax Database Active Record module for model classes.
A package to cast json fields, each sub-keys is castable
统计信息
- 总下载量: 2.49k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 9
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2023-11-14