@ronin/compiler 0.13.1-leo-ron-1071-experimental-278 → 0.13.1-leo-ron-1071-experimental-280

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.
Files changed (2) hide show
  1. package/dist/index.js +21 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -676,6 +676,9 @@ var RONIN_MODEL_FIELD_REGEX = new RegExp(
676
676
  "g"
677
677
  );
678
678
  var RAW_FIELD_TYPES = ["string", "number", "boolean"];
679
+ var CURRENT_TIME_EXPRESSION = {
680
+ [QUERY_SYMBOLS.EXPRESSION]: `strftime('%Y-%m-%dT%H:%M:%f', 'now') || 'Z'`
681
+ };
679
682
  var composeIncludedTableAlias = (fieldSlug) => {
680
683
  return `including_${fieldSlug}`;
681
684
  };
@@ -1333,7 +1336,8 @@ var SYSTEM_FIELDS = [
1333
1336
  {
1334
1337
  name: "RONIN - Created At",
1335
1338
  type: "date",
1336
- slug: "ronin.createdAt"
1339
+ slug: "ronin.createdAt",
1340
+ defaultValue: CURRENT_TIME_EXPRESSION
1337
1341
  },
1338
1342
  {
1339
1343
  name: "RONIN - Created By",
@@ -1343,7 +1347,8 @@ var SYSTEM_FIELDS = [
1343
1347
  {
1344
1348
  name: "RONIN - Updated At",
1345
1349
  type: "date",
1346
- slug: "ronin.updatedAt"
1350
+ slug: "ronin.updatedAt",
1351
+ defaultValue: CURRENT_TIME_EXPRESSION
1347
1352
  },
1348
1353
  {
1349
1354
  name: "RONIN - Updated By",
@@ -1493,8 +1498,12 @@ var getFieldStatement = (models, model, field) => {
1493
1498
  if (field.slug === "id") statement += " PRIMARY KEY";
1494
1499
  if (field.unique === true) statement += " UNIQUE";
1495
1500
  if (field.required === true) statement += " NOT NULL";
1496
- if (typeof field.defaultValue !== "undefined")
1497
- statement += ` DEFAULT ${typeof field.defaultValue === "string" ? `'${field.defaultValue}'` : field.defaultValue}`;
1501
+ if (typeof field.defaultValue !== "undefined") {
1502
+ const symbol = getSymbol(field.defaultValue);
1503
+ let value = typeof field.defaultValue === "string" ? `'${field.defaultValue}'` : field.defaultValue;
1504
+ if (symbol) value = `(${parseFieldExpression(model, "to", symbol.value)})`;
1505
+ statement += ` DEFAULT ${value}`;
1506
+ }
1498
1507
  if (field.collation) statement += ` COLLATE ${field.collation}`;
1499
1508
  if (field.increment === true) statement += " AUTOINCREMENT";
1500
1509
  if (typeof field.check !== "undefined") {
@@ -2164,20 +2173,19 @@ var handleSelecting = (models, model, statementParams, instructions, options) =>
2164
2173
 
2165
2174
  // src/instructions/to.ts
2166
2175
  var handleTo = (models, model, statementParams, queryType, dependencyStatements, instructions, parentModel) => {
2167
- const currentTime = (/* @__PURE__ */ new Date()).toISOString();
2168
2176
  const { with: withInstruction, to: toInstruction } = instructions;
2169
2177
  const defaultFields = {};
2170
2178
  if (queryType === "add") {
2171
2179
  defaultFields.id = toInstruction.id || generateRecordId(model.idPrefix);
2172
2180
  }
2173
- defaultFields.ronin = {
2174
- // If records are being created, set their creation time.
2175
- ...queryType === "add" ? { createdAt: currentTime } : {},
2176
- // If records are being created or updated, set their update time.
2177
- updatedAt: currentTime,
2178
- // Allow for overwriting the default values provided above.
2179
- ...toInstruction.ronin
2180
- };
2181
+ if (queryType === "set" || toInstruction.ronin) {
2182
+ defaultFields.ronin = {
2183
+ // If records are being updated, bump their update time.
2184
+ ...queryType === "set" ? { updatedAt: CURRENT_TIME_EXPRESSION } : {},
2185
+ // Allow for overwriting the default values provided above.
2186
+ ...toInstruction.ronin
2187
+ };
2188
+ }
2181
2189
  const symbol = getSymbol(toInstruction);
2182
2190
  if (symbol?.type === "query") {
2183
2191
  let { queryModel: subQueryModelSlug, queryInstructions: subQueryInstructions } = splitQuery(symbol.value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.13.1-leo-ron-1071-experimental-278",
3
+ "version": "0.13.1-leo-ron-1071-experimental-280",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {