• v1, Beta 10 Pre-Release

    danieljsummers released this 2024-09-27 02:30:09 +00:00 | 11 commits to main since this release

    Lots of good stuff here!

    • There are two new field comparisons; in implements an IN comparison against a field, and inArray does the same thing for fields that are themselves JSON arrays.
    • The Find functions (except byId) now support an array of Fields, as their last parameter, which will be used to order the results. There is also a new Field::named() function which can be used to create field definitions for this purpose. These names follow the same rules as other field names (use "a.b.c" for nested fields), but they support other features as well.
      • To sort descending, include DESC in the name (ex. Field::named('code DESC')).
      • To specify a null clause, include it as well (ex. Field::named('example NULLS FIRST')).
      • To sort the field as a number, prefix the field name with n: (ex. Field::named('n:ranking')). PostgreSQL will cast the field to a number, while SQLite will do its usual best-guess.
      • To sort case-insensitively, prefix the field name with i: (ex. Field::named('i:comment')). SQLite's default is case-sensitive sorting, with uppercase values first. PostgreSQL's behavior is based on libraries in the underlying operating system; some are case-insensitive by default, but others (particularly Mac OS) are case-sensitive.
    • The names of the comparisons in Field constructor functions are now spelled out (ex. Field::equal instead of Field::EQ). The two-character versions remain as aliases, so this will not break existing code.
    • The project now comes back clean for PHPStan level 6, and had some changes flagged on higher levels. One of these changes may fix an issue where IDEs were not picking up the generic type coming from DocumentList->items().
    Downloads
  • v1, Beta 9 Pre-Release

    danieljsummers released this 2024-07-29 20:59:59 +00:00 | 12 commits to main since this release

    This release mostly picks up the updated option/result library. However, the breaking change from beta8 that dropped getOrThrow() from the Options returned from this library is no longer an issue; this library update implements the method.

    Downloads
  • v1, Beta 8 Pre-Release

    danieljsummers released this 2024-07-29 00:23:07 +00:00 | 13 commits to main since this release

    BREAKING CHANGE
    The Option implementation has been swapped from PhpOption to BitBadger\InspiredByFSharp. There are a few ways to fix syntax errors that may be encountered:

    • The new library's Option instances have a toPhpOption() method; add that to the end of the option-returning call, and everything should work fine.
    • The new library's Option instances use get() to obtain the value; these calls will not need to change.
    • The new library uses isSome() in place of isDefined(), and isNone() in place of isEmpty().
    • The new library does not (yet) have getOrThrow().

    FEATURE
    DocumentList now has a mapToArray() method; this will map an associative array of key/value pairs from the items in the list. One potential use for this is obtaining a list of IDs and names to generate an HTML <select> element. $lookup = $list->mapToArray(fn($it) => $it->id, fn($it) => $it->name); will generate such an array from a DocumentList instance, with no requirement to create an intermediate array of documents.

    Downloads
  • v1, Beta 7 Pre-Release

    danieljsummers released this 2024-07-25 01:04:23 +00:00 | 17 commits to main since this release

    It's DocumentList's turn in the spotlight.

    • map(callable(TDoc): U) creates a generator which transforms results rather than returning them directly as items() does.
    • iter(callable(TDoc)) iterates the item list without transformations.
    • items() will now throw a DocumentException if it is called after the generator has been consumed.
    • Finally, there is a section in the documentation dedicated to DocumentList and its usage.
    Downloads
  • v1, Beta 6 Pre-Release

    danieljsummers released this 2024-07-22 15:16:08 +00:00 | 19 commits to main since this release

    BREAKING CHANGES:

    • Instead of setting Configuration::$pdoDSN, call Configuration::useDSN() instead. This allows the library to derive its mode based on the data source name (DSN) being set, rather than waiting for the first time a call is made.
    • Related to the above, it should no longer be necessary to set the mode directly. Configuration::$mode is no longer visible.

    I debated making these changes with a beta digit release, but they should be targeted to one or two lines in each dependent application, and I was having trouble justifying the (somewhat convoluted) way it currently worked as I was writing the documentation. Speaking of documentation...

    DOCUMENTATION IS NOW LIVE! This was a "coming during beta testing" to-do list item, and it has now been accomplished. There is much more detail about how to set up and use the library there.

    Downloads
  • v1, Beta 5 Pre-Release

    danieljsummers released this 2024-07-04 17:18:01 +00:00 | 22 commits to main since this release

    This fixes a logic flaw in beta 4 around handling empty arrays.

    Downloads
  • v1, Beta 4 Pre-Release

    danieljsummers released this 2024-07-04 16:12:17 +00:00 | 23 commits to main since this release

    Parameters::json accepts either an object or an array for its value. In beta 3, an array was unaware of pjson annotations, so custom serialization functions were not called. In this release, if the document array has one entry, and that entry is an array of objects that support toJson() (pjson's serialization function), these will now use the pjson-aware serialization.

    This change allows an array of custom items to be replaced using Patch and passing a single key array with these items. Example:

    Patch::byId('doc_table', 'abc123', ['items' => [$item1, $item2, $item3]]);
    

    This also adds the flags passed to the non-pjson json_encode options to it as well (unescaped slashes and unicode).

    Downloads
  • v1, Beta 3 Pre-Release

    danieljsummers released this 2024-06-29 15:53:39 +00:00 | 24 commits to main since this release

    This release implement support for pjson-decorated classes. If the class has a toJson instance method, it will be used to serialize the JSON instead of json_encode, and if the class has a fromJsonString static method, it will be used to deserialize the JSON instead of json_decode and JsonMapper::map. (Both of these are provided by the JsonSerialize trait provided in the pjson project.)

    The conditional nature of this means that you can choose between pjson or the previous behavior. pjson ignores any field not annotated with #[Json]; so, while it provides more control (particularly in deserialization), it also levies requirements on the classes which it will handle.

    Downloads
  • v1, Beta 2 Pre-Release

    danieljsummers released this 2024-06-25 14:56:07 +00:00 | 25 commits to main since this release

    For this release, Custom::single, Find::byId, and Find::firstBy* now return Options rather than a document or false. This better represents a successful or unsuccessful document retrieval attempt, and the Option type provides things like getOrElse() and getOrCall() for handling occasions when the document was not found.

    Downloads
  • v1, Beta 1 Pre-Release

    danieljsummers released this 2024-06-21 13:54:18 +00:00 | 27 commits to main since this release

    This release implements PostgreSQL support. In addition to the byId and byFields functions, PosgtreSQL supports JSON containment queries (the @> operator; these queries are very efficient with GIN indexes) and JSON Path match queries (the @? operator; the string combines a JSON Path with a condition, ex. $.field ? (@ > 7)).

    One consequence of this support is that many more functions throw DocumentException if the database mode is not set; your IDE may complain more when upgrading from 1.0.0-alpha2. The database mode is derived from the PDO data source name, but it can also be set explicitly via Configuration::$mode using a value from the Mode enum.

    Downloads