This commit is contained in:
2025-12-12 18:55:52 +08:00
parent fe7863fbb8
commit fa6db79cec
4 changed files with 152 additions and 0 deletions

10
src/auth/drizzle/one.ts Normal file
View File

@@ -0,0 +1,10 @@
import { drizzle } from 'drizzle-orm/node-postgres';
import { users } from './user.ts';
import dotenv from 'dotenv';
dotenv.config();
const db = drizzle(process.env.DATABASE_URL!);
const one = await db.select().from(users).limit(1);
console.log(one);

42
src/auth/drizzle/user.ts Normal file
View File

@@ -0,0 +1,42 @@
import { pgTable, serial, text, varchar, uuid, boolean, jsonb, timestamp } from "drizzle-orm/pg-core";
import { InferSelectModel, InferInsertModel } from "drizzle-orm";
export const users = pgTable('cf_user', {
id: uuid('id').primaryKey().defaultRandom(),
username: text('username').notNull().unique(),
nickname: text('nickname'),
password: text('password'),
email: text('email'),
avatar: text('avatar'),
salt: text('salt'),
description: text('description'),
type: text('type').notNull().default('user'),
owner: uuid('owner'),
orgId: uuid('orgId'),
needChangePassword: boolean('needChangePassword').notNull().default(false),
data: jsonb('data').notNull().default({}),
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt').notNull().defaultNow(),
deletedAt: timestamp('deletedAt'),
});
// 类型推断
export type User = InferSelectModel<typeof users>;
export type NewUser = InferInsertModel<typeof users>;
// 用户数据类型
export type UserData = {
orgs?: string[];
wxUnionId?: string;
phone?: string;
};
// 用户类型枚举
export enum UserTypes {
user = 'user',
org = 'org',
visitor = 'visitor',
}
// export class User {
// }