baja-lite 1.5.27 → 1.5.28

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 (3) hide show
  1. package/package.json +1 -1
  2. package/sql.js +19 -1
  3. package/sqlite.js +19 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.5.27",
3
+ "version": "1.5.28",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/baja-lite",
6
6
  "repository": {
package/sql.js CHANGED
@@ -949,10 +949,28 @@ export class Sqlite {
949
949
  PRIMARY KEY ( ______tableName )
950
950
  );
951
951
  `);
952
- this[_daoDB].function('UUID_SHORT', { deterministic: true }, () => snowflake.generate());
952
+ this[_daoDB].function('UUID_SHORT', { deterministic: false }, () => snowflake.generate());
953
+ this[_daoDB].function('UUID', { deterministic: false }, () => snowflake.generate());
953
954
  this[_daoDB].function('TIME_TO_SEC', { deterministic: true }, (time) => time.split(':').map((v, i) => parseInt(v) * (i > 0 ? 1 : 60)).reduce((a, b) => a + b, 0));
954
955
  this[_daoDB].function('IF', { deterministic: true }, (condition, v1, v2) => condition ? v1 : v2);
955
956
  this[_daoDB].function('RIGHT', { deterministic: true }, (src, p) => src.slice(p * -1));
957
+ this[_daoDB].function('LEFT', { deterministic: true }, (str, len) => str?.substring(0, len) || null);
958
+ this[_daoDB].function('NOW', { deterministic: false }, () => new Date().toISOString().slice(0, 19).replace('T', ' '));
959
+ this[_daoDB].function('CURDATE', { deterministic: false }, () => new Date().toISOString().split('T')[0]);
960
+ this[_daoDB].function('DATE_FORMAT', { deterministic: true }, (dateStr, format) => {
961
+ const date = new Date(dateStr);
962
+ return format
963
+ .replace('%Y', date.getFullYear().toString())
964
+ .replace('%m', (date.getMonth() + 1).toString().padStart(2, '0'))
965
+ .replace('%d', date.getDate().toString().padStart(2, '0'))
966
+ .replace('%H', date.getHours().toString().padStart(2, '0'))
967
+ .replace('%i', date.getMinutes().toString().padStart(2, '0'))
968
+ .replace('%s', date.getSeconds().toString().padStart(2, '0'));
969
+ });
970
+ this[_daoDB].function('RAND', { deterministic: false }, () => Math.random());
971
+ this[_daoDB].function('UNIX_TIMESTAMP', { deterministic: false }, (dateStr) => dateStr
972
+ ? Math.floor(new Date(dateStr).getTime() / 1000)
973
+ : Math.floor(Date.now() / 1000));
956
974
  }
957
975
  createConnection(sync) {
958
976
  if (sync === SyncMode.Async) {
package/sqlite.js CHANGED
@@ -132,10 +132,28 @@ export class SqliteRemoteClass {
132
132
  PRIMARY KEY ( ______tableName )
133
133
  );
134
134
  `);
135
- this.dbList[dbName].function('UUID_SHORT', { deterministic: true }, () => snowflake.generate());
135
+ this.dbList[dbName].function('UUID_SHORT', { deterministic: false }, () => snowflake.generate());
136
+ this.dbList[dbName].function('UUID', { deterministic: false }, () => snowflake.generate());
136
137
  this.dbList[dbName].function('TIME_TO_SEC', { deterministic: true }, (time) => time.split(':').map((v, i) => parseInt(v) * (i > 0 ? 1 : 60)).reduce((a, b) => a + b, 0));
137
138
  this.dbList[dbName].function('IF', { deterministic: true }, (condition, v1, v2) => condition ? v1 : v2);
138
139
  this.dbList[dbName].function('RIGHT', { deterministic: true }, (src, p) => src.slice(p * -1));
140
+ this.dbList[dbName].function('LEFT', { deterministic: true }, (str, len) => str?.substring(0, len) || null);
141
+ this.dbList[dbName].function('NOW', { deterministic: false }, () => new Date().toISOString().slice(0, 19).replace('T', ' '));
142
+ this.dbList[dbName].function('CURDATE', { deterministic: false }, () => new Date().toISOString().split('T')[0]);
143
+ this.dbList[dbName].function('DATE_FORMAT', { deterministic: true }, (dateStr, format) => {
144
+ const date = new Date(dateStr);
145
+ return format
146
+ .replace('%Y', date.getFullYear().toString())
147
+ .replace('%m', (date.getMonth() + 1).toString().padStart(2, '0'))
148
+ .replace('%d', date.getDate().toString().padStart(2, '0'))
149
+ .replace('%H', date.getHours().toString().padStart(2, '0'))
150
+ .replace('%i', date.getMinutes().toString().padStart(2, '0'))
151
+ .replace('%s', date.getSeconds().toString().padStart(2, '0'));
152
+ });
153
+ this.dbList[dbName].function('RAND', { deterministic: false }, () => Math.random());
154
+ this.dbList[dbName].function('UNIX_TIMESTAMP', { deterministic: false }, (dateStr) => dateStr
155
+ ? Math.floor(new Date(dateStr).getTime() / 1000)
156
+ : Math.floor(Date.now() / 1000));
139
157
  }
140
158
  }
141
159
  async export(dbName, exportPath) {