Skip to content

Commit

Permalink
feat(mysql): support $random eval operation (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ifrvn committed Apr 13, 2023
1 parent 2339a64 commit bcb6e84
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/mysql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createPool, format } from '@vlasky/mysql'
import type { OkPacket, Pool, PoolConfig } from 'mysql'
import { Dict, difference, makeArray, pick, Time } from 'cosmokit'
import { Database, Driver, Eval, executeUpdate, Field, isEvalExpr, Model, RuntimeError, Selection } from '@minatojs/core'
import { Builder, escapeId } from '@minatojs/sql-utils'
import { Builder, escapeId, transformRandom } from '@minatojs/sql-utils'
import Logger from 'reggol'

declare module 'mysql' {
Expand Down Expand Up @@ -305,6 +305,7 @@ export class MySQLDriver extends Driver {

query<T = any>(sql: string): Promise<T> {
const error = new Error()
sql = transformRandom(sql, 'RAND()')
return new Promise((resolve, reject) => {
this.pool.query(sql, (err: Error, results) => {
if (!err) return resolve(results)
Expand Down

0 comments on commit bcb6e84

Please sign in to comment.