0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

refactor: use getTableName() util

This commit is contained in:
bholmesdev 2024-01-17 16:25:42 -05:00 committed by Nate Moore
parent d4b57a5ca4
commit 4b4954e890

View file

@ -13,14 +13,21 @@ import {
type TextField, type TextField,
} from './types.js'; } from './types.js';
import { type LibSQLDatabase, drizzle } from 'drizzle-orm/libsql'; import { type LibSQLDatabase, drizzle } from 'drizzle-orm/libsql';
import { SQLiteAsyncDialect, SQLiteTable } from 'drizzle-orm/sqlite-core';
import { bold } from 'kleur/colors'; import { bold } from 'kleur/colors';
import { type SQL, type ColumnBuilderBaseConfig, type ColumnDataType, sql } from 'drizzle-orm';
import { import {
type SQL,
type ColumnBuilderBaseConfig,
type ColumnDataType,
sql,
getTableName,
} from 'drizzle-orm';
import {
SQLiteAsyncDialect,
customType, customType,
integer, integer,
sqliteTable, sqliteTable,
text, text,
type SQLiteTable,
type SQLiteColumnBuilderBase, type SQLiteColumnBuilderBase,
} from 'drizzle-orm/sqlite-core'; } from 'drizzle-orm/sqlite-core';
import { z } from 'zod'; import { z } from 'zod';
@ -45,10 +52,9 @@ function isReadableCollection(collection: DBCollection): collection is ReadableD
} }
function checkIfModificationIsAllowed(collections: DBCollections, Table: SQLiteTable) { function checkIfModificationIsAllowed(collections: DBCollections, Table: SQLiteTable) {
// This totally works, don't worry about it const tableName = getTableName(Table);
const tableName = (Table as any)[(SQLiteTable as any).Symbol.Name];
const collection = collections[tableName]; const collection = collections[tableName];
if (collection.writable) { if (!collection.writable) {
throw new Error(`The [${tableName}] collection is read-only.`); throw new Error(`The [${tableName}] collection is read-only.`);
} }
} }