feat: add models init

This commit is contained in:
2025-02-28 09:37:22 +08:00
parent b5242d0734
commit e96a246c14
9 changed files with 148 additions and 32 deletions

4
src/modules/init.ts Normal file
View File

@@ -0,0 +1,4 @@
import { useContextKey, useContext } from '@kevisual/use-config/context';
import { sequelize } from './sequelize.ts';
export { sequelize };

View File

@@ -1,5 +1,6 @@
import { useConfig } from '@kevisual/use-config';
import { Sequelize } from 'sequelize';
import { useContextKey, useContext } from '@kevisual/use-config/context';
type PostgresConfig = {
postgres: {
@@ -19,8 +20,11 @@ if (!postgresConfig) {
process.exit(1);
}
// connect to db
export const sequelize = new Sequelize({
dialect: 'postgres',
...postgresConfig,
// logging: false,
});
export const init = () => {
return new Sequelize({
dialect: 'postgres',
...postgresConfig,
// logging: false,
});
};
export const sequelize = useContextKey('sequelize', init);