mirror of
https://github.com/stackrender/stackrender.git
synced 2026-09-10 03:05:42 +00:00
Develop Undo / Redo functionalitites for the indices
This commit is contained in:
@@ -47,18 +47,18 @@ const DatabaseHistoryProvider: React.FC<Props> = ({ children }) => {
|
||||
return;
|
||||
}
|
||||
const normalizedDatabase = normalizeDatabase(database);
|
||||
console.log (normalizedDatabase)
|
||||
|
||||
const normalizedPresent = normalizeDatabase(datatbaseState.present);
|
||||
const differences = compare(normalizedDatabase, normalizedPresent);
|
||||
|
||||
|
||||
if (differences && differences.length > 0) {
|
||||
setIsProcessing(true);
|
||||
|
||||
const operations: DBDiffOperation[] = mapDiffToDBDiffOperation(differences);
|
||||
console.log ( operations ) ;
|
||||
/*
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
console.log(operations)
|
||||
await executeDbDiffOps(operations)
|
||||
setIsProcessing(false);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ const DatabaseHistoryProvider: React.FC<Props> = ({ children }) => {
|
||||
setIsProcessing(false);
|
||||
}
|
||||
})()
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}, [datatbaseState.present]);
|
||||
|
||||
@@ -151,9 +151,7 @@ const DatabaseProvider: React.FC<Props> = ({ children }) => {
|
||||
})
|
||||
}, [db]);
|
||||
|
||||
|
||||
// CRUD operations for indices
|
||||
|
||||
const createIndex = useCallback(async (index: IndexInsertType): Promise<QueryResult> => {
|
||||
return await db.insert(indices).values({
|
||||
...index,
|
||||
@@ -253,6 +251,26 @@ const DatabaseProvider: React.FC<Props> = ({ children }) => {
|
||||
} else if (operation.type === "UPDATE_RELATIONSHIP") {
|
||||
await tx.update(relationships).set(operation.changes).where(eq(relationships.id, operation.relationshipId));
|
||||
}
|
||||
else if (operation.type == "CREATE_INDEX") {
|
||||
await tx.insert(indices).values(operation.index);
|
||||
if (operation.index.fieldIndices && Object.values(operation.index.fieldIndices).length > 0)
|
||||
await tx.insert(field_indices).values(Object.values(operation.index.fieldIndices));
|
||||
|
||||
}
|
||||
else if (operation.type == "DELETE_INDEX") {
|
||||
await tx.delete(indices).where(eq(indices.id, operation.indexId));
|
||||
}
|
||||
else if (operation.type == "UPDATE_INDEX") {
|
||||
await tx.update(indices).set(operation.changes).where(eq(indices.id, operation.indexId));
|
||||
|
||||
} else if (operation.type == "UPDATE_FIELD_INDICES") {
|
||||
if (operation.delete.length > 0) {
|
||||
await tx.delete(field_indices).where(inArray(field_indices.id, operation.delete))
|
||||
}
|
||||
if (operation.create.length > 0) {
|
||||
await tx.insert(field_indices).values(operation.create);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
@@ -66,7 +66,7 @@ export class StackRenderConnector implements PowerSyncBackendConnector {
|
||||
try {
|
||||
let batch: any[] = [];
|
||||
for (let operation of transaction.crud) {
|
||||
|
||||
|
||||
if (operation.op != UpdateType.DELETE && Object.keys(operation.opData as any).length == 0)
|
||||
continue
|
||||
|
||||
@@ -78,6 +78,7 @@ export class StackRenderConnector implements PowerSyncBackendConnector {
|
||||
};
|
||||
batch.push(payload);
|
||||
}
|
||||
|
||||
if (batch.length > 0) {
|
||||
|
||||
const response = await fetch(`${this.config.backendUrl}/api/data`, {
|
||||
|
||||
Reference in New Issue
Block a user