@@ -314,6 +314,7 @@ API reference
314314
315315.. _fields :
316316
317+ ------
317318Fields
318319------
319320
@@ -343,6 +344,7 @@ guessed type. See :ref:`valid-types` for details on which types are valid.
343344
344345.. _records :
345346
347+ -------
346348Records
347349-------
348350
@@ -367,8 +369,10 @@ Example::
367369 }
368370 ]
369371
372+
370373.. _valid-types :
371374
375+ -----------
372376Field types
373377-----------
374378
@@ -405,34 +409,40 @@ You can find more information about the formatting of dates in the `date/time ty
405409
406410.. _filters :
407411
412+ -------
408413Filters
409414-------
410415
411- Filters specify the fields and values that returned records must match::
416+ Filters are parameters to
417+ :meth: `~ckanext.datastore.logic.action.datastore_search `,
418+ :meth: `~ckanext.datastore.logic.action.datastore_delete ` and
419+ :meth: `~ckanext.datastore.logic.action.datastore_records_delete ` that
420+ specify the fields and values for records to match::
412421
413422 "filters": {
414423 "family_name": "Romano",
415424 "given_name": "Do-Yun"
416425 }
417426
418- This will only return records that match both the ``family_name `` AND
419- ``given_name `` values.
427+ This will only match records where both the ``family_name `` AND
428+ ``given_name `` values match the values given .
420429
421430To match one of multiple values for a field we can use a list::
422431
423432 "filters": {
424433 "paint": ["Black", "Green", "Grey"]
425434 }
426435
427- This will return records that match any of the ``paint `` values to the colors in the list.
436+ This will match records with ``"Black" ``, ``"Green" `` OR ``"Grey" ``
437+ ``paint `` values.
428438
429439
430440.. _advanced_filters :
431441
432442Advanced Filters
433443================
434444
435- CKAN 2.12 and later supports advanced filters: range filter operations and nested AND and
445+ CKAN 2.12 and later support advanced filters: range filter operations and nested AND and
436446OR conditions.
437447
438448Ranges can be specified using filter operations ``lt ``, ``lte ``, ``gt `` or ``gte ``::
@@ -441,15 +451,15 @@ Ranges can be specified using filter operations ``lt``, ``lte``, ``gt`` or ``gte
441451 "age": {"gt": 24}
442452 }
443453
444- This will return all records with age > 24.
454+ This will match all records with age > 24.
445455
446456Filter operations can be combined and even mixed with lists of values::
447457
448458 "filters": {
449459 "year": [2005, {"gte": 2010, "lte": 2019}]
450460 }
451461
452- This will return records with year = 2005 OR between 2010 and 2019.
462+ This will match records with year = 2005 OR between 2010 and 2019.
453463
454464A list filters value may be used to combine filters with an OR instead of an AND::
455465
@@ -458,8 +468,8 @@ A list filters value may be used to combine filters with an OR instead of an AND
458468 {"special": true}
459469 ]
460470
461- This will return records from a table that are either an appetizer OR on special
462- (or both).
471+ This will match records from a table that have either `` course = " appetizer" `` OR
472+ `` special = true `` (or both).
463473
464474``$or `` can be used instead of a field name to group OR conditions within AND conditions::
465475
@@ -471,8 +481,8 @@ This will return records from a table that are either an appetizer OR on special
471481 ]
472482 }
473483
474- This will return records for noise complaints that are unresolved or in progress OR more
475- recent than 2024.
484+ This will match noise complaint records that are unresolved OR in progress, OR
485+ that are more recent than 2024.
476486
477487Field names that begin with ``$ `` must be prefixed with an extra ``$ `` in filters, e.g.
478488a field named ``$AUD `` would be filtered as::
@@ -481,7 +491,8 @@ a field named ``$AUD`` would be filtered as::
481491 "$$AUD": 100
482492 }
483493
484- JSON and array fields can be filtered using an ``eq `` filter operation::
494+ JSON and array fields can be filtered to matching object or list values using an ``eq ``
495+ filter operation::
485496
486497 "filters": {
487498 "seat": {"eq": {"row": 34, "column": "B"}}
@@ -493,22 +504,26 @@ This will return records from a table with a JSON ``seat`` field containing exac
493504``["seafood meal"] ``.
494505
495506
507+ -----------------
496508Search Pagination
497509-----------------
498510
499- Using ``datastore_search `` with ``offset ``-based pagination while retrieving data is
500- common. This works as expected with tables up to around 500k records, but becomes less
511+ Using :meth: `~ckanext.datastore.logic.action.datastore_search `
512+ with the ``offset `` parameter for pagination while retrieving data is common.
513+
514+ This works as expected with tables up to around 500k records, but becomes less
501515efficient with more records. This is due to ``offset `` needing to process the data and
502- only then skip it, which leads to longer and longer query times. In other words, the
503- bigger offset number you have , the more time is required for the query to be processed.
516+ only then skip it, which leads to longer and longer query times. In other words the
517+ bigger offset number you use , the more time is required for the query to be processed.
504518
505- There is an alternative (``keyset `` pagination) that can be used in order to reduce
506- query time speed and as an result process data more quickly. It has one major
507- advantage over ``offset ``: later queries take almost the exact same amount of time
508- as the first ``offset 0 `` (which means no data is skipped).
519+ There is an alternative: `keyset pagination `.
509520
510- In order to use ``keyset `` approach, you'll need to add/update your ``filters `` in
511- ``datastore_search `` and have ``sort `` to match the the filter logic.
521+ Keyset pagination can be used to reduce query time and process data more quickly.
522+ It has one major advantage over ``offset ``: later queries take almost the
523+ exact same amount of time as the first ``offset 0 `` (which means no data is skipped).
524+
525+ In order to use keyset pagination, you'll need to add/update your ``filters `` in
526+ ``datastore_search `` and use ``sort `` to match the the filter logic.
512527
513528For example to generate a keyset paginated query like this::
514529
@@ -529,16 +544,23 @@ Or if we are using keyset paginating in reverse and the last ``_id`` was ``456``
529544We would use ``datastore_search `` parameters like::
530545
531546 "filters": {
532- "_id": {"lt": 123 }
547+ "_id": {"lt": 456 }
533548 },
534549 "sort": "_id desc"
535550
536- To make keyset pagination even easier ``datastore_search `` now automatically returns a
551+ To make keyset pagination easier ``datastore_search `` can return a
537552``next_page `` value with the ``filters `` that are required to retrieve the next page,
538- as long as your results are sorted by the ``_id `` field.
553+ as long as your results are sorted by the ``_id `` field. To generate this value
554+ pass ``"include_next_page": true `` to your ``datastore_search `` call.
555+
556+ If you are already processing the records returned and your records include the
557+ ``_id `` field, it is slightly faster to take the last ``_id `` returned in ``records ``
558+ instead of using ``"include_next_page": true ``.
559+
539560
540561.. _resource-aliases :
541562
563+ ----------------
542564Resource aliases
543565----------------
544566
@@ -547,6 +569,7 @@ A resource in the DataStore can have multiple aliases that are easier to remembe
547569
548570.. _comparison_querying :
549571
572+ ----------------------------------------
550573Comparison of different querying methods
551574----------------------------------------
552575
@@ -564,6 +587,7 @@ The DataStore supports querying with two API endpoints. They are similar but sup
564587
565588.. _db_internals :
566589
590+ ----------------------------------
567591Internal structure of the database
568592----------------------------------
569593
0 commit comments