fix: satisfy database namespace lint
This commit is contained in:
1 parent
0a80d70730
commit
5cc2df19ed
2 files changed
+10
-5
No files matched your search
@@ -6,6 +6,8 @@ import { dbEnv } from "@homarr/core/infrastructure/db/env";
|
|||||||
import type { HomarrDatabase, HomarrDatabaseMysql, HomarrDatabasePostgresql } from "./driver";
|
import type { HomarrDatabase, HomarrDatabaseMysql, HomarrDatabasePostgresql } from "./driver";
|
||||||
import * as schema from "./schema";
|
import * as schema from "./schema";
|
||||||
|
|
||||||
|
const tables = { ...schema };
|
||||||
|
|
||||||
type TableKey = {
|
type TableKey = {
|
||||||
[K in keyof typeof schema]: (typeof schema)[K] extends { _: { brand: "Table" } } ? K : never;
|
[K in keyof typeof schema]: (typeof schema)[K] extends { _: { brand: "Table" } } ? K : never;
|
||||||
}[keyof typeof schema];
|
}[keyof typeof schema];
|
||||||
@@ -36,7 +38,7 @@ export const createDbInsertCollectionForTransaction = <TTableKey extends TableKe
|
|||||||
for (const [key, values] of objectEntries(context)) {
|
for (const [key, values] of objectEntries(context)) {
|
||||||
if (values.length >= 1) {
|
if (values.length >= 1) {
|
||||||
transaction
|
transaction
|
||||||
.insert(schema[key])
|
.insert(tables[key])
|
||||||
.values(values as never)
|
.values(values as never)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
@@ -50,7 +52,7 @@ export const createDbInsertCollectionForTransaction = <TTableKey extends TableKe
|
|||||||
for (const [key, values] of objectEntries(context)) {
|
for (const [key, values] of objectEntries(context)) {
|
||||||
if (values.length >= 1) {
|
if (values.length >= 1) {
|
||||||
// Below is actually the mysqlSchema when the driver is mysql
|
// Below is actually the mysqlSchema when the driver is mysql
|
||||||
await transaction.insert(schema[key] as never).values(values as never);
|
await transaction.insert(tables[key] as never).values(values as never);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import * as mysqlSchema from "../schema/mysql";
|
|||||||
import * as postgresqlSchema from "../schema/postgresql";
|
import * as postgresqlSchema from "../schema/postgresql";
|
||||||
import * as sqliteSchema from "../schema/sqlite";
|
import * as sqliteSchema from "../schema/sqlite";
|
||||||
|
|
||||||
|
const mysqlTables = { ...mysqlSchema };
|
||||||
|
const postgresqlTables = { ...postgresqlSchema };
|
||||||
|
|
||||||
// We need the following three types as there is currently no support for Buffer in mysql & pg and
|
// We need the following three types as there is currently no support for Buffer in mysql & pg and
|
||||||
// so we use a custom type which results in the config beeing different
|
// so we use a custom type which results in the config beeing different
|
||||||
type FixedMysqlConfig = {
|
type FixedMysqlConfig = {
|
||||||
@@ -63,7 +66,7 @@ test("schemas should match", () => {
|
|||||||
if (!("uniqueName" in sqliteColumn)) return;
|
if (!("uniqueName" in sqliteColumn)) return;
|
||||||
if (!("primary" in sqliteColumn)) return;
|
if (!("primary" in sqliteColumn)) return;
|
||||||
|
|
||||||
const mysqlTable = mysqlSchema[tableName];
|
const mysqlTable = mysqlTables[tableName];
|
||||||
|
|
||||||
const mysqlColumn = mysqlTable[columnName as keyof typeof mysqlTable] as object;
|
const mysqlColumn = mysqlTable[columnName as keyof typeof mysqlTable] as object;
|
||||||
if (!("isUnique" in mysqlColumn)) return;
|
if (!("isUnique" in mysqlColumn)) return;
|
||||||
@@ -84,7 +87,7 @@ test("schemas should match", () => {
|
|||||||
).toEqual(mysqlColumn.primary);
|
).toEqual(mysqlColumn.primary);
|
||||||
});
|
});
|
||||||
|
|
||||||
const mysqlTable = mysqlSchema[tableName];
|
const mysqlTable = mysqlTables[tableName];
|
||||||
const sqliteForeignKeys = sqliteTable[Symbol.for("drizzle:SQLiteInlineForeignKeys") as keyof typeof sqliteTable] as
|
const sqliteForeignKeys = sqliteTable[Symbol.for("drizzle:SQLiteInlineForeignKeys") as keyof typeof sqliteTable] as
|
||||||
| SqliteForeignKey[]
|
| SqliteForeignKey[]
|
||||||
| undefined;
|
| undefined;
|
||||||
@@ -144,7 +147,7 @@ test("schemas should match for postgresql", () => {
|
|||||||
objectEntries(sqliteSchema).forEach(([tableName, sqliteTable]) => {
|
objectEntries(sqliteSchema).forEach(([tableName, sqliteTable]) => {
|
||||||
// keys of sqliteSchema and postgresqlSchema are the same, so we can safely use tableName as key
|
// keys of sqliteSchema and postgresqlSchema are the same, so we can safely use tableName as key
|
||||||
// skipcq: JS-E1007
|
// skipcq: JS-E1007
|
||||||
const postgresqlTable = postgresqlSchema[tableName];
|
const postgresqlTable = postgresqlTables[tableName];
|
||||||
Object.entries(sqliteTable).forEach(([columnName, sqliteColumn]: [string, object]) => {
|
Object.entries(sqliteTable).forEach(([columnName, sqliteColumn]: [string, object]) => {
|
||||||
if (!("isUnique" in sqliteColumn)) return;
|
if (!("isUnique" in sqliteColumn)) return;
|
||||||
if (!("uniqueName" in sqliteColumn)) return;
|
if (!("uniqueName" in sqliteColumn)) return;
|
||||||
|
|||||||
Reference in new issue
Block a user