forked from imbytecat/fullstack-starter
refactor: 移除本地数据库依赖并清理废弃模块
- 移除对本地数据库包的依赖并更新客户端、合约和服务器包的引用为目录源。 - 移除对本地数据库包的依赖引用并清理相关配置 - 删除数据库包的配置文件及依赖项 - 移除对 todo 模式的导出,清理已废弃的模块引用。 - 删除待办事项表的定义及相关字段配置 - 删除已废弃的字段生成工具函数及对应配置,移除对 uuidv7 和 PostgreSQL 特定生成策略的依赖。 - 移除字段工具导出,不再从字段工具模块导出内容 - 删除 SQLite 数据库模块的初始化文件 - 删除数据库包中的 TypeScript 配置文件以统一项目配置
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"name": "@furtherverse/database",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"imports": {
|
||||
"#*": "./src/*"
|
||||
},
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./*": "./src/*.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"fix": "biome check --write",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"drizzle-orm": "catalog:",
|
||||
"uuid": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@furtherverse/tsconfig": "workspace:*"
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './todo'
|
||||
@@ -1,8 +0,0 @@
|
||||
import { boolean, pgTable, text } from 'drizzle-orm/pg-core'
|
||||
import { generatedFields } from '../utils'
|
||||
|
||||
export const todoTable = pgTable('todo', {
|
||||
...generatedFields,
|
||||
title: text('title').notNull(),
|
||||
completed: boolean('completed').notNull().default(false),
|
||||
})
|
||||
@@ -1,58 +0,0 @@
|
||||
import { sql } from 'drizzle-orm'
|
||||
import { timestamp, uuid } from 'drizzle-orm/pg-core'
|
||||
import { v7 as uuidv7 } from 'uuid'
|
||||
|
||||
// id
|
||||
|
||||
export const id = (name: string) => uuid(name)
|
||||
export const pk = (name: string, strategy?: 'native' | 'extension') => {
|
||||
switch (strategy) {
|
||||
// PG 18+
|
||||
case 'native':
|
||||
return id(name).primaryKey().default(sql`uuidv7()`)
|
||||
|
||||
// PG 13+ with extension
|
||||
case 'extension':
|
||||
return id(name).primaryKey().default(sql`uuid_generate_v7()`)
|
||||
|
||||
// Any PG version
|
||||
default:
|
||||
return id(name)
|
||||
.primaryKey()
|
||||
.$defaultFn(() => uuidv7())
|
||||
}
|
||||
}
|
||||
|
||||
// timestamp
|
||||
|
||||
export const createdAt = (name = 'created_at') =>
|
||||
timestamp(name, { withTimezone: true }).notNull().defaultNow()
|
||||
|
||||
export const updatedAt = (name = 'updated_at') =>
|
||||
timestamp(name, { withTimezone: true })
|
||||
.notNull()
|
||||
.defaultNow()
|
||||
.$onUpdateFn(() => new Date())
|
||||
|
||||
// generated fields
|
||||
|
||||
export const generatedFields = {
|
||||
id: pk('id'),
|
||||
createdAt: createdAt('created_at'),
|
||||
updatedAt: updatedAt('updated_at'),
|
||||
}
|
||||
|
||||
// Helper to create omit keys from generatedFields
|
||||
const createGeneratedFieldKeys = <T extends Record<string, unknown>>(
|
||||
fields: T,
|
||||
): Record<keyof T, true> => {
|
||||
return Object.keys(fields).reduce(
|
||||
(acc, key) => {
|
||||
acc[key as keyof T] = true
|
||||
return acc
|
||||
},
|
||||
{} as Record<keyof T, true>,
|
||||
)
|
||||
}
|
||||
|
||||
export const generatedFieldKeys = createGeneratedFieldKeys(generatedFields)
|
||||
@@ -1 +0,0 @@
|
||||
export * from './field'
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "@furtherverse/tsconfig/base.json"
|
||||
}
|
||||
Reference in New Issue
Block a user