Finalize Dexie-to-SQLite migration prep: docs, circular dep removal, SQL helpers, tests
- Removed all vestigial Dexie/USE_DEXIE_DB references from code and docs - Centralized DB logic in PlatformServiceMixin; resolved logger/databaseUtil circular dependency - Modularized SQL helpers (`$generateInsertStatement`, `$generateUpdateStatement`) and added unit tests - Created/updated migration tracking docs and helper script for cross-machine progress - Confirmed all lint/type checks and tests pass; ready for systematic file migration
This commit is contained in:
32
src/test/PlatformServiceMixin.test.ts
Normal file
32
src/test/PlatformServiceMixin.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import {
|
||||
generateInsertStatement,
|
||||
generateUpdateStatement,
|
||||
} from "@/utils/sqlHelpers";
|
||||
|
||||
describe("sqlHelpers SQL Statement Generation", () => {
|
||||
it("generates correct INSERT statement", () => {
|
||||
const contact = {
|
||||
name: "Alice",
|
||||
age: 30,
|
||||
isActive: true,
|
||||
tags: ["friend"],
|
||||
};
|
||||
const { sql, params } = generateInsertStatement(contact, "contacts");
|
||||
expect(sql).toBe(
|
||||
"INSERT INTO contacts (name, age, isActive, tags) VALUES (?, ?, ?, ?)",
|
||||
);
|
||||
expect(params).toEqual(["Alice", 30, 1, JSON.stringify(["friend"])]);
|
||||
});
|
||||
|
||||
it("generates correct UPDATE statement", () => {
|
||||
const changes = { name: "Bob", isActive: false };
|
||||
const { sql, params } = generateUpdateStatement(
|
||||
changes,
|
||||
"contacts",
|
||||
"id = ?",
|
||||
[42],
|
||||
);
|
||||
expect(sql).toBe("UPDATE contacts SET name = ?, isActive = ? WHERE id = ?");
|
||||
expect(params).toEqual(["Bob", 0, 42]);
|
||||
});
|
||||
});
|
||||
42
src/test/PlatformServiceMixinTest.vue
Normal file
42
src/test/PlatformServiceMixinTest.vue
Normal file
@@ -0,0 +1,42 @@
|
||||
<template>
|
||||
<div>
|
||||
<h2>PlatformServiceMixin Test</h2>
|
||||
<button @click="testInsert">Test Insert</button>
|
||||
<button @click="testUpdate">Test Update</button>
|
||||
<pre>{{ result }}</pre>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Options, Vue } from "vue-facing-decorator";
|
||||
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
|
||||
|
||||
@Options({
|
||||
mixins: [PlatformServiceMixin],
|
||||
})
|
||||
export default class PlatformServiceMixinTest extends Vue {
|
||||
result: string = "";
|
||||
|
||||
testInsert() {
|
||||
const contact = {
|
||||
name: "Alice",
|
||||
age: 30,
|
||||
isActive: true,
|
||||
tags: ["friend"],
|
||||
};
|
||||
const { sql, params } = this.$generateInsertStatement(contact, "contacts");
|
||||
this.result = `SQL: ${sql}\nParams: ${JSON.stringify(params)}`;
|
||||
}
|
||||
|
||||
testUpdate() {
|
||||
const changes = { name: "Bob", isActive: false };
|
||||
const { sql, params } = this.$generateUpdateStatement(
|
||||
changes,
|
||||
"contacts",
|
||||
"id = ?",
|
||||
[42],
|
||||
);
|
||||
this.result = `SQL: ${sql}\nParams: ${JSON.stringify(params)}`;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user