@atscript/db-mysql 0.1.169 → 0.1.171

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.
@@ -0,0 +1,34 @@
1
+ //#region src/annotation-values.ts
2
+ /**
3
+ * `@db.mysql.onUpdate` values MySQL accepts in `ON UPDATE`:
4
+ * `CURRENT_TIMESTAMP` / `LOCALTIMESTAMP` / `LOCALTIME` with optional
5
+ * parentheses, or `NOW()`, each with an optional precision 0–6
6
+ * (group 1 or 2).
7
+ */
8
+ const MYSQL_ON_UPDATE_RE = /^(?:(?:current_timestamp|localtimestamp|localtime)(?:\(\s*([0-6])?\s*\))?|now\(\s*([0-6])?\s*\))$/i;
9
+ /** An engine / character-set / collation name: what `@db.mysql.*` may put into DDL unquoted. */
10
+ const MYSQL_NAME_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
11
+ /**
12
+ * `name` when it is a bare MySQL name ({@link MYSQL_NAME_RE}), else an error
13
+ * naming `annotation` — the compiler refuses such a value; this guards
14
+ * metadata built without it.
15
+ */
16
+ function mysqlName(annotation, name) {
17
+ if (!MYSQL_NAME_RE.test(name)) throw new Error(`${annotation} "${name}" is not a MySQL name (letters, digits, _)`);
18
+ return name;
19
+ }
20
+ /**
21
+ * The `ON UPDATE` expression for `@db.mysql.onUpdate` `expr` on a column of
22
+ * type `sqlType`: `CURRENT_TIMESTAMP(n)` as written when it names a
23
+ * precision, else `columnDefault` (the column's own precision — MySQL
24
+ * requires them to match). Any other expression throws (the compiler refuses
25
+ * it; nothing else reaches the DDL).
26
+ */
27
+ function mysqlOnUpdateExpr(expr, columnDefault) {
28
+ const match = MYSQL_ON_UPDATE_RE.exec(expr.trim());
29
+ if (!match) throw new Error(`@db.mysql.onUpdate "${expr}" is not CURRENT_TIMESTAMP[(n)]`);
30
+ const fsp = match[1] ?? match[2];
31
+ return fsp === void 0 ? columnDefault : `CURRENT_TIMESTAMP(${fsp})`;
32
+ }
33
+ //#endregion
34
+ export { mysqlOnUpdateExpr as i, MYSQL_ON_UPDATE_RE as n, mysqlName as r, MYSQL_NAME_RE as t };
@@ -0,0 +1,57 @@
1
+ //#region src/annotation-values.ts
2
+ /**
3
+ * `@db.mysql.onUpdate` values MySQL accepts in `ON UPDATE`:
4
+ * `CURRENT_TIMESTAMP` / `LOCALTIMESTAMP` / `LOCALTIME` with optional
5
+ * parentheses, or `NOW()`, each with an optional precision 0–6
6
+ * (group 1 or 2).
7
+ */
8
+ const MYSQL_ON_UPDATE_RE = /^(?:(?:current_timestamp|localtimestamp|localtime)(?:\(\s*([0-6])?\s*\))?|now\(\s*([0-6])?\s*\))$/i;
9
+ /** An engine / character-set / collation name: what `@db.mysql.*` may put into DDL unquoted. */
10
+ const MYSQL_NAME_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
11
+ /**
12
+ * `name` when it is a bare MySQL name ({@link MYSQL_NAME_RE}), else an error
13
+ * naming `annotation` — the compiler refuses such a value; this guards
14
+ * metadata built without it.
15
+ */
16
+ function mysqlName(annotation, name) {
17
+ if (!MYSQL_NAME_RE.test(name)) throw new Error(`${annotation} "${name}" is not a MySQL name (letters, digits, _)`);
18
+ return name;
19
+ }
20
+ /**
21
+ * The `ON UPDATE` expression for `@db.mysql.onUpdate` `expr` on a column of
22
+ * type `sqlType`: `CURRENT_TIMESTAMP(n)` as written when it names a
23
+ * precision, else `columnDefault` (the column's own precision — MySQL
24
+ * requires them to match). Any other expression throws (the compiler refuses
25
+ * it; nothing else reaches the DDL).
26
+ */
27
+ function mysqlOnUpdateExpr(expr, columnDefault) {
28
+ const match = MYSQL_ON_UPDATE_RE.exec(expr.trim());
29
+ if (!match) throw new Error(`@db.mysql.onUpdate "${expr}" is not CURRENT_TIMESTAMP[(n)]`);
30
+ const fsp = match[1] ?? match[2];
31
+ return fsp === void 0 ? columnDefault : `CURRENT_TIMESTAMP(${fsp})`;
32
+ }
33
+ //#endregion
34
+ Object.defineProperty(exports, "MYSQL_NAME_RE", {
35
+ enumerable: true,
36
+ get: function() {
37
+ return MYSQL_NAME_RE;
38
+ }
39
+ });
40
+ Object.defineProperty(exports, "MYSQL_ON_UPDATE_RE", {
41
+ enumerable: true,
42
+ get: function() {
43
+ return MYSQL_ON_UPDATE_RE;
44
+ }
45
+ });
46
+ Object.defineProperty(exports, "mysqlName", {
47
+ enumerable: true,
48
+ get: function() {
49
+ return mysqlName;
50
+ }
51
+ });
52
+ Object.defineProperty(exports, "mysqlOnUpdateExpr", {
53
+ enumerable: true,
54
+ get: function() {
55
+ return mysqlOnUpdateExpr;
56
+ }
57
+ });