-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
4,050 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
ITERATIONS=50 | ||
ROUNDS=10 | ||
LOG=false | ||
POSTGRES_URL="postgres://postgres:postgres@localhost:15432/postgres" | ||
POSTGRES_URL="postgres://postgres:postgres@localhost:15432/postgres" | ||
MYSQL_URL="mysql://test:test@localhost:13306/test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { exit } from 'node:process'; | ||
import db from './mysql' | ||
|
||
const ITERATIONS = Number.parseInt(process.env.ITERATIONS); | ||
const ROUNDS = Number.parseInt(process.env.ROUNDS); | ||
const POOLSIZE = Number.parseInt(process.env.POOLSIZE); | ||
|
||
benchmark(); | ||
|
||
async function benchmark() { | ||
await warmup(); | ||
console.time(`drizzle:pool ${POOLSIZE}`); | ||
for (let i = 0; i < ROUNDS; i++) { | ||
await getRowsWithRelations(); | ||
} | ||
console.timeEnd(`drizzle:pool ${POOLSIZE}`) | ||
exit(0); | ||
} | ||
|
||
async function warmup() { | ||
//to initate possible lazy loaded pool | ||
const promises = []; | ||
for (let i = 0; i < ITERATIONS; i++) { | ||
promises.push(db.query.customers.findFirst()); | ||
} | ||
await Promise.all(promises); | ||
} | ||
|
||
async function getRowsWithRelations() { | ||
const promises = []; | ||
for (let i = 0; i < ITERATIONS; i++) { | ||
const p = db.query.orders.findMany({ | ||
with: { | ||
details: { | ||
with: { | ||
product: { | ||
with: { | ||
supplier: { | ||
|
||
} | ||
} | ||
} | ||
} | ||
}, | ||
customer: {}, | ||
employee: {}, | ||
} | ||
// }).then(x => console.dir(x, {depth: Infinity})); | ||
}).then(JSON.stringify); | ||
promises.push(p); | ||
} | ||
await Promise.all(promises); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { drizzle } from 'drizzle-orm/mysql2'; | ||
import mysql from 'mysql2/promise'; | ||
import * as schema from './schema-mysql'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
const POOLSIZE = Number.parseInt(process.env.POOLSIZE, 10); | ||
const LOG = process.env.LOG === 'true'; | ||
|
||
const pool = mysql.createPool({ | ||
uri: process.env.MYSQL_URL, | ||
connectionLimit: POOLSIZE, | ||
}); | ||
|
||
export const db = drizzle(pool, { | ||
schema, | ||
mode: 'default', | ||
logger: LOG, | ||
}); | ||
|
||
export type db = typeof db; | ||
|
||
export default db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.