From 16cc3eed017df367183ab61169197583727bf5d6 Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Wed, 14 Oct 2020 23:40:16 +0800 Subject: [PATCH] fix(teach): some hacks to remove mysql from dependency --- packages/plugin-mysql/src/database.ts | 7 +++++-- packages/plugin-teach/src/database/mysql.ts | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/plugin-mysql/src/database.ts b/packages/plugin-mysql/src/database.ts index 3ca9af3619..0fdde24cb0 100644 --- a/packages/plugin-mysql/src/database.ts +++ b/packages/plugin-mysql/src/database.ts @@ -22,8 +22,8 @@ export default class MysqlDatabase { public pool: Pool public config: Config - escape = escape - escapeId = escapeId + escape: typeof escape + escapeId: typeof escapeId constructor(public app: App, config: Config) { this.config = { @@ -158,3 +158,6 @@ export default class MysqlDatabase { this.pool.end() } } + +MysqlDatabase.prototype.escape = escape +MysqlDatabase.prototype.escapeId = escapeId diff --git a/packages/plugin-teach/src/database/mysql.ts b/packages/plugin-teach/src/database/mysql.ts index 031085910d..82329d44f7 100644 --- a/packages/plugin-teach/src/database/mysql.ts +++ b/packages/plugin-teach/src/database/mysql.ts @@ -1,8 +1,7 @@ import { Context, extendDatabase } from 'koishi-core' import { clone, defineProperty, Observed, pick } from 'koishi-utils' import { Dialogue, equal, DialogueTest } from '../utils' -import { escape } from 'mysql' -import MysqlDatabase from 'koishi-plugin-mysql/dist/database' +import type MysqlDatabase from 'koishi-plugin-mysql/dist/database' declare module 'koishi-core/dist/context' { interface EventMap { @@ -127,6 +126,8 @@ export default function apply(ctx: Context, config: Dialogue.Config) { }) ctx.on('dialogue/mysql', ({ regexp, answer, question, original }, conditionals) => { + const { escape } = require('koishi-plugin-mysql/dist/database').default.prototype as MysqlDatabase + if (regexp) { if (answer !== undefined) conditionals.push('`answer` REGEXP ' + escape(answer)) if (question !== undefined) conditionals.push('`question` REGEXP ' + escape(original))