Skip to content

Commit 3238a49

Browse files
committed
perf: remove unnecessary async/await
1 parent 31e4566 commit 3238a49

File tree

4 files changed

+95
-100
lines changed

4 files changed

+95
-100
lines changed

.changeset/cool-candles-strive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"slonik": patch
3+
---
4+
5+
remove unnecessary async/await

packages/slonik/src/binders/bindPool.ts

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -15,209 +15,209 @@ export const bindPool = (
1515
clientConfiguration: ClientConfiguration,
1616
): DatabasePool => {
1717
const boundPool = {
18-
any: async (query) => {
19-
return await createConnection(
18+
any: (query) => {
19+
return createConnection(
2020
parentLog,
2121
pool,
2222
clientConfiguration,
2323
'IMPLICIT_QUERY',
24-
async (connectionLog, connection, boundConnection) => {
25-
return await boundConnection.any(query);
24+
(connectionLog, connection, boundConnection) => {
25+
return boundConnection.any(query);
2626
},
27-
async (newPool) => {
28-
return await newPool.any(query);
27+
(newPool) => {
28+
return newPool.any(query);
2929
},
3030
query,
3131
);
3232
},
33-
anyFirst: async (query) => {
34-
return await createConnection(
33+
anyFirst: (query) => {
34+
return createConnection(
3535
parentLog,
3636
pool,
3737
clientConfiguration,
3838
'IMPLICIT_QUERY',
39-
async (connectionLog, connection, boundConnection) => {
40-
return await boundConnection.anyFirst(query);
39+
(connectionLog, connection, boundConnection) => {
40+
return boundConnection.anyFirst(query);
4141
},
42-
async (newPool) => {
43-
return await newPool.anyFirst(query);
42+
(newPool) => {
43+
return newPool.anyFirst(query);
4444
},
4545
query,
4646
);
4747
},
4848
configuration: clientConfiguration,
49-
connect: async (connectionHandler) => {
50-
return await createConnection(
49+
connect: (connectionHandler) => {
50+
return createConnection(
5151
parentLog,
5252
pool,
5353
clientConfiguration,
5454
'EXPLICIT',
55-
async (connectionLog, connection, boundConnection) => {
56-
return await connectionHandler(boundConnection);
55+
(connectionLog, connection, boundConnection) => {
56+
return connectionHandler(boundConnection);
5757
},
58-
async (newPool) => {
59-
return await newPool.connect(connectionHandler);
58+
(newPool) => {
59+
return newPool.connect(connectionHandler);
6060
},
6161
);
6262
},
6363
end: async () => {
6464
await pool.end();
6565
},
66-
exists: async (query) => {
67-
return await createConnection(
66+
exists: (query) => {
67+
return createConnection(
6868
parentLog,
6969
pool,
7070
clientConfiguration,
7171
'IMPLICIT_QUERY',
72-
async (connectionLog, connection, boundConnection) => {
73-
return await boundConnection.exists(query);
72+
(connectionLog, connection, boundConnection) => {
73+
return boundConnection.exists(query);
7474
},
75-
async (newPool) => {
76-
return await newPool.exists(query);
75+
(newPool) => {
76+
return newPool.exists(query);
7777
},
7878
query,
7979
);
8080
},
81-
many: async (query) => {
82-
return await createConnection(
81+
many: (query) => {
82+
return createConnection(
8383
parentLog,
8484
pool,
8585
clientConfiguration,
8686
'IMPLICIT_QUERY',
87-
async (connectionLog, connection, boundConnection) => {
88-
return await boundConnection.many(query);
87+
(connectionLog, connection, boundConnection) => {
88+
return boundConnection.many(query);
8989
},
90-
async (newPool) => {
91-
return await newPool.many(query);
90+
(newPool) => {
91+
return newPool.many(query);
9292
},
9393
query,
9494
);
9595
},
96-
manyFirst: async (query) => {
97-
return await createConnection(
96+
manyFirst: (query) => {
97+
return createConnection(
9898
parentLog,
9999
pool,
100100
clientConfiguration,
101101
'IMPLICIT_QUERY',
102-
async (connectionLog, connection, boundConnection) => {
103-
return await boundConnection.manyFirst(query);
102+
(connectionLog, connection, boundConnection) => {
103+
return boundConnection.manyFirst(query);
104104
},
105-
async (newPool) => {
106-
return await newPool.manyFirst(query);
105+
(newPool) => {
106+
return newPool.manyFirst(query);
107107
},
108108
query,
109109
);
110110
},
111-
maybeOne: async (query) => {
112-
return await createConnection(
111+
maybeOne: (query) => {
112+
return createConnection(
113113
parentLog,
114114
pool,
115115
clientConfiguration,
116116
'IMPLICIT_QUERY',
117-
async (connectionLog, connection, boundConnection) => {
118-
return await boundConnection.maybeOne(query);
117+
(connectionLog, connection, boundConnection) => {
118+
return boundConnection.maybeOne(query);
119119
},
120-
async (newPool) => {
121-
return await newPool.maybeOne(query);
120+
(newPool) => {
121+
return newPool.maybeOne(query);
122122
},
123123
query,
124124
);
125125
},
126-
maybeOneFirst: async (query) => {
127-
return await createConnection(
126+
maybeOneFirst: (query) => {
127+
return createConnection(
128128
parentLog,
129129
pool,
130130
clientConfiguration,
131131
'IMPLICIT_QUERY',
132-
async (connectionLog, connection, boundConnection) => {
133-
return await boundConnection.maybeOneFirst(query);
132+
(connectionLog, connection, boundConnection) => {
133+
return boundConnection.maybeOneFirst(query);
134134
},
135-
async (newPool) => {
136-
return await newPool.maybeOneFirst(query);
135+
(newPool) => {
136+
return newPool.maybeOneFirst(query);
137137
},
138138
query,
139139
);
140140
},
141-
one: async (query) => {
142-
return await createConnection(
141+
one: (query) => {
142+
return createConnection(
143143
parentLog,
144144
pool,
145145
clientConfiguration,
146146
'IMPLICIT_QUERY',
147-
async (connectionLog, connection, boundConnection) => {
148-
return await boundConnection.one(query);
147+
(connectionLog, connection, boundConnection) => {
148+
return boundConnection.one(query);
149149
},
150-
async (newPool) => {
151-
return await newPool.one(query);
150+
(newPool) => {
151+
return newPool.one(query);
152152
},
153153
query,
154154
);
155155
},
156-
oneFirst: async (query) => {
157-
return await createConnection(
156+
oneFirst: (query) => {
157+
return createConnection(
158158
parentLog,
159159
pool,
160160
clientConfiguration,
161161
'IMPLICIT_QUERY',
162-
async (connectionLog, connection, boundConnection) => {
163-
return await boundConnection.oneFirst(query);
162+
(connectionLog, connection, boundConnection) => {
163+
return boundConnection.oneFirst(query);
164164
},
165-
async (newPool) => {
166-
return await newPool.oneFirst(query);
165+
(newPool) => {
166+
return newPool.oneFirst(query);
167167
},
168168
query,
169169
);
170170
},
171-
query: async (query) => {
172-
return await createConnection(
171+
query: (query) => {
172+
return createConnection(
173173
parentLog,
174174
pool,
175175
clientConfiguration,
176176
'IMPLICIT_QUERY',
177-
async (connectionLog, connection, boundConnection) => {
178-
return await boundConnection.query(query);
177+
(connectionLog, connection, boundConnection) => {
178+
return boundConnection.query(query);
179179
},
180-
async (newPool) => {
181-
return await newPool.query(query);
180+
(newPool) => {
181+
return newPool.query(query);
182182
},
183183
query,
184184
);
185185
},
186186
state: () => {
187187
return pool.state();
188188
},
189-
stream: async (streamQuery, streamHandler) => {
190-
return await createConnection(
189+
stream: (streamQuery, streamHandler) => {
190+
return createConnection(
191191
parentLog,
192192
pool,
193193
clientConfiguration,
194194
'IMPLICIT_QUERY',
195-
async (connectionLog, connection, boundConnection) => {
196-
return await boundConnection.stream(streamQuery, streamHandler);
195+
(connectionLog, connection, boundConnection) => {
196+
return boundConnection.stream(streamQuery, streamHandler);
197197
},
198-
async (newPool) => {
199-
return await newPool.stream(streamQuery, streamHandler);
198+
(newPool) => {
199+
return newPool.stream(streamQuery, streamHandler);
200200
},
201201
streamQuery,
202202
);
203203
},
204-
transaction: async (transactionHandler, transactionRetryLimit) => {
205-
return await createConnection(
204+
transaction: (transactionHandler, transactionRetryLimit) => {
205+
return createConnection(
206206
parentLog,
207207
pool,
208208
clientConfiguration,
209209
'IMPLICIT_TRANSACTION',
210-
async (connectionLog, connection) => {
211-
return await transaction(
210+
(connectionLog, connection) => {
211+
return transaction(
212212
connectionLog,
213213
connection,
214214
clientConfiguration,
215215
transactionHandler,
216216
transactionRetryLimit,
217217
);
218218
},
219-
async (newPool) => {
220-
return await newPool.transaction(transactionHandler);
219+
(newPool) => {
220+
return newPool.transaction(transactionHandler);
221221
},
222222
);
223223
},

packages/slonik/src/binders/bindPoolConnection.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,8 @@ export const bindPoolConnection = (
2929
anyFirst: (slonikSql) => {
3030
return anyFirst(parentLog, connection, clientConfiguration, slonikSql);
3131
},
32-
exists: async (slonikSql) => {
33-
return await exists(
34-
parentLog,
35-
connection,
36-
clientConfiguration,
37-
slonikSql,
38-
);
32+
exists: (slonikSql) => {
33+
return exists(parentLog, connection, clientConfiguration, slonikSql);
3934
},
4035
many: (slonikSql) => {
4136
return many(parentLog, connection, clientConfiguration, slonikSql);
@@ -63,8 +58,8 @@ export const bindPoolConnection = (
6358
query: (slonikSql) => {
6459
return queryMethod(parentLog, connection, clientConfiguration, slonikSql);
6560
},
66-
stream: async (slonikSql, streamHandler) => {
67-
return await stream(
61+
stream: (slonikSql, streamHandler) => {
62+
return stream(
6863
parentLog,
6964
connection,
7065
clientConfiguration,
@@ -73,8 +68,8 @@ export const bindPoolConnection = (
7368
undefined,
7469
);
7570
},
76-
transaction: async (handler, transactionRetryLimit) => {
77-
return await transaction(
71+
transaction: (handler, transactionRetryLimit) => {
72+
return transaction(
7873
parentLog,
7974
connection,
8075
clientConfiguration,

packages/slonik/src/binders/bindTransactionConnection.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,10 @@ export const bindTransactionConnection = (
4949
},
5050
emit: eventEmitter.emit.bind(eventEmitter),
5151
eventNames: eventEmitter.eventNames.bind(eventEmitter),
52-
exists: async (slonikSql) => {
52+
exists: (slonikSql) => {
5353
assertTransactionDepth();
5454

55-
return await exists(
56-
parentLog,
57-
connection,
58-
clientConfiguration,
59-
slonikSql,
60-
);
55+
return exists(parentLog, connection, clientConfiguration, slonikSql);
6156
},
6257
getMaxListeners: eventEmitter.getMaxListeners.bind(eventEmitter),
6358
listenerCount: eventEmitter.listenerCount.bind(eventEmitter),
@@ -111,21 +106,21 @@ export const bindTransactionConnection = (
111106
removeAllListeners: eventEmitter.removeAllListeners.bind(eventEmitter),
112107
removeListener: eventEmitter.removeListener.bind(eventEmitter),
113108
setMaxListeners: eventEmitter.setMaxListeners.bind(eventEmitter),
114-
stream: async (slonikSql, streamHandler) => {
109+
stream: (slonikSql, streamHandler) => {
115110
assertTransactionDepth();
116111

117-
return await stream(
112+
return stream(
118113
parentLog,
119114
connection,
120115
clientConfiguration,
121116
slonikSql,
122117
streamHandler,
123118
);
124119
},
125-
transaction: async (handler, transactionRetryLimit) => {
120+
transaction: (handler, transactionRetryLimit) => {
126121
assertTransactionDepth();
127122

128-
return await nestedTransaction(
123+
return nestedTransaction(
129124
parentLog,
130125
connection,
131126
clientConfiguration,

0 commit comments

Comments
 (0)