generated from tailored/app-template
temp
This commit is contained in:
@@ -1,3 +1,16 @@
|
||||
import { useContextKey } from '@kevisual/use-config/context';
|
||||
import { Redis } from 'ioredis';
|
||||
export const redis = useContextKey('redis', () => {
|
||||
const redis = new Redis({
|
||||
host: 'localhost',
|
||||
port: 6379,
|
||||
});
|
||||
return redis;
|
||||
});
|
||||
|
||||
export const redis = useContextKey('redis');
|
||||
const checkConnection = async () => {
|
||||
const res = await redis.ping();
|
||||
console.log('redis ping', res);
|
||||
};
|
||||
|
||||
// checkConnection();
|
||||
|
||||
12
src/modules/query.ts
Normal file
12
src/modules/query.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Query } from '@kevisual/query/query';
|
||||
import { QueryConfig } from '@kevisual/query-config';
|
||||
import { config } from './config.ts';
|
||||
|
||||
const baseURL = new URL(config.path, config.host);
|
||||
export const query = new Query({
|
||||
url: baseURL.toString(),
|
||||
});
|
||||
|
||||
export const queryConfig = new QueryConfig({
|
||||
query: query as any,
|
||||
});
|
||||
30
src/modules/sequelize.ts
Normal file
30
src/modules/sequelize.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Sequelize } from 'sequelize';
|
||||
import { useConfig } from '@kevisual/use-config/env';
|
||||
export const config = useConfig() as any;
|
||||
|
||||
export type PostgresConfig = {
|
||||
postgres: {
|
||||
username: string;
|
||||
password: string;
|
||||
host: string;
|
||||
port: number;
|
||||
database: string;
|
||||
};
|
||||
};
|
||||
if (!config.POSTGRES_PASSWORD || !config.POSTGRES_USER) {
|
||||
console.error('postgres config is required password and user');
|
||||
process.exit(1);
|
||||
}
|
||||
const postgresConfig = {
|
||||
username: config.POSTGRES_USER,
|
||||
password: config.POSTGRES_PASSWORD,
|
||||
host: config.POSTGRES_HOST || 'localhost',
|
||||
port: parseInt(config.POSTGRES_PORT || '5432'),
|
||||
database: config.POSTGRES_DB || 'postgres',
|
||||
};
|
||||
// connect to db
|
||||
export const sequelize = new Sequelize({
|
||||
dialect: 'postgres',
|
||||
...postgresConfig,
|
||||
// logging: false,
|
||||
});
|
||||
Reference in New Issue
Block a user