mysql-dashboard 0.2.0 → 0.2.1

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/lib/index.js CHANGED
@@ -450,6 +450,21 @@ function buildCreateTableStatement(tableIdent, columns) {
450
450
  ${lines.join(",\n ")}
451
451
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`;
452
452
  }
453
+ function buildModifyColumnPositionClause(m) {
454
+ if (m.placeFirst) {
455
+ return " FIRST";
456
+ }
457
+ const a = m.afterColumn?.trim();
458
+ if (!a) {
459
+ return "";
460
+ }
461
+ assertColumnName(a);
462
+ const effectiveName = m.newName?.trim() && m.newName.trim() !== m.columnName ? m.newName.trim() : m.columnName;
463
+ if (a === effectiveName) {
464
+ throw new Error("\u4E0D\u80FD\u4F7F\u7528 AFTER \u6307\u5411\u5F53\u524D\u5B57\u6BB5\u672C\u8EAB");
465
+ }
466
+ return ` AFTER ${escapeIdentifier(a)}`;
467
+ }
453
468
  function buildAddColumnClause(col) {
454
469
  assertColumnName(col.name.trim());
455
470
  assertColumnType(col.columnType);
@@ -499,6 +514,15 @@ async function getPrimaryKeyColumns(conn, databaseName, tableName) {
499
514
  );
500
515
  return rows.map((r) => r.COLUMN_NAME);
501
516
  }
517
+ async function getTableColumnNamesInOrder(conn, databaseName, tableName) {
518
+ const [rows] = await conn.query(
519
+ `SELECT COLUMN_NAME FROM information_schema.COLUMNS
520
+ WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?
521
+ ORDER BY ORDINAL_POSITION`,
522
+ [databaseName, tableName]
523
+ );
524
+ return rows.map((r) => r.COLUMN_NAME);
525
+ }
502
526
  function attachRowKeys(row, pkCols) {
503
527
  if (pkCols.length === 0) {
504
528
  return row;
@@ -646,6 +670,7 @@ function stripMetaFields(obj) {
646
670
  const result = await withMysqlConnection(connection, async (conn) => {
647
671
  await conn.query(`USE ${escapeIdentifier(body.databaseName)}`);
648
672
  const pkCols = await getPrimaryKeyColumns(conn, body.databaseName, body.collectionName);
673
+ const columnNames = await getTableColumnNamesInOrder(conn, body.databaseName, body.collectionName);
649
674
  const [rows] = await conn.query(
650
675
  `SELECT * FROM ${table} LIMIT ? OFFSET ?`,
651
676
  [pageSize, skip]
@@ -655,6 +680,7 @@ function stripMetaFields(obj) {
655
680
  const documents = rows.map((r) => attachRowKeys({ ...r }, pkCols));
656
681
  return {
657
682
  documents,
683
+ columnNames,
658
684
  total,
659
685
  page,
660
686
  pageSize,
@@ -924,13 +950,14 @@ function stripMetaFields(obj) {
924
950
  const draft = buildModifyDraft(m);
925
951
  const newN = m.newName?.trim() && m.newName.trim() !== m.columnName ? m.newName.trim() : m.columnName;
926
952
  const attr = buildColumnAttributesSql(draft);
953
+ const pos = buildModifyColumnPositionClause(m);
927
954
  if (newN !== m.columnName) {
928
955
  await conn.query(
929
- `ALTER TABLE ${table} CHANGE COLUMN ${escapeIdentifier(m.columnName)} ${escapeIdentifier(newN)} ${attr}`
956
+ `ALTER TABLE ${table} CHANGE COLUMN ${escapeIdentifier(m.columnName)} ${escapeIdentifier(newN)} ${attr}${pos}`
930
957
  );
931
958
  } else {
932
959
  await conn.query(
933
- `ALTER TABLE ${table} MODIFY COLUMN ${escapeIdentifier(m.columnName)} ${attr}`
960
+ `ALTER TABLE ${table} MODIFY COLUMN ${escapeIdentifier(m.columnName)} ${attr}${pos}`
934
961
  );
935
962
  }
936
963
  }
package/output/index.html CHANGED
@@ -8,6 +8,6 @@
8
8
  </head>
9
9
  <body>
10
10
  <div id="root"></div>
11
- <script src="/static/index.js?c8dbb6da"></script>
11
+ <script src="/static/index.js?1229983b"></script>
12
12
  </body>
13
13
  </html>