sql dumper

This commit is contained in:
Jan Prochazka
2020-03-02 22:22:44 +01:00
parent e038be12b9
commit b933e4577c
2 changed files with 31 additions and 22 deletions

View File

@@ -40,6 +40,11 @@ class SqlDumper {
break; break;
} }
} }
putFormattedList(c, collection) {
this.putCollection(", ", collection, item =>
this.putFormattedValue(c, item)
);
}
/** @param format {string} */ /** @param format {string} */
put(format, ...args) { put(format, ...args) {
let i = 0; let i = 0;
@@ -58,7 +63,20 @@ class SqlDumper {
case "%": case "%":
c = format[i]; c = format[i];
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++; argIndex++;
break; break;
case "&": case "&":
@@ -156,29 +174,20 @@ class SqlDumper {
/** @param table {import('@dbgate/types').TableInfo} */ /** @param table {import('@dbgate/types').TableInfo} */
createTable(table) { createTable(table) {
this.put("^create ^table %f ( &>&n", 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.put("%i", col.columnName);
this.columnDefinition(col); this.columnDefinition(col);
}); });
// bool first = true; if (table.primaryKey) {
// _primaryKeyWrittenInCreateTable = false; this.put(",&n");
// foreach (var col in table.Columns) if (table.primaryKey.constraintName) {
// { this.put("^constraint %i", table.primaryKey.constraintName);
// if (!first) Put(", &n"); }
// first = false; this.put(
// Put("%i ", col.Name); " ^primary ^key (%,i)",
// ColumnDefinition(col, true, true, true); table.primaryKey.columns.map(x => x.columnName)
// } );
// 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);
// }
// foreach (var cnt in table.ForeignKeys) // foreach (var cnt in table.ForeignKeys)
// { // {
// if (!first) Put(", &n"); // if (!first) Put(", &n");

View File

@@ -14,7 +14,7 @@ export interface ConstraintInfo extends NamedObjectInfo {
} }
export interface ColumnsConstraintInfo extends ConstraintInfo { export interface ColumnsConstraintInfo extends ConstraintInfo {
columns: ConstraintInfo[]; columns: ColumnReference[];
} }
export interface PrimaryKeyInfo extends ColumnsConstraintInfo {} export interface PrimaryKeyInfo extends ColumnsConstraintInfo {}