@atri-bot/lib-db 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +29 -0
- package/dist/index.mjs +1 -0
- package/package.json +9 -11
- package/dist/index.d.ts +0 -17
- package/dist/index.js +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as _atri_bot_core0 from "@atri-bot/core";
|
|
2
|
+
import { AnyRelations, DrizzleConfig, EmptyRelations } from "drizzle-orm";
|
|
3
|
+
import * as drizzle_orm_bun_sql_postgres_driver0 from "drizzle-orm/bun-sql/postgres/driver";
|
|
4
|
+
import { MigrationConfig } from "drizzle-orm/migrator";
|
|
5
|
+
|
|
6
|
+
//#region src/index.d.ts
|
|
7
|
+
interface InitDbPluginOptions {
|
|
8
|
+
connectString: string;
|
|
9
|
+
config: DrizzleConfig;
|
|
10
|
+
}
|
|
11
|
+
declare function InitDbPlugin(options: InitDbPluginOptions): _atri_bot_core0.definePluginReturnType<object, {
|
|
12
|
+
pluginName: string;
|
|
13
|
+
install(): Promise<void>;
|
|
14
|
+
uninstall(): void;
|
|
15
|
+
}>;
|
|
16
|
+
interface DbPluginOptions<TSchema extends Record<string, unknown>, TRelations extends AnyRelations> {
|
|
17
|
+
config: DrizzleConfig<TSchema, TRelations>;
|
|
18
|
+
migration?: MigrationConfig;
|
|
19
|
+
}
|
|
20
|
+
declare function DbPlugin<TSchema extends Record<string, unknown>, TRelations extends AnyRelations = EmptyRelations>(options: DbPluginOptions<TSchema, TRelations>): _atri_bot_core0.definePluginReturnType<object, {
|
|
21
|
+
pluginName: string;
|
|
22
|
+
drizzle: drizzle_orm_bun_sql_postgres_driver0.BunSQLDatabase<TSchema, TRelations> & {
|
|
23
|
+
$client: Bun.SQL;
|
|
24
|
+
};
|
|
25
|
+
install(): Promise<void>;
|
|
26
|
+
uninstall(): void;
|
|
27
|
+
}>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { DbPlugin, DbPluginOptions, InitDbPlugin, InitDbPluginOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:process";import{definePlugin as t}from"@atri-bot/core";import{sql as n}from"drizzle-orm";import{drizzle as r}from"drizzle-orm/bun-sql";import{migrate as i}from"drizzle-orm/bun-sql/migrator";var a=`@atri-bot/lib-db`;let o=null;function s(i){return t({pluginName:`${a}-init-db`,async install(){try{await r(i.connectString,i.config).execute(n`SELECT 1;`),o=i.connectString,this.logger.INFO(`测试数据库连接成功`)}catch(t){this.logger.ERROR(`测试数据库连接失败`,t),e.exit(1)}},uninstall(){}})}function c(e){if(!o)throw Error(`请先通过 InitDbPlugin 插件初始化数据库连接`);return t({pluginName:`${a}-db`,drizzle:r(o??``,e.config),async install(){e.migration&&await i(this.drizzle,e.migration)},uninstall(){}})}export{c as DbPlugin,s as InitDbPlugin};
|
package/package.json
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atri-bot/lib-db",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.2.0",
|
|
4
5
|
"description": "db lib for atri framework",
|
|
5
6
|
"author": "huan_kong",
|
|
6
7
|
"license": "MIT",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
8
|
+
"main": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.mts",
|
|
10
10
|
"files": [
|
|
11
11
|
"./dist/**/*"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "
|
|
15
|
-
"clean": "rimraf dist",
|
|
14
|
+
"build": "tsdown",
|
|
16
15
|
"lint": "eslint",
|
|
17
|
-
"
|
|
18
|
-
"type-check": "tsc --noEmit -p tsconfig.json --composite false"
|
|
16
|
+
"typecheck": "tsc --noEmit -p tsconfig.json --composite false"
|
|
19
17
|
},
|
|
20
18
|
"dependencies": {
|
|
21
|
-
"@
|
|
22
|
-
"
|
|
23
|
-
"
|
|
19
|
+
"@atri-bot/core": "^2.0.0",
|
|
20
|
+
"@huan_kong/logger": "^2.0.2",
|
|
21
|
+
"drizzle-orm": "^1.0.0-beta.18-7eb39f0"
|
|
24
22
|
}
|
|
25
23
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { LogLevel, Logger } from '@huan_kong/logger';
|
|
2
|
-
import { Options, Sequelize } from 'sequelize';
|
|
3
|
-
|
|
4
|
-
type DbConfig = Options & {
|
|
5
|
-
debug?: boolean;
|
|
6
|
-
logLevel?: LogLevel;
|
|
7
|
-
baseDir: string;
|
|
8
|
-
};
|
|
9
|
-
declare class Db {
|
|
10
|
-
config: DbConfig;
|
|
11
|
-
logger: Logger;
|
|
12
|
-
sequelize: Sequelize;
|
|
13
|
-
dbs: Record<string, Sequelize>;
|
|
14
|
-
constructor(config: DbConfig);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { Db, type DbConfig };
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Logger as l,LogLevel as r}from"@huan_kong/logger";import g from"crypto";import n from"path";import{Sequelize as d}from"sequelize";var b={},s=class{config;logger;sequelize;dbs=b;constructor(e){this.config=e,this.logger=new l({title:"Db",level:e.logLevel??(e.debug?r.DEBUG:void 0)}),"logger"in e||(e.logging=e.debug?o=>this.logger.DEBUG(o):!1);let i={dialect:"sqlite",storage:n.join(e.baseDir,"./db.sqlite"),...e};i.dialect==="sqlite"&&"timezone"in i&&delete i.timezone;let t=g.createHash("sha256").update(JSON.stringify(i)).digest("hex");this.sequelize=this.dbs[t]??new d(i),this.dbs[t]=this.sequelize}};export{s as Db};
|