mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 17:16:01 +00:00
insert rows
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import { Command, Insert, Update, Delete, UpdateField, Condition } from '@dbgate/sqltree';
|
||||
import { NamedObjectInfo } from '@dbgate/types';
|
||||
|
||||
export interface ChangeSetItem {
|
||||
pureName: string;
|
||||
@@ -189,3 +190,31 @@ export function revertChangeSetRowChanges(changeSet: ChangeSet, definition: Chan
|
||||
};
|
||||
return changeSet;
|
||||
}
|
||||
|
||||
export function getChangeSetInsertedRows(changeSet: ChangeSet, name?: NamedObjectInfo) {
|
||||
if (!name) return [];
|
||||
if (!changeSet) return [];
|
||||
const rows = changeSet.inserts.filter(x => x.pureName == name.pureName && x.schemaName == name.schemaName);
|
||||
const maxIndex = _.maxBy(rows, x => x.insertedRowIndex)?.insertedRowIndex;
|
||||
if (maxIndex == null) return [];
|
||||
const res = Array(maxIndex + 1).fill({});
|
||||
for (const row of rows) {
|
||||
res[row.insertedRowIndex] = row.fields;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
export function changeSetInsertNewRow(changeSet: ChangeSet, name?: NamedObjectInfo): ChangeSet {
|
||||
const insertedRows = getChangeSetInsertedRows(changeSet, name);
|
||||
return {
|
||||
...changeSet,
|
||||
inserts: [
|
||||
...changeSet.inserts,
|
||||
{
|
||||
...name,
|
||||
insertedRowIndex: insertedRows.length,
|
||||
fields: {},
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user