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;
}
}
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++;
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 "&":
@ -160,25 +178,16 @@ class SqlDumper {
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");

View File

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