@maiyunnet/kebab 4.1.0 → 5.0.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.
@@ -63,7 +63,6 @@ export default class extends sCtr.Ctr {
63
63
  return rtn;
64
64
  }
65
65
  notfound() {
66
- // --- Set on route.php ---
67
66
  this._httpCode = 404;
68
67
  return 'Custom 404 page.';
69
68
  }
@@ -122,7 +121,7 @@ export default class extends sCtr.Ctr {
122
121
  `<br><br><a href="${this._config.const.urlBase}test/middle">View "test/middle"</a>`,
123
122
  '<br><br><b>Model test:</b>',
124
123
  '<br><br><b style="color: red;">In a production environment, please delete "mod/test.ts", "mod/testdata.ts" files.</b>',
125
- `<br><a href="${this._config.const.urlBase}test/mod-test">Click to see an example of a Test model</a>`,
124
+ `<br><a href="${this._config.const.urlBase}test/mod-test">Click to see an example of a Test model</a> <a href="${this._config.const.urlBase}test/mod-test?s=pgsql">pgsql</a>`,
126
125
  `<br><a href="${this._config.const.urlBase}test/mod-split">View "test/mod-split"</a>`,
127
126
  `<br><a href="${this._config.const.urlBase}test/mod-insert">View "test/mod-insert"</a>`,
128
127
  '<br><br><b>Library test:</b>',
@@ -145,7 +144,7 @@ export default class extends sCtr.Ctr {
145
144
  '<br><br><b>Crypto:</b>',
146
145
  `<br><br><a href="${this._config.const.urlBase}test/crypto">View "test/crypto"</a>`,
147
146
  '<br><br><b>Db:</b>',
148
- `<br><br><a href="${this._config.const.urlBase}test/db">View "test/db"</a>`,
147
+ `<br><br><a href="${this._config.const.urlBase}test/db">View "test/db"</a> <a href="${this._config.const.urlBase}test/db?s=pgsql">pgsql</a>`,
149
148
  `<br><br><b>Vector:</b>`,
150
149
  `<br><br><a href="${this._config.const.urlBase}test/vector">View "test/vector"</a>`,
151
150
  '<br><br><b>Kv:</b>',
@@ -180,14 +179,14 @@ export default class extends sCtr.Ctr {
180
179
  `<br><br><a href="${this._config.const.urlBase}test/captcha-fastbuild">View "test/captcha-fastbuild"</a>`,
181
180
  `<br><a href="${this._config.const.urlBase}test/captcha-base64">View "test/captcha-base64"</a>`,
182
181
  '<br><br><b>Sql:</b>',
183
- `<br><br><a href="${this._config.const.urlBase}test/sql?type=insert">View "test/sql?type=insert"</a>`,
184
- `<br><a href="${this._config.const.urlBase}test/sql?type=select">View "test/sql?type=select"</a>`,
185
- `<br><a href="${this._config.const.urlBase}test/sql?type=update">View "test/sql?type=update"</a>`,
186
- `<br><a href="${this._config.const.urlBase}test/sql?type=delete">View "test/sql?type=delete"</a>`,
187
- `<br><a href="${this._config.const.urlBase}test/sql?type=where">View "test/sql?type=where"</a>`,
188
- `<br><a href="${this._config.const.urlBase}test/sql?type=having">View "test/sql?type=having"</a>`,
189
- `<br><a href="${this._config.const.urlBase}test/sql?type=by">View "test/sql?type=by"</a>`,
190
- `<br><a href="${this._config.const.urlBase}test/sql?type=field">View "test/sql?type=field"</a>`,
182
+ `<br><br><a href="${this._config.const.urlBase}test/sql?type=insert">View "test/sql?type=insert"</a> <a href="${this._config.const.urlBase}test/sql?type=insert&s=pgsql">pgsql</a>`,
183
+ `<br><a href="${this._config.const.urlBase}test/sql?type=select">View "test/sql?type=select"</a> <a href="${this._config.const.urlBase}test/sql?type=select&s=pgsql">pgsql</a>`,
184
+ `<br><a href="${this._config.const.urlBase}test/sql?type=update">View "test/sql?type=update"</a> <a href="${this._config.const.urlBase}test/sql?type=update&s=pgsql">pgsql</a>`,
185
+ `<br><a href="${this._config.const.urlBase}test/sql?type=delete">View "test/sql?type=delete"</a> <a href="${this._config.const.urlBase}test/sql?type=delete&s=pgsql">pgsql</a>`,
186
+ `<br><a href="${this._config.const.urlBase}test/sql?type=where">View "test/sql?type=where"</a> <a href="${this._config.const.urlBase}test/sql?type=where&s=pgsql">pgsql</a>`,
187
+ `<br><a href="${this._config.const.urlBase}test/sql?type=having">View "test/sql?type=having"</a> <a href="${this._config.const.urlBase}test/sql?type=having&s=pgsql">pgsql</a>`,
188
+ `<br><a href="${this._config.const.urlBase}test/sql?type=by">View "test/sql?type=by"</a> <a href="${this._config.const.urlBase}test/sql?type=by&s=pgsql">pgsql</a>`,
189
+ `<br><a href="${this._config.const.urlBase}test/sql?type=field">View "test/sql?type=field"</a> <a href="${this._config.const.urlBase}test/sql?type=field&s=pgsql">pgsql</a>`,
191
190
  '<br><br><b>Jwt:</b>',
192
191
  `<br><br><a href="${this._config.const.urlBase}test/jwt">View "test/jwt"</a>`,
193
192
  `<br><a href="${this._config.const.urlBase}test/jwt?type=kv">View "test/jwt?type=kv"</a>`,
@@ -559,37 +558,42 @@ Result:<pre id="result">Nothing.</pre>` + this._getEnd();
559
558
  return retur;
560
559
  }
561
560
  const echo = ['<b style="color: red;">In a production environment, please delete the "mod/test.ts" file.</b>'];
562
- const db = lDb.get(this);
563
- let stmt = await db.query('SELECT * FROM `m_test` WHERE `token` LIMIT 1;');
561
+ const db = this._get['s'] === 'pgsql' ? lDb.get(this, {
562
+ 'service': lDb.ESERVICE.PGSQL,
563
+ }) : lDb.get(this);
564
+ let stmt = await db.query(this._get['s'] === 'pgsql' ?
565
+ 'SELECT * FROM "m"."test" LIMIT 1;' :
566
+ 'SELECT * FROM `m_test` LIMIT 1;');
564
567
  if (!stmt.rows) {
565
- return [0, 'Failed("m_test" not found).'];
568
+ return [0, this._get['s'] === 'pgsql' ?
569
+ 'Failed("m"."test" not found).' :
570
+ 'Failed("m_test" not found).'];
566
571
  }
567
572
  if (this._get['action'] === 'remove') {
568
573
  await mTest.removeByWhere(db, [
569
- ['token', 'LIKE', 'test_%']
574
+ ['token', 'LIKE', 'test_%'],
570
575
  ], {
571
- 'pre': this
576
+ 'pre': this._get['s'] === 'pgsql' ? 'm' : this,
572
577
  });
573
- return this._location('test/mod-test');
578
+ return this._location('test/mod-test' + (this._get['s'] === 'pgsql' ? '?s=pgsql' : ''));
574
579
  }
575
580
  else {
576
581
  const time = lTime.stamp();
577
582
  const test = mTest.getCreate(db, {
578
- 'ctr': this
583
+ 'ctr': this,
584
+ 'pre': this._get['s'] === 'pgsql' ? 'm' : undefined,
579
585
  });
580
586
  test.set({
581
587
  'name': 'nam' + lCore.rand(0, 3).toString(),
582
588
  'point': { 'x': lCore.rand(0, 99), 'y': lCore.rand(0, 99) },
583
589
  'polygon': [
584
- [
585
- { 'x': 1, 'y': 1 },
586
- { 'x': 2, 'y': 2 },
587
- { 'x': 3, 'y': 3 },
588
- { 'x': 1, 'y': 1 }
589
- ]
590
+ { 'x': 1, 'y': 1 },
591
+ { 'x': 2, 'y': 2 },
592
+ { 'x': 3, 'y': 3 },
593
+ { 'x': 1, 'y': 1 },
590
594
  ],
591
595
  'json': { 'x': { 'y': 'abc' } },
592
- 'time_add': time
596
+ 'time_add': time,
593
597
  });
594
598
  const result = await test.create();
595
599
  echo.push(`<pre>const time = lTime.stamp();
@@ -600,37 +604,38 @@ test.set({
600
604
  'name': 'nam' + lCore.rand(0, 4).toString(),
601
605
  'point': { 'x': lCore.rand(0, 99), 'y': lCore.rand(0, 99) },
602
606
  'polygon': [
603
- [
604
- { 'x': 1, 'y': 1 },
605
- { 'x': 2, 'y': 2 },
606
- { 'x': 3, 'y': 3 },
607
- { 'x': 1, 'y': 1 }
608
- ]
607
+ { 'x': 1, 'y': 1 },
608
+ { 'x': 2, 'y': 2 },
609
+ { 'x': 3, 'y': 3 },
610
+ { 'x': 1, 'y': 1 },
609
611
  ],
610
612
  'json': { 'x': { 'y': 'abc' } },
611
- 'time_add': time
613
+ 'time_add': time,
612
614
  });
613
615
  const result = await test.create();
614
616
  JSON.stringify(result));</pre>` + JSON.stringify(result));
615
617
  echo.push('<pre>JSON.stringify(test.toArray());</pre>' + lText.htmlescape(JSON.stringify(test.toArray())));
616
618
  echo.push('<br><br>Test table:');
617
- stmt = await db.query('SELECT * FROM `m_test` WHERE `token` LIKE \'test_%\' ORDER BY `id` ASC;');
619
+ stmt = await db.query(this._get['s'] === 'pgsql' ?
620
+ 'SELECT * FROM "m"."test" WHERE "token" LIKE \'test_%\' ORDER BY "id" ASC;' :
621
+ 'SELECT * FROM `m_test` WHERE `token` LIKE \'test_%\' ORDER BY `id` ASC;');
618
622
  this._dbTable(stmt, echo);
619
623
  // --- explain ---
620
624
  const ls = mTest.where(db, [
621
- ['time_add', '>', time - 60 * 5]
625
+ ['time_add', '>', time - 60 * 5],
622
626
  ], {
623
- 'ctr': this
627
+ 'ctr': this,
628
+ 'pre': this._get['s'] === 'pgsql' ? 'm' : undefined,
624
629
  });
625
630
  const r = await ls.explain();
626
631
  echo.push(`<pre>const ls = mTest.where<mTest>(db, [
627
- ['time_add', '>', time - 60 * 5]
632
+ ['time_add', '>', time - 60 * 5],
628
633
  ], {
629
- 'ctr': this
634
+ 'ctr': this,
630
635
  });
631
636
  const r = await ls.explain();</pre>` + lText.htmlescape(JSON.stringify(r)));
632
637
  const r2 = await ls.explain(true);
633
- echo.push('<pre>ls->explain(true);</pre>');
638
+ echo.push('<pre>ls.explain(true);</pre>');
634
639
  if (r2) {
635
640
  echo.push('<table style="width: 100%;">');
636
641
  for (const k in r2) {
@@ -645,7 +650,8 @@ const r = await ls.explain();</pre>` + lText.htmlescape(JSON.stringify(r)));
645
650
  let ft = await mTest.one(db, [
646
651
  ['time_add', '>', '0']
647
652
  ], {
648
- 'ctr': this
653
+ 'ctr': this,
654
+ 'pre': this._get['s'] === 'pgsql' ? 'm' : undefined,
649
655
  });
650
656
  echo.push(`<pre>await mTest.one<mTest>(db, [
651
657
  ['time_add', '>', '0']
@@ -673,7 +679,8 @@ const r = await ls.explain();</pre>` + lText.htmlescape(JSON.stringify(r)));
673
679
  });
674
680
  await ft.save();</pre>`);
675
681
  ft = await mTest.find(db, ft.id, {
676
- 'ctr': this
682
+ 'ctr': this,
683
+ 'pre': this._get['s'] === 'pgsql' ? 'm' : undefined,
677
684
  });
678
685
  if (!ft) {
679
686
  return '';
@@ -693,12 +700,10 @@ await ft.save();</pre>`);
693
700
  'y': 40
694
701
  },
695
702
  'polygon': [
696
- [
697
- { 'x': 5, 'y': 1 },
698
- { 'x': 6, 'y': 2 },
699
- { 'x': 7, 'y': 3 },
700
- { 'x': 5, 'y': 1 }
701
- ]
703
+ { 'x': 5, 'y': 1 },
704
+ { 'x': 6, 'y': 2 },
705
+ { 'x': 7, 'y': 3 },
706
+ { 'x': 5, 'y': 1 }
702
707
  ],
703
708
  'json': { 'x': { 'y': 'def' } }
704
709
  });
@@ -710,12 +715,10 @@ await ft.save();</pre>`);
710
715
  'y': 40
711
716
  },
712
717
  'polygon': [
713
- [
714
- { 'x': 5, 'y': 1 },
715
- { 'x': 6, 'y': 2 },
716
- { 'x': 7, 'y': 3 },
717
- { 'x': 5, 'y': 1 }
718
- ]
718
+ { 'x': 5, 'y': 1 },
719
+ { 'x': 6, 'y': 2 },
720
+ { 'x': 7, 'y': 3 },
721
+ { 'x': 5, 'y': 1 }
719
722
  ],
720
723
  'json': { 'x': { 'y': 'def' } }
721
724
  });
@@ -733,12 +736,12 @@ await ft.refresh();</pre>`);
733
736
  else {
734
737
  echo.push('<div>false</div>');
735
738
  }
736
- echo.push('<br><a href="' + this._config.const.urlBase + 'test/mod-test?action=remove">Remove all test data</a> | <a href="' + this._config.const.urlBase + 'test">Return</a>');
739
+ echo.push('<br><a href="' + this._config.const.urlBase + 'test/mod-test?action=remove' + (this._get['s'] === 'pgsql' ? '&s=pgsql' : '') + '">Remove all test data</a> | <a href="' + this._config.const.urlBase + 'test">Return</a>');
737
740
  return echo.join('') + '<br><br>' + this._getEnd();
738
741
  }
739
742
  }
740
743
  async modSplit() {
741
- const echo = ['<b style="color: red;">In a production environment, please delete "mod/test.php" and "mod/testdata.php" files.</b>'];
744
+ const echo = ['<b style="color: red;">In a production environment, please delete "mod/test.ts" and "mod/testdata.ts" files.</b>'];
742
745
  const db = lDb.get(this);
743
746
  echo.push(`<br><br>Test SQL:<pre>CREATE TABLE \`m_test\` (
744
747
  \`id\` INT NOT NULL AUTO_INCREMENT,
@@ -790,7 +793,8 @@ CREATE TABLE \`m_test_data_0\` (
790
793
  const db = lDb.get(this);
791
794
  const ids = [];
792
795
  const ls = await mTest.select(db, ['id'], {
793
- 'ctr': this
796
+ 'ctr': this,
797
+ 'index': ['1', '2']
794
798
  }).by('time_add').limit(0, 50).all();
795
799
  if (ls) {
796
800
  for (const item of ls) {
@@ -819,7 +823,7 @@ CREATE TABLE \`m_test_data_0\` (
819
823
  return [1, { 'id': id, 'index': index }];
820
824
  }
821
825
  async modInsert() {
822
- const echo = ['<b style="color: red;">In a production environment, please delete "mod/test.php" and "mod/testdata.php" files.</b>'];
826
+ const echo = ['<b style="color: red;">In a production environment, please delete "mod/test.ts" and "mod/testdata.ts" files.</b>'];
823
827
  const db = lDb.get(this);
824
828
  const datas = [];
825
829
  for (let i = 0; i < 20; ++i) {
@@ -1245,79 +1249,98 @@ JSON.stringify(r);</pre>${JSON.stringify(r)}`);
1245
1249
  }
1246
1250
  async db() {
1247
1251
  const echo = [(Math.round(this._getRunTime() * 10000000) / 10000).toString()];
1248
- const db = lDb.get(this);
1252
+ const db = lDb.get(this, {
1253
+ 'service': this._get['s'] === 'pgsql' ? lDb.ESERVICE.PGSQL : lDb.ESERVICE.MYSQL,
1254
+ });
1249
1255
  // --- 先获取 test 表的情况 ---
1250
- let stmt = await db.query('SELECT * FROM `m_test` ORDER BY `id` DESC LIMIT 10;');
1256
+ let sql = this._get['s'] === 'pgsql' ? 'SELECT * FROM "m"."test" ORDER BY "id" DESC LIMIT 10;' : 'SELECT * FROM `m_test` ORDER BY `id` DESC LIMIT 10;';
1257
+ let sql2 = '';
1258
+ let stmt = await db.query(sql);
1251
1259
  if (!stmt.rows) {
1252
1260
  return [0, stmt.error ? (stmt.error.message + '(' + stmt.error.errno.toString() + ')') : 'Failed("m_test" not found).'];
1253
1261
  }
1254
1262
  echo.push(`<pre>const db = lDb.get(this);
1255
- const stmt = await db.query('SELECT * FROM \`m_test\` ORDER BY \`id\` DESC LIMIT 10;');</pre>`);
1263
+ const stmt = await db.query('${sql}');</pre>`);
1256
1264
  this._dbTable(stmt, echo);
1257
1265
  echo.push('<br>ms: ' + (Math.round(this._getRunTime() * 10000000) / 10000).toString());
1258
1266
  // --- 插入 test-token 的条目 ---
1259
1267
  const time = lTime.stamp().toString();
1260
- let exec = await db.execute('INSERT INTO `m_test` (`token`, `point`, `time_add`) VALUES (\'test-token\', ST_POINTFROMTEXT(\'POINT(10 10)\'), \'' + time + '\');');
1268
+ let name = lCore.random(4);
1269
+ sql = this._get['s'] === 'pgsql' ?
1270
+ `INSERT INTO "m"."test" ("name", "token", "point", "time_add") VALUES ('${name}', 'test-token', '(1, 2)'::point, '${time}');` :
1271
+ 'INSERT INTO `m_test` (`name`, `token`, `point`, `time_add`) VALUES (\'' + name + '\', \'test-token\', ST_POINTFROMTEXT(\'POINT(10 10)\'), \'' + time + '\');';
1272
+ let exec = await db.execute(sql);
1261
1273
  let ms = (Math.round(this._getRunTime() * 10000000) / 10000).toString();
1262
- let insertId = 0;
1274
+ let insert = 0;
1263
1275
  if (exec.error?.errno === 1062) {
1264
- insertId = (await db.query('SELECT * FROM `m_test` WHERE `token` = \'test-token\';')).rows?.[0].id ?? 0;
1276
+ sql2 = this._get['s'] === 'pgsql' ?
1277
+ `SELECT * FROM "m"."test" WHERE "token" = 'test-token';` :
1278
+ 'SELECT * FROM `m_test` WHERE `token` = \'test-token\';';
1279
+ insert = (await db.query(sql2)).rows?.[0].id ?? 0;
1265
1280
  ms += ', ' + (Math.round(this._getRunTime() * 10000000) / 10000).toString();
1266
1281
  }
1267
1282
  else {
1268
- insertId = exec.packet?.insertId ?? 0;
1283
+ insert = exec.packet?.insert ?? 0;
1269
1284
  }
1270
1285
  echo.push(`<pre>const time = lTime.stamp().toString();
1271
- const exec = await db.execute('INSERT INTO \`m_test\` (\`token\`, \`data\`, \`time_update\`, \`time_add\`) VALUES (\\'test-token\\', ST_POINTFROMTEXT(\\'POINT(10 10)\\'), \\'' + time + '\\');');
1272
- let insertId: number = 0;
1286
+ const exec = await db.execute('${sql}');
1287
+ let insert: number = 0;
1273
1288
  if (exec.error?.errno === 1062) {
1274
- insertId = (await db.query('SELECT * FROM \`m_test\` WHERE \`token\` = \\'test-token\\';')).rows?.[0].id ?? 0;
1289
+ insert = (await db.query('${sql2}')).rows?.[0].id ?? 0;
1275
1290
  }
1276
1291
  else {
1277
- insertId = exec.packet?.insertId ?? 0;
1292
+ insert = exec.packet?.insertId ?? 0;
1278
1293
  }</pre>
1279
1294
  exec: ${JSON.stringify(exec)}<br>
1280
- insertId: ${JSON.stringify(insertId)}<br>
1295
+ insert: ${JSON.stringify(insert)}<br>
1281
1296
  errno: ${JSON.stringify(exec.error?.errno)}<br>
1282
1297
  error: ${JSON.stringify(exec.error)}<br>
1283
1298
  ms: ${ms}<br><br>`);
1284
1299
  // --- 获取最近的一条 ---
1285
- stmt = await db.query('SELECT * FROM `m_test` ORDER BY `id` DESC LIMIT 1;');
1300
+ sql = this._get['s'] === 'pgsql' ?
1301
+ `SELECT * FROM "m"."test" ORDER BY "id" DESC LIMIT 1;` :
1302
+ 'SELECT * FROM `m_test` ORDER BY `id` DESC LIMIT 1;';
1303
+ stmt = await db.query(sql);
1286
1304
  this._dbTable(stmt, echo);
1287
1305
  // --- 再次插入 test-token 的条目 ---
1288
- exec = await db.execute('INSERT INTO `m_test` (`token`, `point`, `time_add`) VALUES (\'test-token\', ST_POINTFROMTEXT(\'POINT(10 10)\'), \'' + time + '\');');
1289
- insertId = exec.packet?.insertId ?? 0;
1290
- echo.push(`<pre>exec = await db.execute('INSERT INTO \`m_test\` (\`token\`, \`point\`, \`time_add\`) VALUES (\\'test-token\\', ST_POINTFROMTEXT(\\'POINT(10 10)\\'), \\'' + time + '\\');');
1291
- insertId = exec.packet?.insertId ?? 0;</pre>
1306
+ name = lCore.random(4);
1307
+ sql = this._get['s'] === 'pgsql' ?
1308
+ `INSERT INTO "m"."test" ("name", "token", "point", "time_add") VALUES ('${name}', 'test-token', '(10, 10)'::point, '${time}');` :
1309
+ 'INSERT INTO `m_test` (`name`, `token`, `point`, `time_add`) VALUES (\'' + name + '\', \'test-token\', ST_POINTFROMTEXT(\'POINT(10 10)\'), \'' + time + '\');';
1310
+ exec = await db.execute(sql);
1311
+ insert = exec.packet?.insert ?? 0;
1312
+ echo.push(`<pre>exec = await db.execute('${sql}');
1313
+ insert = exec.packet?.insert ?? 0;</pre>
1292
1314
  exec: ${JSON.stringify(exec)}<br>
1293
- insertId: ${JSON.stringify(insertId)}<br>
1315
+ insert: ${JSON.stringify(insert)}<br>
1294
1316
  errno: ${JSON.stringify(exec.error?.errno)}<br>
1295
1317
  error: ${JSON.stringify(exec.error)}<br>
1296
1318
  ms: ${(Math.round(this._getRunTime() * 10000000) / 10000).toString()}<br>`);
1297
- // --- 依据唯一键替换值 ---
1298
- exec = await db.execute('REPLACE INTO `m_test` (`token`, `point`, `time_add`) VALUES (\'test-token\', ST_POINTFROMTEXT(\'POINT(20 20)\'), \'' + time + '\');');
1299
- insertId = exec.packet?.insertId ?? 0;
1300
- echo.push(`<pre>exec = await db.execute('REPLACE INTO \`m_session\` (\`token\`, \`point\`, \`time_add\`) VALUES (\\'test-token\\', ST_POINTFROMTEXT(\\'POINT(20 20)\\'), \\'' + time + '\\');');
1301
- insertId = exec.packet?.insertId ?? 0;</pre>
1302
- exec: ${JSON.stringify(exec)}<br>
1303
- insertId: ${JSON.stringify(insertId)}<br>
1304
- errno: ${JSON.stringify(exec.error?.errno)}<br>
1305
- error: ${JSON.stringify(exec.error)}<br>
1306
- ms: ${(Math.round(this._getRunTime() * 10000000) / 10000).toString()}<br><br>`);
1307
1319
  // --- 显示近 10 条 ---
1308
- stmt = await db.query('SELECT * FROM `m_test` ORDER BY `id` DESC LIMIT 10;');
1320
+ sql = this._get['s'] === 'pgsql' ?
1321
+ 'SELECT * FROM "m"."test" ORDER BY "id" DESC LIMIT 10;' :
1322
+ 'SELECT * FROM `m_test` ORDER BY `id` DESC LIMIT 10;';
1323
+ stmt = await db.query(sql);
1309
1324
  this._dbTable(stmt, echo);
1310
1325
  // --- explain 开始 ---
1311
- const explain = 'EXPLAIN';
1312
- stmt = await db.query(explain + ' SELECT * FROM `m_test` LIMIT 10;');
1313
- echo.push(`<pre>stmt = await db.query('${explain} SELECT * FROM \`m_test\` LIMIT 10;');</pre>`);
1326
+ sql = this._get['s'] === 'pgsql' ?
1327
+ 'EXPLAIN SELECT * FROM "m"."test" LIMIT 10;' :
1328
+ 'EXPLAIN SELECT * FROM `m_test` LIMIT 10;';
1329
+ stmt = await db.query(sql);
1330
+ echo.push(`<pre>stmt = await db.query('${sql}');</pre>`);
1314
1331
  this._dbTable(stmt, echo);
1315
1332
  echo.push('<br>ms: ' + (Math.round(this._getRunTime() * 10000000) / 10000).toString());
1316
1333
  // --- 删除测试添加的 token ---
1317
- exec = await db.execute('DELETE FROM `m_test` WHERE `token` = \'test-token\';');
1318
- echo.push(`<pre>exec = await db.execute('DELETE FROM \`m_test\` WHERE \`token\` = \\'test-token\\';');</pre>
1334
+ sql = this._get['s'] === 'pgsql' ?
1335
+ `DELETE FROM "m"."test" WHERE "token" = 'test-token';` :
1336
+ 'DELETE FROM `m_test` WHERE `token` = \'test-token\';';
1337
+ exec = await db.execute(sql);
1338
+ echo.push(`<pre>exec = await db.execute('${sql}');</pre>
1319
1339
  exec: ${JSON.stringify(exec)}<br><br>`);
1320
- stmt = await db.query('SELECT * FROM `m_test` ORDER BY `id` DESC LIMIT 10;');
1340
+ sql = this._get['s'] === 'pgsql' ?
1341
+ 'SELECT * FROM "m"."test" ORDER BY "id" DESC LIMIT 10;' :
1342
+ 'SELECT * FROM `m_test` ORDER BY `id` DESC LIMIT 10;';
1343
+ stmt = await db.query(sql);
1321
1344
  this._dbTable(stmt, echo);
1322
1345
  return echo.join('') + '<br>queries: ' + db.getQueries().toString() + '<br>' + this._getEnd();
1323
1346
  }
@@ -2229,7 +2252,9 @@ Result:<pre id="result">Nothing.</pre>`);
2229
2252
  }
2230
2253
  sql() {
2231
2254
  const echo = [];
2232
- let sql = lSql.get('test_');
2255
+ let sql = this._get['s'] === 'pgsql' ? lSql.get('test', {
2256
+ 'service': lSql.ESERVICE.PGSQL,
2257
+ }) : lSql.get('test_');
2233
2258
  switch (this._get['type']) {
2234
2259
  case 'insert': {
2235
2260
  let s = sql.insert('user').values(['name', 'age'], [
@@ -2255,24 +2280,6 @@ Result:<pre id="result">Nothing.</pre>`);
2255
2280
  echo.push(`<pre>sql.insert('user').values({ 'name': 'Bob', 'age': '24' });</pre>
2256
2281
  <b>getSql() :</b> ${s}<br>
2257
2282
  <b>getData():</b> <pre>${JSON.stringify(sd, undefined, 4)}</pre>
2258
- <b>format() :</b> ${sql.format(s, sd)}<hr>`);
2259
- s = sql.replace('user').values({ 'token': '20200202', 'name': 'Bob' }).getSql();
2260
- sd = sql.getData();
2261
- echo.push(`<pre>sql.replace('user').values({ 'token': '20200202', 'name': 'Bob' });</pre>
2262
- <b>getSql() :</b> ${s}<br>
2263
- <b>getData():</b> <pre>${JSON.stringify(sd, undefined, 4)}</pre>
2264
- <b>format() :</b> ${sql.format(s, sd)}<hr>`);
2265
- s = sql.insert('order').notExists('order', { 'name': 'Amy', 'age': '16', 'time_add': lTime.stamp(), 'point': ['POINT(?)', ['20']] }, { 'name': 'Amy' }).getSql();
2266
- sd = sql.getData();
2267
- echo.push(`<pre>sql.insert('order').notExists('order', { 'name': 'Amy', 'age': '16', 'time_add': lTime.stamp(), 'point': ['POINT(?)', ['20']] }, { 'name': 'Amy' });</pre>
2268
- <b>getSql() :</b> ${s}<br>
2269
- <b>getData():</b> <pre>${JSON.stringify(sd, undefined, 4)}</pre>
2270
- <b>format() :</b> ${sql.format(s, sd)}<hr>`);
2271
- s = sql.insert('verify').values({ 'token': 'abc', 'time_update': '10' }).duplicate({ 'time_update': ['CONCAT(`time_update`, ?)', ['01']] }).getSql();
2272
- sd = sql.getData();
2273
- echo.push(`<pre>sql.insert('verify').values({ 'token': 'abc', 'time_update': '10' }).duplicate({ 'time_update': ['CONCAT(\`time_update\`, ?)', ['01']] });</pre>
2274
- <b>getSql() :</b> ${s}<br>
2275
- <b>getData():</b> <pre>${JSON.stringify(sd, undefined, 4)}</pre>
2276
2283
  <b>format() :</b> ${sql.format(s, sd)}<hr>`);
2277
2284
  // --- insert 中使用函数 ---
2278
2285
  s = sql.insert('geo').values({ 'point': ['ST_POINTFROMTEXT(?)', ['POINT(122.147775 30.625014)']] }).getSql();
@@ -2362,9 +2369,9 @@ Result:<pre id="result">Nothing.</pre>`);
2362
2369
  <b>getSql() :</b> ${s}<br>
2363
2370
  <b>getData():</b> <pre>${JSON.stringify(sd, undefined, 4)}</pre>
2364
2371
  <b>format() :</b> ${sql.format(s, sd)}<hr>`);
2365
- s = sql.select(['o.*', 'u.nick as unick'], ['order o']).leftJoin('`user` AS u', { 'o.user_id': lSql.column('u.id'), 'state': '1' }).getSql();
2372
+ s = sql.select(['o.*', 'u.nick as unick'], ['order o']).leftJoin('`user` AS u', { 'o.user_id': lSql.column('u.id'), 'u.state': '1' }).getSql();
2366
2373
  sd = sql.getData();
2367
- echo.push(`<pre>sql.select(['o.*', 'u.nick as unick'], ['order o']).leftJoin('\`user\` AS u', { 'o.user_id': lSql.column('u.id'), 'state': '1' });</pre>
2374
+ echo.push(`<pre>sql.select(['o.*', 'u.nick as unick'], ['order o']).leftJoin('\`user\` AS u', { 'o.user_id': lSql.column('u.id'), 'u.state': '1' });</pre>
2368
2375
  <b>getSql() :</b> ${s}<br>
2369
2376
  <b>getData():</b> <pre>${JSON.stringify(sd, undefined, 4)}</pre>
2370
2377
  <b>format() :</b> ${sql.format(s, sd)}<hr>`);
@@ -1,6 +1,7 @@
1
1
  import * as lCore from '#kebab/lib/core.js';
2
2
  import sMod from '#kebab/sys/mod.js';
3
3
  /*
4
+ // --- MYSQL ---
4
5
  CREATE TABLE `m_test` (
5
6
  `id` int NOT NULL AUTO_INCREMENT,
6
7
  `name` char(4) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
@@ -14,6 +15,27 @@ CREATE TABLE `m_test` (
14
15
  UNIQUE INDEX `utoken`(`token` ASC) USING BTREE,
15
16
  UNIQUE INDEX `uname`(`name` ASC) USING BTREE
16
17
  ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
18
+ // --- PGSQL ---
19
+ CREATE TABLE "m"."test" (
20
+ "id" int8 NOT NULL GENERATED BY DEFAULT AS IDENTITY (INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1),
21
+ "name" char(4) COLLATE "pg_catalog"."default" NOT NULL,
22
+ "token" varchar(32) COLLATE "pg_catalog"."default" NOT NULL,
23
+ "point" point NOT NULL,
24
+ "polygon" polygon,
25
+ "json" jsonb,
26
+ "time_add" int8 NOT NULL,
27
+ CONSTRAINT "test_pkey" PRIMARY KEY ("id")
28
+ );
29
+ ALTER TABLE "m"."test" OWNER TO "postgres";
30
+ CREATE INDEX "time_add" ON "m"."test" USING btree (
31
+ "time_add" "pg_catalog"."int8_ops" ASC NULLS LAST
32
+ );
33
+ CREATE UNIQUE INDEX "uname" ON "m"."test" USING btree (
34
+ "name" COLLATE "pg_catalog"."default" "pg_catalog"."bpchar_ops" ASC NULLS LAST
35
+ );
36
+ CREATE UNIQUE INDEX "utoken" ON "m"."test" USING btree (
37
+ "token" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
38
+ );
17
39
  */
18
40
  export default class default_1 extends sMod {
19
41
  static { this._$table = 'test'; }