starwait/drizzle/customType.ts
2025-04-25 01:52:47 +08:00

27 lines
879 B
TypeScript

// | ------------------------------------------------------------
// | @版本: version 0.1
// | @创建人: 【Nie-x7129】
// | @E-mail: x71291@outlook.com
// | @所在项目: pac-auth
// | @文件描述: customType.ts -
// | @创建时间: 2024-06-04 16:27
// | @更新时间: 2024-06-04 16:27
// | @修改记录:
// | -*-*-*- (时间--修改人--修改说明) -*-*-*-
// | =
// | ------------------------------------------------------------
// 定义自定义类型
import { customType } from 'drizzle-orm/mysql-core';
// 写入读取是将bigint转化为string
export const bigintString = customType({
dataType() {
return 'bigint';
},
fromDriver(value) { // 数据库 -> JS
return value?.toString(); // 处理 null 值
},
toDriver(value) { // JS -> 数据库
return BigInt(value); // 确保写入时为数字类型
}
});