tinybase 7.2.0-beta.0 → 7.2.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/queries/index.d.ts +196 -22
- package/@types/queries/with-schemas/index.d.ts +210 -22
- package/@types/ui-react/index.d.ts +285 -0
- package/@types/ui-react/with-schemas/index.d.ts +318 -0
- package/index.js +29 -5
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/queries/index.js +1 -1
- package/min/queries/index.js.gz +0 -0
- package/min/queries/with-schemas/index.js +1 -1
- package/min/queries/with-schemas/index.js.gz +0 -0
- package/min/ui-react/index.js +1 -1
- package/min/ui-react/index.js.gz +0 -0
- package/min/ui-react/with-schemas/index.js +1 -1
- package/min/ui-react/with-schemas/index.js.gz +0 -0
- package/min/ui-react-dom/index.js +1 -1
- package/min/ui-react-dom/index.js.gz +0 -0
- package/min/ui-react-dom/with-schemas/index.js +1 -1
- package/min/ui-react-dom/with-schemas/index.js.gz +0 -0
- package/min/ui-react-inspector/index.js +1 -1
- package/min/ui-react-inspector/index.js.gz +0 -0
- package/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/omni/index.js +131 -24
- package/omni/with-schemas/index.js +131 -24
- package/package.json +1 -1
- package/queries/index.js +41 -5
- package/queries/with-schemas/index.js +41 -5
- package/readme.md +13 -13
- package/releases.md +39 -39
- package/ui-react/index.js +102 -19
- package/ui-react/with-schemas/index.js +102 -19
- package/ui-react-dom/index.js +39 -13
- package/ui-react-dom/with-schemas/index.js +39 -13
- package/ui-react-inspector/index.js +41 -15
- package/ui-react-inspector/with-schemas/index.js +41 -15
- package/with-schemas/index.js +29 -5
|
@@ -19,6 +19,47 @@ import type {
|
|
|
19
19
|
Store,
|
|
20
20
|
} from '../store/index.d.ts';
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* The ParamValue type describes a single param value that can be used in a
|
|
24
|
+
* parameterized query.
|
|
25
|
+
*
|
|
26
|
+
* A ParamValue is similar to a Cell, but params cannot be `undefined`. They
|
|
27
|
+
* must be a JavaScript string, number, boolean, or null.
|
|
28
|
+
* @example
|
|
29
|
+
* ```js
|
|
30
|
+
* import type {ParamValue} from 'tinybase';
|
|
31
|
+
*
|
|
32
|
+
* export const paramValue1: ParamValue = 'dog';
|
|
33
|
+
* export const paramValue2: ParamValue = 5;
|
|
34
|
+
* export const paramValue3: ParamValue = true;
|
|
35
|
+
* export const paramValue4: ParamValue = null;
|
|
36
|
+
* ```
|
|
37
|
+
* @category Params
|
|
38
|
+
* @since v7.2.0
|
|
39
|
+
*/
|
|
40
|
+
export type ParamValue = string | number | boolean | null;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The ParamValues type describes an object of param values, keyed by param Id,
|
|
44
|
+
* used to provide values for a parameterized query.
|
|
45
|
+
*
|
|
46
|
+
* A ParamValues object is provided when setting a query definition with params,
|
|
47
|
+
* or when updating params with the setParamValues method.
|
|
48
|
+
* @example
|
|
49
|
+
* ```js
|
|
50
|
+
* import type {ParamValues} from 'tinybase';
|
|
51
|
+
*
|
|
52
|
+
* export const paramValues: ParamValues = {
|
|
53
|
+
* species: 'dog',
|
|
54
|
+
* minAge: 5,
|
|
55
|
+
* active: true,
|
|
56
|
+
* };
|
|
57
|
+
* ```
|
|
58
|
+
* @category Params
|
|
59
|
+
* @since v7.2.0
|
|
60
|
+
*/
|
|
61
|
+
export type ParamValues = {[paramId: Id]: ParamValue};
|
|
62
|
+
|
|
22
63
|
/**
|
|
23
64
|
* The ResultTable type is the data structure representing the results of a
|
|
24
65
|
* query.
|
|
@@ -258,14 +299,13 @@ export type ResultRowCallback = (
|
|
|
258
299
|
export type ResultCellCallback = (cellId: Id, cell: ResultCell) => void;
|
|
259
300
|
|
|
260
301
|
/**
|
|
261
|
-
* The QueryIdsListener type describes a function that is used to listen
|
|
262
|
-
*
|
|
302
|
+
* The QueryIdsListener type describes a function that is used to listen to
|
|
303
|
+
* Query definitions being added or removed.
|
|
263
304
|
*
|
|
264
|
-
* A QueryIdsListener is provided when using the
|
|
265
|
-
*
|
|
305
|
+
* A QueryIdsListener is provided when using the addQueryIdsListener method. See
|
|
306
|
+
* that method for specific examples.
|
|
266
307
|
*
|
|
267
|
-
* When called, a QueryIdsListener is given a reference to the
|
|
268
|
-
* Queries object.
|
|
308
|
+
* When called, a QueryIdsListener is given a reference to the Queries object.
|
|
269
309
|
* @param queries A reference to the Queries object that changed.
|
|
270
310
|
* @category Listener
|
|
271
311
|
* @since v2.0.0
|
|
@@ -629,9 +669,9 @@ export type QueriesListenerStats = {
|
|
|
629
669
|
*/
|
|
630
670
|
export type GetTableCell = {
|
|
631
671
|
/**
|
|
632
|
-
* When called with one parameter, this function will return the value of
|
|
633
|
-
*
|
|
634
|
-
*
|
|
672
|
+
* When called with one parameter, this function will return the value of the
|
|
673
|
+
* specified Cell from the query's root Table for the Row being selected or
|
|
674
|
+
* filtered.
|
|
635
675
|
* @param cellId The Id of the Cell to fetch the value for.
|
|
636
676
|
* @returns A Cell value or `undefined`.
|
|
637
677
|
* @category Callback
|
|
@@ -639,9 +679,9 @@ export type GetTableCell = {
|
|
|
639
679
|
*/
|
|
640
680
|
(cellId: Id): CellOrUndefined;
|
|
641
681
|
/**
|
|
642
|
-
* When called with two parameters, this function will return the value of
|
|
643
|
-
*
|
|
644
|
-
*
|
|
682
|
+
* When called with two parameters, this function will return the value of the
|
|
683
|
+
* specified Cell from a Table that has been joined in the query, for the Row
|
|
684
|
+
* being selected or filtered.
|
|
645
685
|
* @param joinedTableId The Id of the Table to fetch the value from. If the
|
|
646
686
|
* underlying Table was joined 'as' a different Id, that should instead be
|
|
647
687
|
* used.
|
|
@@ -653,6 +693,50 @@ export type GetTableCell = {
|
|
|
653
693
|
(joinedTableId: Id, joinedCellId: Id): CellOrUndefined;
|
|
654
694
|
};
|
|
655
695
|
|
|
696
|
+
/**
|
|
697
|
+
* The Param type describes a function that takes a param Id and returns its
|
|
698
|
+
* value within a parameterized query.
|
|
699
|
+
*
|
|
700
|
+
* A Param function is provided when setting parameterized query definitions,
|
|
701
|
+
* and allows you to reference dynamic param values that can be updated without
|
|
702
|
+
* redefining the entire query.
|
|
703
|
+
* @param paramId The Id of the param to fetch the value for.
|
|
704
|
+
* @returns A Cell value or `undefined` if the param is not set.
|
|
705
|
+
* @example
|
|
706
|
+
* This example shows a query that uses a param to filter results.
|
|
707
|
+
*
|
|
708
|
+
* ```js
|
|
709
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
710
|
+
*
|
|
711
|
+
* const store = createStore().setTable('pets', {
|
|
712
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
713
|
+
* felix: {species: 'cat', color: 'black'},
|
|
714
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
715
|
+
* });
|
|
716
|
+
*
|
|
717
|
+
* const queries = createQueries(store);
|
|
718
|
+
* queries.setQueryDefinition(
|
|
719
|
+
* 'query',
|
|
720
|
+
* 'pets',
|
|
721
|
+
* ({select, where, param}) => {
|
|
722
|
+
* select('color');
|
|
723
|
+
* where('species', param('species'));
|
|
724
|
+
* },
|
|
725
|
+
* {species: 'dog'},
|
|
726
|
+
* );
|
|
727
|
+
*
|
|
728
|
+
* console.log(queries.getResultTable('query'));
|
|
729
|
+
* // -> {fido: {color: 'brown'}, cujo: {color: 'black'}}
|
|
730
|
+
*
|
|
731
|
+
* queries.setParamValue('query', 'species', 'cat');
|
|
732
|
+
* console.log(queries.getResultTable('query'));
|
|
733
|
+
* // -> {felix: {color: 'black'}}
|
|
734
|
+
* ```
|
|
735
|
+
* @category Definition
|
|
736
|
+
* @since v7.2.0
|
|
737
|
+
*/
|
|
738
|
+
export type Param = (paramId: Id) => ParamValue | undefined;
|
|
739
|
+
|
|
656
740
|
/**
|
|
657
741
|
* The Select type describes a function that lets you specify a Cell or
|
|
658
742
|
* calculated value for including into the query's result.
|
|
@@ -1732,8 +1816,8 @@ export interface Queries {
|
|
|
1732
1816
|
* The third `query` parameter is a callback that you provide to define the
|
|
1733
1817
|
* query. That callback is provided with a `keywords` object that contains the
|
|
1734
1818
|
* functions you use to define the query, like `select`, `join`, and so on.
|
|
1735
|
-
* You can see how that is used in the simple example below. The following
|
|
1736
|
-
*
|
|
1819
|
+
* You can see how that is used in the simple example below. The following six
|
|
1820
|
+
* clause types are supported:
|
|
1737
1821
|
*
|
|
1738
1822
|
* - The Select type describes a function that lets you specify a Cell or
|
|
1739
1823
|
* calculated value for including into the query's result.
|
|
@@ -1746,6 +1830,8 @@ export interface Queries {
|
|
|
1746
1830
|
* of a Cell in multiple ResultRows should be aggregated together.
|
|
1747
1831
|
* - The Having type describes a function that lets you specify conditions to
|
|
1748
1832
|
* filter results, based on the grouped Cells resulting from a Group clause.
|
|
1833
|
+
* - The Param type (since v7.2) describes a function that lets you specify
|
|
1834
|
+
* parameters for a parameterized query.
|
|
1749
1835
|
*
|
|
1750
1836
|
* Full documentation and examples are provided in the sections for each of
|
|
1751
1837
|
* those clause types.
|
|
@@ -1764,7 +1850,7 @@ export interface Queries {
|
|
|
1764
1850
|
*
|
|
1765
1851
|
* ```js
|
|
1766
1852
|
* import {createQueries, createStore} from 'tinybase';
|
|
1767
|
-
*
|
|
1853
|
+
*
|
|
1768
1854
|
* const store = createStore().setTable('pets', {
|
|
1769
1855
|
* fido: {species: 'dog', color: 'brown'},
|
|
1770
1856
|
* felix: {species: 'cat', color: 'black'},
|
|
@@ -1792,7 +1878,9 @@ export interface Queries {
|
|
|
1792
1878
|
where: Where;
|
|
1793
1879
|
group: Group;
|
|
1794
1880
|
having: Having;
|
|
1881
|
+
param: Param;
|
|
1795
1882
|
}) => void,
|
|
1883
|
+
paramValues?: ParamValues,
|
|
1796
1884
|
): Queries;
|
|
1797
1885
|
|
|
1798
1886
|
/**
|
|
@@ -1829,6 +1917,92 @@ export interface Queries {
|
|
|
1829
1917
|
*/
|
|
1830
1918
|
delQueryDefinition(queryId: Id): Queries;
|
|
1831
1919
|
|
|
1920
|
+
/**
|
|
1921
|
+
* The setParamValues method sets multiple param values for a parameterized
|
|
1922
|
+
* query at once, causing the query to re-evaluate with the new param values.
|
|
1923
|
+
* @param queryId The Id of the query to update the params for.
|
|
1924
|
+
* @param paramValues An object containing the param Ids and values to set.
|
|
1925
|
+
* @returns A reference to the Queries object for convenient chaining.
|
|
1926
|
+
* @example
|
|
1927
|
+
* This example creates a parameterized query and then updates multiple
|
|
1928
|
+
* parameters at once.
|
|
1929
|
+
*
|
|
1930
|
+
* ```js
|
|
1931
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
1932
|
+
*
|
|
1933
|
+
* const store = createStore().setTable('pets', {
|
|
1934
|
+
* fido: {species: 'dog', color: 'brown', age: 5},
|
|
1935
|
+
* felix: {species: 'cat', color: 'black', age: 3},
|
|
1936
|
+
* cujo: {species: 'dog', color: 'black', age: 7},
|
|
1937
|
+
* });
|
|
1938
|
+
*
|
|
1939
|
+
* const queries = createQueries(store);
|
|
1940
|
+
* queries.setQueryDefinition(
|
|
1941
|
+
* 'query',
|
|
1942
|
+
* 'pets',
|
|
1943
|
+
* ({select, where, param}) => {
|
|
1944
|
+
* select('color');
|
|
1945
|
+
* where('species', param('species'));
|
|
1946
|
+
* where((getTableCell) => getTableCell('age') >= param('minAge'));
|
|
1947
|
+
* },
|
|
1948
|
+
* {species: 'dog', minAge: 5},
|
|
1949
|
+
* );
|
|
1950
|
+
*
|
|
1951
|
+
* console.log(queries.getResultTable('query'));
|
|
1952
|
+
* // -> {fido: {color: 'brown'}, cujo: {color: 'black'}}
|
|
1953
|
+
*
|
|
1954
|
+
* queries.setParamValues('query', {species: 'cat', minAge: 2});
|
|
1955
|
+
* console.log(queries.getResultTable('query'));
|
|
1956
|
+
* // -> {felix: {color: 'black'}}
|
|
1957
|
+
* ```
|
|
1958
|
+
* @category Configuration
|
|
1959
|
+
* @since v7.2.0
|
|
1960
|
+
*/
|
|
1961
|
+
setParamValues(queryId: Id, paramValues: ParamValues): Queries;
|
|
1962
|
+
|
|
1963
|
+
/**
|
|
1964
|
+
* The setParamValue method sets a single param value for a parameterized
|
|
1965
|
+
* query, causing the query to re-evaluate with the new param value.
|
|
1966
|
+
* @param queryId The Id of the query to update the param for.
|
|
1967
|
+
* @param paramId The Id of the param to set.
|
|
1968
|
+
* @param value The value to set for the param.
|
|
1969
|
+
* @returns A reference to the Queries object for convenient chaining.
|
|
1970
|
+
* @example
|
|
1971
|
+
* This example creates a parameterized query and then updates one of its
|
|
1972
|
+
* params.
|
|
1973
|
+
*
|
|
1974
|
+
* ```js
|
|
1975
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
1976
|
+
*
|
|
1977
|
+
* const store = createStore().setTable('pets', {
|
|
1978
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
1979
|
+
* felix: {species: 'cat', color: 'black'},
|
|
1980
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
1981
|
+
* });
|
|
1982
|
+
*
|
|
1983
|
+
* const queries = createQueries(store);
|
|
1984
|
+
* queries.setQueryDefinition(
|
|
1985
|
+
* 'query',
|
|
1986
|
+
* 'pets',
|
|
1987
|
+
* ({select, where, param}) => {
|
|
1988
|
+
* select('color');
|
|
1989
|
+
* where('species', param('species'));
|
|
1990
|
+
* },
|
|
1991
|
+
* {species: 'dog'},
|
|
1992
|
+
* );
|
|
1993
|
+
*
|
|
1994
|
+
* console.log(queries.getResultTable('query'));
|
|
1995
|
+
* // -> {fido: {color: 'brown'}, cujo: {color: 'black'}}
|
|
1996
|
+
*
|
|
1997
|
+
* queries.setParamValue('query', 'species', 'cat');
|
|
1998
|
+
* console.log(queries.getResultTable('query'));
|
|
1999
|
+
* // -> {felix: {color: 'black'}}
|
|
2000
|
+
* ```
|
|
2001
|
+
* @category Configuration
|
|
2002
|
+
* @since v7.2.0
|
|
2003
|
+
*/
|
|
2004
|
+
setParamValue(queryId: Id, paramId: Id, value: ParamValue): Queries;
|
|
2005
|
+
|
|
1832
2006
|
/**
|
|
1833
2007
|
* The getStore method returns a reference to the underlying Store that is
|
|
1834
2008
|
* backing this Queries object.
|
|
@@ -2763,23 +2937,23 @@ export interface Queries {
|
|
|
2763
2937
|
|
|
2764
2938
|
/**
|
|
2765
2939
|
* The addResultTableCellIdsListener method registers a listener function with
|
|
2766
|
-
* the Queries object that will be called whenever the Cell Ids that
|
|
2767
|
-
*
|
|
2940
|
+
* the Queries object that will be called whenever the Cell Ids that appear
|
|
2941
|
+
* anywhere in a ResultTable change.
|
|
2768
2942
|
*
|
|
2769
2943
|
* The provided listener is a ResultTableCellIdsListener function, and will be
|
|
2770
2944
|
* called with a reference to the Queries object and the Id of the ResultTable
|
|
2771
2945
|
* that changed (which is also the query Id).
|
|
2772
2946
|
*
|
|
2773
|
-
* By default, such a listener is only called when a Cell Id is added
|
|
2774
|
-
*
|
|
2775
|
-
*
|
|
2947
|
+
* By default, such a listener is only called when a Cell Id is added to, or
|
|
2948
|
+
* removed from, the ResultTable. To listen to all changes in the ResultTable,
|
|
2949
|
+
* use the addResultTableListener method.
|
|
2776
2950
|
*
|
|
2777
2951
|
* You can either listen to a single ResultTable (by specifying a query Id as
|
|
2778
2952
|
* the method's first parameter) or changes to any ResultTable (by providing a
|
|
2779
2953
|
* `null` wildcard).
|
|
2780
2954
|
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
2781
|
-
* @param listener The function that will be called whenever the Cell
|
|
2782
|
-
*
|
|
2955
|
+
* @param listener The function that will be called whenever the Cell Ids that
|
|
2956
|
+
* appear anywhere in the ResultTable change.
|
|
2783
2957
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2784
2958
|
* @example
|
|
2785
2959
|
* This example registers a listener that responds to any change to the
|
|
@@ -30,6 +30,47 @@ import type {
|
|
|
30
30
|
Store,
|
|
31
31
|
} from '../../store/with-schemas/index.d.ts';
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* The ParamValue type describes a single param value that can be used in a
|
|
35
|
+
* parameterized query.
|
|
36
|
+
*
|
|
37
|
+
* A ParamValue is similar to a Cell, but params cannot be `undefined`. They
|
|
38
|
+
* must be a JavaScript string, number, boolean, or null.
|
|
39
|
+
* @example
|
|
40
|
+
* ```js
|
|
41
|
+
* import type {ParamValue} from 'tinybase';
|
|
42
|
+
*
|
|
43
|
+
* export const paramValue1: ParamValue = 'dog';
|
|
44
|
+
* export const paramValue2: ParamValue = 5;
|
|
45
|
+
* export const paramValue3: ParamValue = true;
|
|
46
|
+
* export const paramValue4: ParamValue = null;
|
|
47
|
+
* ```
|
|
48
|
+
* @category Params
|
|
49
|
+
* @since v7.2.0
|
|
50
|
+
*/
|
|
51
|
+
export type ParamValue = string | number | boolean | null;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The ParamValues type describes an object of param values, keyed by param Id,
|
|
55
|
+
* used to provide values for a parameterized query.
|
|
56
|
+
*
|
|
57
|
+
* A ParamValues object is provided when setting a query definition with params,
|
|
58
|
+
* or when updating params with the setParamValues method.
|
|
59
|
+
* @example
|
|
60
|
+
* ```js
|
|
61
|
+
* import type {ParamValues} from 'tinybase';
|
|
62
|
+
*
|
|
63
|
+
* export const paramValues: ParamValues = {
|
|
64
|
+
* species: 'dog',
|
|
65
|
+
* minAge: 5,
|
|
66
|
+
* active: true,
|
|
67
|
+
* };
|
|
68
|
+
* ```
|
|
69
|
+
* @category Params
|
|
70
|
+
* @since v7.2.0
|
|
71
|
+
*/
|
|
72
|
+
export type ParamValues = {[paramId: Id]: ParamValue};
|
|
73
|
+
|
|
33
74
|
/**
|
|
34
75
|
* The ResultTable type is the data structure representing the results of a
|
|
35
76
|
* query.
|
|
@@ -269,8 +310,8 @@ export type ResultRowCallback = (
|
|
|
269
310
|
export type ResultCellCallback = (cellId: Id, cell: ResultCell) => void;
|
|
270
311
|
|
|
271
312
|
/**
|
|
272
|
-
* The QueryIdsListener type describes a function that is used to listen
|
|
273
|
-
*
|
|
313
|
+
* The QueryIdsListener type describes a function that is used to listen to
|
|
314
|
+
* Query definitions being added or removed.
|
|
274
315
|
*
|
|
275
316
|
* This has schema-based typing. The following is a simplified representation:
|
|
276
317
|
*
|
|
@@ -278,11 +319,10 @@ export type ResultCellCallback = (cellId: Id, cell: ResultCell) => void;
|
|
|
278
319
|
* (queries: Queries) => void;
|
|
279
320
|
* ```
|
|
280
321
|
*
|
|
281
|
-
* A QueryIdsListener is provided when using the
|
|
282
|
-
*
|
|
322
|
+
* A QueryIdsListener is provided when using the addQueryIdsListener method. See
|
|
323
|
+
* that method for specific examples.
|
|
283
324
|
*
|
|
284
|
-
* When called, a QueryIdsListener is given a reference to the
|
|
285
|
-
* Queries object.
|
|
325
|
+
* When called, a QueryIdsListener is given a reference to the Queries object.
|
|
286
326
|
* @param queries A reference to the Queries object that changed.
|
|
287
327
|
* @category Listener
|
|
288
328
|
* @since v2.0.0
|
|
@@ -741,9 +781,9 @@ export type GetTableCell<
|
|
|
741
781
|
RootTableId extends TableIdFromSchema<Schema>,
|
|
742
782
|
> = {
|
|
743
783
|
/**
|
|
744
|
-
* When called with one parameter, this function will return the value of
|
|
745
|
-
*
|
|
746
|
-
*
|
|
784
|
+
* When called with one parameter, this function will return the value of the
|
|
785
|
+
* specified Cell from the query's root Table for the Row being selected or
|
|
786
|
+
* filtered.
|
|
747
787
|
* @param cellId The Id of the Cell to fetch the value for.
|
|
748
788
|
* @returns A Cell value or `undefined`.
|
|
749
789
|
* @category Callback
|
|
@@ -753,9 +793,9 @@ export type GetTableCell<
|
|
|
753
793
|
cellId: RootCellId,
|
|
754
794
|
): CellOrUndefined<Schema, RootTableId, RootCellId>;
|
|
755
795
|
/**
|
|
756
|
-
* When called with two parameters, this function will return the value of
|
|
757
|
-
*
|
|
758
|
-
*
|
|
796
|
+
* When called with two parameters, this function will return the value of the
|
|
797
|
+
* specified Cell from a Table that has been joined in the query, for the Row
|
|
798
|
+
* being selected or filtered.
|
|
759
799
|
* @param joinedTableId The Id of the Table to fetch the value from. If the
|
|
760
800
|
* underlying Table was joined 'as' a different Id, that should instead be
|
|
761
801
|
* used.
|
|
@@ -778,6 +818,50 @@ export type GetTableCell<
|
|
|
778
818
|
| undefined;
|
|
779
819
|
};
|
|
780
820
|
|
|
821
|
+
/**
|
|
822
|
+
* The Param type describes a function that takes a param Id and returns its
|
|
823
|
+
* value within a parameterized query.
|
|
824
|
+
*
|
|
825
|
+
* A Param function is provided when setting parameterized query definitions,
|
|
826
|
+
* and allows you to reference dynamic param values that can be updated without
|
|
827
|
+
* redefining the entire query.
|
|
828
|
+
* @param paramId The Id of the param to fetch the value for.
|
|
829
|
+
* @returns A Cell value or `undefined` if the param is not set.
|
|
830
|
+
* @example
|
|
831
|
+
* This example shows a query that uses a param to filter results.
|
|
832
|
+
*
|
|
833
|
+
* ```js
|
|
834
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
835
|
+
*
|
|
836
|
+
* const store = createStore().setTable('pets', {
|
|
837
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
838
|
+
* felix: {species: 'cat', color: 'black'},
|
|
839
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
840
|
+
* });
|
|
841
|
+
*
|
|
842
|
+
* const queries = createQueries(store);
|
|
843
|
+
* queries.setQueryDefinition(
|
|
844
|
+
* 'query',
|
|
845
|
+
* 'pets',
|
|
846
|
+
* ({select, where, param}) => {
|
|
847
|
+
* select('color');
|
|
848
|
+
* where('species', param('species'));
|
|
849
|
+
* },
|
|
850
|
+
* {species: 'dog'},
|
|
851
|
+
* );
|
|
852
|
+
*
|
|
853
|
+
* console.log(queries.getResultTable('query'));
|
|
854
|
+
* // -> {fido: {color: 'brown'}, cujo: {color: 'black'}}
|
|
855
|
+
*
|
|
856
|
+
* queries.setParamValue('query', 'species', 'cat');
|
|
857
|
+
* console.log(queries.getResultTable('query'));
|
|
858
|
+
* // -> {felix: {color: 'black'}}
|
|
859
|
+
* ```
|
|
860
|
+
* @category Definition
|
|
861
|
+
* @since v7.2.0
|
|
862
|
+
*/
|
|
863
|
+
export type Param = (paramId: Id) => ParamValue | undefined;
|
|
864
|
+
|
|
781
865
|
/**
|
|
782
866
|
* The Select type describes a function that lets you specify a Cell or
|
|
783
867
|
* calculated value for including into the query's result.
|
|
@@ -1916,7 +2000,9 @@ export interface Queries<in out Schemas extends OptionalSchemas> {
|
|
|
1916
2000
|
* where: Where;
|
|
1917
2001
|
* group: Group;
|
|
1918
2002
|
* having: Having;
|
|
2003
|
+
* param: Param;
|
|
1919
2004
|
* }) => void,
|
|
2005
|
+
* paramValues?: ParamValues,
|
|
1920
2006
|
* ): Queries;
|
|
1921
2007
|
* ```
|
|
1922
2008
|
*
|
|
@@ -1930,8 +2016,8 @@ export interface Queries<in out Schemas extends OptionalSchemas> {
|
|
|
1930
2016
|
* The third `query` parameter is a callback that you provide to define the
|
|
1931
2017
|
* query. That callback is provided with a `keywords` object that contains the
|
|
1932
2018
|
* functions you use to define the query, like `select`, `join`, and so on.
|
|
1933
|
-
* You can see how that is used in the simple example below. The following
|
|
1934
|
-
*
|
|
2019
|
+
* You can see how that is used in the simple example below. The following six
|
|
2020
|
+
* clause types are supported:
|
|
1935
2021
|
*
|
|
1936
2022
|
* - The Select type describes a function that lets you specify a Cell or
|
|
1937
2023
|
* calculated value for including into the query's result.
|
|
@@ -1944,6 +2030,8 @@ export interface Queries<in out Schemas extends OptionalSchemas> {
|
|
|
1944
2030
|
* of a Cell in multiple ResultRows should be aggregated together.
|
|
1945
2031
|
* - The Having type describes a function that lets you specify conditions to
|
|
1946
2032
|
* filter results, based on the grouped Cells resulting from a Group clause.
|
|
2033
|
+
* - The Param type (since v7.2) describes a function that lets you specify
|
|
2034
|
+
* parameters for a parameterized query.
|
|
1947
2035
|
*
|
|
1948
2036
|
* Full documentation and examples are provided in the sections for each of
|
|
1949
2037
|
* those clause types.
|
|
@@ -1962,7 +2050,7 @@ export interface Queries<in out Schemas extends OptionalSchemas> {
|
|
|
1962
2050
|
*
|
|
1963
2051
|
* ```js
|
|
1964
2052
|
* import {createQueries, createStore} from 'tinybase';
|
|
1965
|
-
*
|
|
2053
|
+
*
|
|
1966
2054
|
* const store = createStore().setTable('pets', {
|
|
1967
2055
|
* fido: {species: 'dog', color: 'brown'},
|
|
1968
2056
|
* felix: {species: 'cat', color: 'black'},
|
|
@@ -1990,7 +2078,9 @@ export interface Queries<in out Schemas extends OptionalSchemas> {
|
|
|
1990
2078
|
where: Where<Schemas[0], RootTableId>;
|
|
1991
2079
|
group: Group;
|
|
1992
2080
|
having: Having;
|
|
2081
|
+
param: Param;
|
|
1993
2082
|
}) => void,
|
|
2083
|
+
paramValues?: ParamValues,
|
|
1994
2084
|
): Queries<Schemas>;
|
|
1995
2085
|
|
|
1996
2086
|
/**
|
|
@@ -2033,6 +2123,104 @@ export interface Queries<in out Schemas extends OptionalSchemas> {
|
|
|
2033
2123
|
*/
|
|
2034
2124
|
delQueryDefinition(queryId: Id): Queries<Schemas>;
|
|
2035
2125
|
|
|
2126
|
+
/**
|
|
2127
|
+
* The setParamValues method sets multiple param values for a parameterized
|
|
2128
|
+
* query at once, causing the query to re-evaluate with the new param values.
|
|
2129
|
+
* @param queryId The Id of the query to update the params for.
|
|
2130
|
+
* @param paramValues An object containing the param Ids and values to set.
|
|
2131
|
+
* @returns A reference to the Queries object for convenient chaining.
|
|
2132
|
+
* @example
|
|
2133
|
+
* This example creates a parameterized query and then updates multiple
|
|
2134
|
+
* parameters at once.
|
|
2135
|
+
*
|
|
2136
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
2137
|
+
*
|
|
2138
|
+
* ```ts override
|
|
2139
|
+
* setParamValues(queryId: Id, paramValues: ParamValues): Queries;
|
|
2140
|
+
* ```
|
|
2141
|
+
*
|
|
2142
|
+
* ```js
|
|
2143
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
2144
|
+
*
|
|
2145
|
+
* const store = createStore().setTable('pets', {
|
|
2146
|
+
* fido: {species: 'dog', color: 'brown', age: 5},
|
|
2147
|
+
* felix: {species: 'cat', color: 'black', age: 3},
|
|
2148
|
+
* cujo: {species: 'dog', color: 'black', age: 7},
|
|
2149
|
+
* });
|
|
2150
|
+
*
|
|
2151
|
+
* const queries = createQueries(store);
|
|
2152
|
+
* queries.setQueryDefinition(
|
|
2153
|
+
* 'query',
|
|
2154
|
+
* 'pets',
|
|
2155
|
+
* ({select, where, param}) => {
|
|
2156
|
+
* select('color');
|
|
2157
|
+
* where('species', param('species'));
|
|
2158
|
+
* where((getTableCell) => getTableCell('age') >= param('minAge'));
|
|
2159
|
+
* },
|
|
2160
|
+
* {species: 'dog', minAge: 5},
|
|
2161
|
+
* );
|
|
2162
|
+
*
|
|
2163
|
+
* console.log(queries.getResultTable('query'));
|
|
2164
|
+
* // -> {fido: {color: 'brown'}, cujo: {color: 'black'}}
|
|
2165
|
+
*
|
|
2166
|
+
* queries.setParamValues('query', {species: 'cat', minAge: 2});
|
|
2167
|
+
* console.log(queries.getResultTable('query'));
|
|
2168
|
+
* // -> {felix: {color: 'black'}}
|
|
2169
|
+
* ```
|
|
2170
|
+
* @category Configuration
|
|
2171
|
+
* @since v7.2.0
|
|
2172
|
+
*/
|
|
2173
|
+
setParamValues(queryId: Id, paramValues: ParamValues): Queries<Schemas>;
|
|
2174
|
+
|
|
2175
|
+
/**
|
|
2176
|
+
* The setParamValue method sets a single param value for a parameterized
|
|
2177
|
+
* query, causing the query to re-evaluate with the new param value.
|
|
2178
|
+
* @param queryId The Id of the query to update the param for.
|
|
2179
|
+
* @param paramId The Id of the param to set.
|
|
2180
|
+
* @param value The value to set for the param.
|
|
2181
|
+
* @returns A reference to the Queries object for convenient chaining.
|
|
2182
|
+
* @example
|
|
2183
|
+
* This example creates a parameterized query and then updates one of its
|
|
2184
|
+
* params.
|
|
2185
|
+
*
|
|
2186
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
2187
|
+
*
|
|
2188
|
+
* ```ts override
|
|
2189
|
+
* setParamValue(queryId: Id, paramId: Id, value: ParamValue): Queries;
|
|
2190
|
+
* ```
|
|
2191
|
+
*
|
|
2192
|
+
* ```js
|
|
2193
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
2194
|
+
*
|
|
2195
|
+
* const store = createStore().setTable('pets', {
|
|
2196
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
2197
|
+
* felix: {species: 'cat', color: 'black'},
|
|
2198
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
2199
|
+
* });
|
|
2200
|
+
*
|
|
2201
|
+
* const queries = createQueries(store);
|
|
2202
|
+
* queries.setQueryDefinition(
|
|
2203
|
+
* 'query',
|
|
2204
|
+
* 'pets',
|
|
2205
|
+
* ({select, where, param}) => {
|
|
2206
|
+
* select('color');
|
|
2207
|
+
* where('species', param('species'));
|
|
2208
|
+
* },
|
|
2209
|
+
* {species: 'dog'},
|
|
2210
|
+
* );
|
|
2211
|
+
*
|
|
2212
|
+
* console.log(queries.getResultTable('query'));
|
|
2213
|
+
* // -> {fido: {color: 'brown'}, cujo: {color: 'black'}}
|
|
2214
|
+
*
|
|
2215
|
+
* queries.setParamValue('query', 'species', 'cat');
|
|
2216
|
+
* console.log(queries.getResultTable('query'));
|
|
2217
|
+
* // -> {felix: {color: 'black'}}
|
|
2218
|
+
* ```
|
|
2219
|
+
* @category Configuration
|
|
2220
|
+
* @since v7.2.0
|
|
2221
|
+
*/
|
|
2222
|
+
setParamValue(queryId: Id, paramId: Id, value: ParamValue): Queries<Schemas>;
|
|
2223
|
+
|
|
2036
2224
|
/**
|
|
2037
2225
|
* The getStore method returns a reference to the underlying Store that is
|
|
2038
2226
|
* backing this Queries object.
|
|
@@ -2996,8 +3184,8 @@ export interface Queries<in out Schemas extends OptionalSchemas> {
|
|
|
2996
3184
|
|
|
2997
3185
|
/**
|
|
2998
3186
|
* The addResultTableCellIdsListener method registers a listener function with
|
|
2999
|
-
* the Queries object that will be called whenever the Cell Ids that
|
|
3000
|
-
*
|
|
3187
|
+
* the Queries object that will be called whenever the Cell Ids that appear
|
|
3188
|
+
* anywhere in a ResultTable change.
|
|
3001
3189
|
*
|
|
3002
3190
|
* This has schema-based typing. The following is a simplified representation:
|
|
3003
3191
|
*
|
|
@@ -3012,16 +3200,16 @@ export interface Queries<in out Schemas extends OptionalSchemas> {
|
|
|
3012
3200
|
* called with a reference to the Queries object and the Id of the ResultTable
|
|
3013
3201
|
* that changed (which is also the query Id).
|
|
3014
3202
|
*
|
|
3015
|
-
* By default, such a listener is only called when a Cell Id is added
|
|
3016
|
-
*
|
|
3017
|
-
*
|
|
3203
|
+
* By default, such a listener is only called when a Cell Id is added to, or
|
|
3204
|
+
* removed from, the ResultTable. To listen to all changes in the ResultTable,
|
|
3205
|
+
* use the addResultTableListener method.
|
|
3018
3206
|
*
|
|
3019
3207
|
* You can either listen to a single ResultTable (by specifying a query Id as
|
|
3020
3208
|
* the method's first parameter) or changes to any ResultTable (by providing a
|
|
3021
3209
|
* `null` wildcard).
|
|
3022
3210
|
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
3023
|
-
* @param listener The function that will be called whenever the Cell
|
|
3024
|
-
*
|
|
3211
|
+
* @param listener The function that will be called whenever the Cell Ids that
|
|
3212
|
+
* appear anywhere in the ResultTable change.
|
|
3025
3213
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
3026
3214
|
* @example
|
|
3027
3215
|
* This example registers a listener that responds to any change to the
|