@saltcorn/data 0.8.9 → 0.9.0-beta.0
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/dist/base-plugin/index.d.ts +46 -40
- package/dist/base-plugin/index.d.ts.map +1 -1
- package/dist/base-plugin/types.d.ts +11 -0
- package/dist/base-plugin/types.d.ts.map +1 -1
- package/dist/base-plugin/types.js +6 -0
- package/dist/base-plugin/types.js.map +1 -1
- package/dist/models/field.d.ts +4 -0
- package/dist/models/field.d.ts.map +1 -1
- package/dist/models/field.js +1 -0
- package/dist/models/field.js.map +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/internal/table_helper.d.ts +33 -0
- package/dist/models/internal/table_helper.d.ts.map +1 -0
- package/dist/models/internal/table_helper.js +134 -0
- package/dist/models/internal/table_helper.js.map +1 -0
- package/dist/models/table.d.ts +156 -19
- package/dist/models/table.d.ts.map +1 -1
- package/dist/models/table.js +131 -15
- package/dist/models/table.js.map +1 -1
- package/dist/models/user.d.ts.map +1 -1
- package/dist/models/user.js +1 -2
- package/dist/models/user.js.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../models/table.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,KAAK,EACL,aAAa,EACb,GAAG,EAEH,WAAW,EAEZ,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EACR,SAAS,EACV,MAAM,gDAAgD,CAAC;AAExD,OAAO,KAAK,EACV,cAAc,EAEf,MAAM,+CAA+C,CAAC;AAEvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAmBlE,OAAO,KAAK,eAAe,MAAM,qBAAqB,CAAC;AA0BvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8CAA8C,CAAC;AAChF,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, InvalidConfiguration, InvalidAdminAction, satisfies, structuredClone, getLines, mergeIntoWhere, stringToJSON, isNode, apply, applyAsync, asyncMap, } = utils_1.default;
|
|
49
49
|
const tags_1 = __importDefault(require("@saltcorn/markup/tags"));
|
|
50
50
|
const { text } = tags_1.default;
|
|
51
|
+
const table_helper_1 = require("./internal/table_helper");
|
|
51
52
|
/**
|
|
52
53
|
* Transponce Objects
|
|
53
54
|
* TODO more detailed explanation
|
|
@@ -84,18 +85,82 @@ const dateFormats = [moment_1.default.ISO_8601];
|
|
|
84
85
|
const isDate = function (date) {
|
|
85
86
|
return (0, moment_1.default)(date, dateFormats, true).isValid();
|
|
86
87
|
};
|
|
87
|
-
// todo resolve database specific
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
*
|
|
89
|
+
* A class representing database tables and their properties.
|
|
90
|
+
*
|
|
91
|
+
* Use this to create or delete tables and their properties, or to query
|
|
92
|
+
* or change table rows.
|
|
93
|
+
*
|
|
94
|
+
* To query, update, insert or delete rows in an existing table, first you
|
|
95
|
+
* should find the table object with {@link Table.findOne}.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```
|
|
99
|
+
* Table.findOne({name: "Customers"}) // find the table with name "Customers"
|
|
100
|
+
* Table.findOne("Customers") // find the table with name "Customers" (shortcut)
|
|
101
|
+
* Table.findOne({ id: 5 }) // find the table with id=5
|
|
102
|
+
* Table.findOne(5) // find the table with id=5 (shortcut)
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* Table.findOne is synchronous (no need to await), But the functions that
|
|
106
|
+
* query and manipulate (such as {@link Table.insertRow}, {@link Table.getRows},
|
|
107
|
+
* {@link Table.updateRow}, {@link Table.deleteRows}) rows are mostly asyncronous,
|
|
108
|
+
* so you can put the await in front of the
|
|
109
|
+
* whole expression
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* To count the number of rows in the customer table
|
|
113
|
+
* ```
|
|
114
|
+
* const nrows = await Table.findOne("Customers").countRows()
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* For further examples, see the [Table test suite](https://github.com/saltcorn/saltcorn/blob/master/packages/saltcorn-data/tests/table.test.ts)
|
|
118
|
+
*
|
|
119
|
+
* ## Querying table rows
|
|
120
|
+
*
|
|
121
|
+
* There are several methods you can use to retrieve rows in the database:
|
|
122
|
+
*
|
|
123
|
+
* * {@link Table.countRows} To count the number of rows, optionally matching a criterion
|
|
124
|
+
* * {@link Table.getRows} To retrieve multiple rows matching a criterion
|
|
125
|
+
* * {@link Table.getRow} To retrieve a single row matching a criterion
|
|
126
|
+
* * {@link Table.getJoinedRows} To retrieve rows together with joinfields and aggregations
|
|
127
|
+
*
|
|
128
|
+
* These functions all take `Where` expressions which are JavaScript objects describing
|
|
129
|
+
* the criterion to match to. Some examples:
|
|
130
|
+
*
|
|
131
|
+
* * `{ name: "Jim" }`: Match all rows with name="Jim"
|
|
132
|
+
* * `{ name: { ilike: "im"} }`: Match all rows where name contains "im" (case insensitive)
|
|
133
|
+
* * `{ age: { lt: 18 } }`: Match all rows with age<18
|
|
134
|
+
* * `{ age: { lt: 18, equal: true } }`: Match all rows with age<=18
|
|
135
|
+
* * `{ age: { gt: 18, lt: 65} }`: Match all rows with 18<age<65
|
|
136
|
+
* * `{ name: { or: ["Harry", "Sally"] } }`: Match all rows with name="Harry" or "Sally"
|
|
137
|
+
* * `{ or: [{ name: "Joe"}, { age: 37 }] }`: Match all rows with name="Joe" or age=37
|
|
138
|
+
* * `{ not: { id: 5 } }`: All rows except id=5
|
|
139
|
+
*
|
|
140
|
+
* For further examples, see the [mkWhere test suite](https://github.com/saltcorn/saltcorn/blob/master/packages/db-common/internal.test.js)
|
|
141
|
+
*
|
|
142
|
+
* ## Updating a Row
|
|
143
|
+
*
|
|
144
|
+
* There are two nearly identical functions for updating rows depending on how you want
|
|
145
|
+
* failures treated
|
|
146
|
+
*
|
|
147
|
+
* * {@link Table.updateRow} Update a row, throws an exception if update is invalid
|
|
148
|
+
* * {@link Table.tryUpdateRow} Update a row, return an error message if update is invalid
|
|
149
|
+
*
|
|
150
|
+
* ## Inserting a new Row
|
|
151
|
+
*
|
|
152
|
+
* There are two nearly identical functions for inserting a new row depending on how you want
|
|
153
|
+
* failures treated
|
|
154
|
+
*
|
|
155
|
+
* * {@link Table.insertRow} insert a row, throws an exception if it is invalid
|
|
156
|
+
* * {@link Table.tryInsertRow} insert a row, return an error message if it is invalid
|
|
157
|
+
*
|
|
158
|
+
* ## Deleting rows
|
|
159
|
+
*
|
|
160
|
+
* Use {@link Table.deleteRows} to delete any number (zero, one or many) of rows matching a criterion. It uses
|
|
161
|
+
* the same `where` expression as the functions for querying rows
|
|
162
|
+
*
|
|
163
|
+
*
|
|
99
164
|
* @category saltcorn-data
|
|
100
165
|
*/
|
|
101
166
|
class Table {
|
|
@@ -984,7 +1049,7 @@ class Table {
|
|
|
984
1049
|
await this.updateRow({ [field_name]: !row[field_name] }, id, user);
|
|
985
1050
|
}
|
|
986
1051
|
/**
|
|
987
|
-
* Get primary key field
|
|
1052
|
+
* Get primary key field name
|
|
988
1053
|
* @type {string}
|
|
989
1054
|
*/
|
|
990
1055
|
get pk_name() {
|
|
@@ -995,7 +1060,9 @@ class Table {
|
|
|
995
1060
|
return pkField;
|
|
996
1061
|
}
|
|
997
1062
|
/**
|
|
998
|
-
* Check table constraints
|
|
1063
|
+
* Check table constraints against a row object. Will return a string With an error message if the
|
|
1064
|
+
* table constraints are violated, `undefined` if the row does not violate any constraints
|
|
1065
|
+
*
|
|
999
1066
|
* @param row
|
|
1000
1067
|
*/
|
|
1001
1068
|
check_table_constraints(row0) {
|
|
@@ -1028,9 +1095,23 @@ class Table {
|
|
|
1028
1095
|
return undefined;
|
|
1029
1096
|
}
|
|
1030
1097
|
/**
|
|
1031
|
-
* Insert row
|
|
1098
|
+
* Insert row into the table. By passing in the user as
|
|
1099
|
+
* the second argument, tt will check write rights. If a user object is not
|
|
1100
|
+
* supplied, the insert goes ahead without checking write permissions.
|
|
1101
|
+
*
|
|
1102
|
+
* Returns the primary key value of the inserted row.
|
|
1103
|
+
*
|
|
1104
|
+
* This will throw an exception if the row
|
|
1105
|
+
* does not conform to the table constraints. If you would like to insert a row
|
|
1106
|
+
* with a function that can return an error message, use {@link Table.tryInsertRow} instead.
|
|
1107
|
+
*
|
|
1108
|
+
* @example
|
|
1109
|
+
* ```
|
|
1110
|
+
* await Table.findOne("People").insertRow({ name: "Jim", age: 35 })
|
|
1111
|
+
* ```
|
|
1112
|
+
*
|
|
1032
1113
|
* @param v_in
|
|
1033
|
-
* @param
|
|
1114
|
+
* @param user
|
|
1034
1115
|
* @param resultCollector
|
|
1035
1116
|
* @returns {Promise<*>}
|
|
1036
1117
|
*/
|
|
@@ -2237,6 +2318,38 @@ class Table {
|
|
|
2237
2318
|
return rows.length > 0 ? rows[0] : null;
|
|
2238
2319
|
}
|
|
2239
2320
|
/**
|
|
2321
|
+
* Get rows along with joined and aggregated fields. The argument to `getJoinedRows` is an object
|
|
2322
|
+
* with several different possible fields, all of which are optional
|
|
2323
|
+
*
|
|
2324
|
+
* * `where`: A Where expression indicating the criterion to match
|
|
2325
|
+
* * `joinFields`: An object with the joinfields to retrieve
|
|
2326
|
+
* * `aggregations`: An object with the aggregations to retrieve
|
|
2327
|
+
* * `orderBy`: A string with the name of the field to order by
|
|
2328
|
+
* * `orderDesc`: If true, descending order
|
|
2329
|
+
* * `limit`: A number with the maximum number of rows to retrieve
|
|
2330
|
+
* * `offset`: The number of rows to skip in the result before returning rows
|
|
2331
|
+
*
|
|
2332
|
+
* @example
|
|
2333
|
+
* ```
|
|
2334
|
+
* const patients = Table.findOne({ name: "patients" });
|
|
2335
|
+
* const patients_rows = await patients.getJoinedRows({
|
|
2336
|
+
* where: { age: { gt: 65 } },
|
|
2337
|
+
* orderBy: "id",
|
|
2338
|
+
* aggregations: {
|
|
2339
|
+
* avg_temp: {
|
|
2340
|
+
* table: "readings",
|
|
2341
|
+
* ref: "patient_id",
|
|
2342
|
+
* field: "temperature",
|
|
2343
|
+
* aggregate: "avg",
|
|
2344
|
+
* },
|
|
2345
|
+
* },
|
|
2346
|
+
* joinFields: {
|
|
2347
|
+
* pages: { ref: "favbook", target: "pages" },
|
|
2348
|
+
* author: { ref: "favbook", target: "author" },
|
|
2349
|
+
* },
|
|
2350
|
+
* });
|
|
2351
|
+
* ```
|
|
2352
|
+
*
|
|
2240
2353
|
* @param {object} [opts = {}]
|
|
2241
2354
|
* @returns {Promise<object[]>}
|
|
2242
2355
|
*/
|
|
@@ -2381,6 +2494,9 @@ class Table {
|
|
|
2381
2494
|
}
|
|
2382
2495
|
return result;
|
|
2383
2496
|
}
|
|
2497
|
+
getFormulaExamples(typename) {
|
|
2498
|
+
return (0, table_helper_1.get_formula_examples)(typename, this.fields.filter((f) => !f.calculated));
|
|
2499
|
+
}
|
|
2384
2500
|
}
|
|
2385
2501
|
module.exports = Table;
|
|
2386
2502
|
//# sourceMappingURL=table.js.map
|