From 4b4954e8904e1d376177846779c4f8a4d27d9c34 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 17 Jan 2024 16:25:42 -0500 Subject: [PATCH] refactor: use getTableName() util --- packages/db/src/internal.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/db/src/internal.ts b/packages/db/src/internal.ts index 38814b02f3..7d9c2def1e 100644 --- a/packages/db/src/internal.ts +++ b/packages/db/src/internal.ts @@ -13,14 +13,21 @@ import { type TextField, } from './types.js'; import { type LibSQLDatabase, drizzle } from 'drizzle-orm/libsql'; -import { SQLiteAsyncDialect, SQLiteTable } from 'drizzle-orm/sqlite-core'; import { bold } from 'kleur/colors'; -import { type SQL, type ColumnBuilderBaseConfig, type ColumnDataType, sql } from 'drizzle-orm'; import { + type SQL, + type ColumnBuilderBaseConfig, + type ColumnDataType, + sql, + getTableName, +} from 'drizzle-orm'; +import { + SQLiteAsyncDialect, customType, integer, sqliteTable, text, + type SQLiteTable, type SQLiteColumnBuilderBase, } from 'drizzle-orm/sqlite-core'; import { z } from 'zod'; @@ -45,10 +52,9 @@ function isReadableCollection(collection: DBCollection): collection is ReadableD } function checkIfModificationIsAllowed(collections: DBCollections, Table: SQLiteTable) { - // This totally works, don't worry about it - const tableName = (Table as any)[(SQLiteTable as any).Symbol.Name]; + const tableName = getTableName(Table); const collection = collections[tableName]; - if (collection.writable) { + if (!collection.writable) { throw new Error(`The [${tableName}] collection is read-only.`); } }