Skip to content

Commit

Permalink
fix(teach): some hacks to remove mysql from dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Oct 14, 2020
1 parent 25d7ba5 commit 16cc3ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/plugin-mysql/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -158,3 +158,6 @@ export default class MysqlDatabase {
this.pool.end()
}
}

MysqlDatabase.prototype.escape = escape
MysqlDatabase.prototype.escapeId = escapeId
5 changes: 3 additions & 2 deletions packages/plugin-teach/src/database/mysql.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 16cc3ee

Please sign in to comment.