Skip to content

piying-org/piying-orm

Repository files navigation

NPM Version Coverage Status MIT License

document

Use

import { convert, column, columnPrimaryKey } from "@piying/orm/typeorm";
import * as v from 'valibot';
export const Account = v.pipe(
  v.object({
    id: v.pipe(v.string(), columnPrimaryKey({ generated: "uuid" })),
    createdAt: v.pipe(v.date(), column({ createDate: true })),
    updateAt: v.pipe(v.date(), column({ updateDate: true })),
    username: v.pipe(v.string(), v.title("用户名"), column({ length: 50 })),
  }),
);
const instance = convert(
  {
    Account,
  },
  {
    dataSourceOptions: {
      type: "better-sqlite3",
      database: path.join(process.cwd(), ".tmp", "data.sqlite"),
      synchronize: false,
      logging: true,
    },
  },
);
await instance.dataSource.initialize();
result.object.Account;