Skip to content

Action

vds_version_record(resource_id, record_id)

Retrieves all the versions available for a record in a resource. These will be returned as a list of ints in ascending order.

Parameters:

Name Type Description Default
resource_id str

the resource ID

required
record_id str

the record ID

required

Returns:

Type Description
List[int]

a list of versions, or an empty list if the record doesn't exist

Source code in ckanext/versioned_datastore/logic/version/action.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@action(schema.vds_version_record(), helptext.vds_version_record, get=True)
def vds_version_record(resource_id: str, record_id: str) -> List[int]:
    """
    Retrieves all the versions available for a record in a resource. These will be
    returned as a list of ints in ascending order.

    :param resource_id: the resource ID
    :param record_id: the record ID
    :returns: a list of versions, or an empty list if the record doesn't exist
    """
    query = DirectQuery(
        [resource_id],
        None,
        Q('term', **{DocumentField.ID: record_id}),
    )
    request = SearchRequest(query, force_no_version=True)
    response = request.run()
    return sorted(hit.version for hit in response.hits)

vds_version_resource(resource_id)

Returns a list of the available versions for a datastore resource. These will be in ascending order.

Parameters:

Name Type Description Default
resource_id str

the resource ID

required

Returns:

Type Description
List[int]

the versions in ascending order

Source code in ckanext/versioned_datastore/logic/version/action.py
45
46
47
48
49
50
51
52
53
54
55
@action(schema.vds_version_resource(), helptext.vds_version_resource, get=True)
def vds_version_resource(resource_id: str) -> List[int]:
    """
    Returns a list of the available versions for a datastore resource. These will be in
    ascending order.

    :param resource_id: the resource ID
    :returns: the versions in ascending order
    """
    database = get_database(resource_id)
    return database.get_versions()

vds_version_round(resource_id, version=None)

Given a resource ID and a version, rounds the version to the lowest, nearest version of the resource (i.e. rounds it down). If no version parameter is provided, or the provided version parameter higher than the current version of the resource, then the latest version of the resource is returned.

Parameters:

Name Type Description Default
resource_id str

the resource ID

required
version Optional[int]

the version to round (default is None)

None

Returns:

Type Description

the rounded version

Source code in ckanext/versioned_datastore/logic/version/action.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@action(schema.vds_version_round(), helptext.vds_version_round, get=True)
def vds_version_round(resource_id: str, version: Optional[int] = None):
    """
    Given a resource ID and a version, rounds the version to the lowest, nearest version
    of the resource (i.e. rounds it down). If no version parameter is provided, or the
    provided version parameter higher than the current version of the resource, then the
    latest version of the resource is returned.

    :param resource_id: the resource ID
    :param version: the version to round (default is None)
    :returns: the rounded version
    """
    database = get_database(resource_id)
    versions = database.get_versions()

    if version is None or version >= versions[-1]:
        # cap the requested version to the latest version
        return versions[-1]
    elif version < versions[0]:
        # use the requested version if it's lower than the lowest available version
        return version
    else:
        # find the lowest, nearest version to the requested one
        position = bisect.bisect_right(versions, version)
        return versions[position - 1]

vds_version_schema()

Retrieves all the query schema versions that are available.

Returns:

Type Description

a list of query schema versions.

Source code in ckanext/versioned_datastore/logic/version/action.py
15
16
17
18
19
20
21
22
@action(schema.vds_version_schema(), helptext.vds_version_schema, get=True)
def vds_version_schema():
    """
    Retrieves all the query schema versions that are available.

    :returns: a list of query schema versions.
    """
    return get_schema_versions()