@@ -2,11 +2,16 @@ import mysql from "mysql2/promise";
2
2
import type { Connector } from "db0" ;
3
3
import { BoundableStatement } from "./_internal/statement" ;
4
4
5
- export type ConnectorOptions = mysql . ConnectionOptions
5
+ export type ConnectorOptions = mysql . ConnectionOptions ;
6
6
7
- type InternalQuery = ( sql : string , params ?: unknown [ ] ) => Promise < mysql . QueryResult >
7
+ type InternalQuery = (
8
+ sql : string ,
9
+ params ?: unknown [ ] ,
10
+ ) => Promise < mysql . QueryResult > ;
8
11
9
- export default function mysqlConnector ( opts : ConnectorOptions ) : Connector < mysql . Connection > {
12
+ export default function mysqlConnector (
13
+ opts : ConnectorOptions ,
14
+ ) : Connector < mysql . Connection > {
10
15
let _connection : mysql . Connection | undefined ;
11
16
const getConnection = async ( ) => {
12
17
if ( _connection ) {
@@ -15,19 +20,22 @@ export default function mysqlConnector(opts: ConnectorOptions): Connector<mysql.
15
20
16
21
_connection = await mysql . createConnection ( {
17
22
...opts ,
18
- } )
23
+ } ) ;
19
24
20
25
return _connection ;
21
26
} ;
22
27
23
- const query : InternalQuery = ( sql , params ) => getConnection ( ) . then ( ( c ) => c . query ( sql , params ) ) . then ( ( res ) => res [ 0 ] ) ;
28
+ const query : InternalQuery = ( sql , params ) =>
29
+ getConnection ( )
30
+ . then ( ( c ) => c . query ( sql , params ) )
31
+ . then ( ( res ) => res [ 0 ] ) ;
24
32
25
33
return {
26
34
name : "mysql" ,
27
35
dialect : "mysql" ,
28
36
getInstance : ( ) => getConnection ( ) ,
29
- exec : sql => query ( sql ) ,
30
- prepare : sql => new StatementWrapper ( sql , query )
37
+ exec : ( sql ) => query ( sql ) ,
38
+ prepare : ( sql ) => new StatementWrapper ( sql , query ) ,
31
39
} ;
32
40
}
33
41
@@ -42,20 +50,20 @@ class StatementWrapper extends BoundableStatement<void> {
42
50
}
43
51
44
52
async all ( ...params ) {
45
- const res = await this . #query( this . #sql, params ) as mysql . RowDataPacket [ ]
46
- return res
53
+ const res = ( await this . #query( this . #sql, params ) ) as mysql . RowDataPacket [ ] ;
54
+ return res ;
47
55
}
48
56
49
57
async run ( ...params ) {
50
- const res = await this . #query( this . #sql, params ) as mysql . RowDataPacket [ ]
58
+ const res = ( await this . #query( this . #sql, params ) ) as mysql . RowDataPacket [ ] ;
51
59
return {
52
60
success : true ,
53
61
...res ,
54
- }
62
+ } ;
55
63
}
56
64
57
65
async get ( ...params ) {
58
- const res = await this . #query( this . #sql, params ) as mysql . RowDataPacket [ ]
59
- return res [ 0 ]
66
+ const res = ( await this . #query( this . #sql, params ) ) as mysql . RowDataPacket [ ] ;
67
+ return res [ 0 ] ;
60
68
}
61
69
}
0 commit comments