@csvw-rdf-convertor/core
Version:
This library was generated with [Nx](https://nx.dev).
37 lines (36 loc) • 1.29 kB
JavaScript
import { MultiMap } from 'mnemonist';
export class TableSchema {
get columns() {
return this._columns;
}
addColumns(...columns) {
this._columns.push(...columns);
}
/** you need to verify foreign keys integrity yourself */ removeColumns(...columns) {
if (columns.some((column)=>this.primaryKey.has(column))) {
throw new Error('Cannot remove a column that is part of the primary key');
}
this._columns = this._columns.filter((column)=>!columns.includes(column));
}
/** you need to verify foreign keys integrity yourself */ renameColumn(oldName, newName) {
if (this.columns.includes(newName)) {
throw new Error('Cannot rename to an existing column');
}
const i = this._columns.indexOf(oldName);
if (i === -1) {
throw new Error('Column not found');
}
this._columns[i] = newName;
if (this.primaryKey.delete(oldName)) {
this.primaryKey.delete(oldName);
this.primaryKey.add(newName);
}
}
constructor(name){
this.name = name;
this._columns = [];
this.primaryKey = new Set();
this.foreignKeys = new MultiMap(Set);
}
}
//# sourceMappingURL=table-schema.js.map