mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
sql dumper
This commit is contained in:
parent
e038be12b9
commit
b933e4577c
@ -40,6 +40,11 @@ class SqlDumper {
|
||||
break;
|
||||
}
|
||||
}
|
||||
putFormattedList(c, collection) {
|
||||
this.putCollection(", ", collection, item =>
|
||||
this.putFormattedValue(c, item)
|
||||
);
|
||||
}
|
||||
/** @param format {string} */
|
||||
put(format, ...args) {
|
||||
let i = 0;
|
||||
@ -58,7 +63,20 @@ class SqlDumper {
|
||||
case "%":
|
||||
c = format[i];
|
||||
i++;
|
||||
this.putFormattedValue(c, args[argIndex]);
|
||||
switch (c) {
|
||||
case "%":
|
||||
this.putRaw("%");
|
||||
break;
|
||||
case ",":
|
||||
c = format[i];
|
||||
i++;
|
||||
this.putFormattedList(c, args[argIndex]);
|
||||
break;
|
||||
default:
|
||||
this.putFormattedValue(c, args[argIndex]);
|
||||
break;
|
||||
}
|
||||
|
||||
argIndex++;
|
||||
break;
|
||||
case "&":
|
||||
@ -156,29 +174,20 @@ class SqlDumper {
|
||||
/** @param table {import('@dbgate/types').TableInfo} */
|
||||
createTable(table) {
|
||||
this.put("^create ^table %f ( &>&n", table);
|
||||
this.putCollection(", &n", table.columns, col => {
|
||||
this.putCollection(",&n", table.columns, col => {
|
||||
this.put("%i", col.columnName);
|
||||
this.columnDefinition(col);
|
||||
});
|
||||
// bool first = true;
|
||||
// _primaryKeyWrittenInCreateTable = false;
|
||||
// foreach (var col in table.Columns)
|
||||
// {
|
||||
// if (!first) Put(", &n");
|
||||
// first = false;
|
||||
// Put("%i ", col.Name);
|
||||
// ColumnDefinition(col, true, true, true);
|
||||
// }
|
||||
// if (table.PrimaryKey != null && !_primaryKeyWrittenInCreateTable)
|
||||
// {
|
||||
// if (!first) Put(", &n");
|
||||
// first = false;
|
||||
// if (table.PrimaryKey.ConstraintName != null)
|
||||
// {
|
||||
// Put("^constraint %i", table.PrimaryKey.ConstraintName);
|
||||
// }
|
||||
// Put(" ^primary ^key (%,i)", table.PrimaryKey.Columns);
|
||||
// }
|
||||
if (table.primaryKey) {
|
||||
this.put(",&n");
|
||||
if (table.primaryKey.constraintName) {
|
||||
this.put("^constraint %i", table.primaryKey.constraintName);
|
||||
}
|
||||
this.put(
|
||||
" ^primary ^key (%,i)",
|
||||
table.primaryKey.columns.map(x => x.columnName)
|
||||
);
|
||||
}
|
||||
// foreach (var cnt in table.ForeignKeys)
|
||||
// {
|
||||
// if (!first) Put(", &n");
|
||||
|
2
packages/types/dbinfo.d.ts
vendored
2
packages/types/dbinfo.d.ts
vendored
@ -14,7 +14,7 @@ export interface ConstraintInfo extends NamedObjectInfo {
|
||||
}
|
||||
|
||||
export interface ColumnsConstraintInfo extends ConstraintInfo {
|
||||
columns: ConstraintInfo[];
|
||||
columns: ColumnReference[];
|
||||
}
|
||||
|
||||
export interface PrimaryKeyInfo extends ColumnsConstraintInfo {}
|
||||
|
Loading…
Reference in New Issue
Block a user