-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add test with 100.000 sqlite variables
- Loading branch information
1 parent
abf789f
commit 776ca1c
Showing
6 changed files
with
122 additions
and
0 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
1 change: 1 addition & 0 deletions
1
src/packages/client/src/__tests__/runtime-tests/sqlite-variable-limit/.gitignore
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 @@ | ||
# !dev.db |
Binary file added
BIN
+6.24 MB
src/packages/client/src/__tests__/runtime-tests/sqlite-variable-limit/dev.db.br
Binary file not shown.
87 changes: 87 additions & 0 deletions
87
src/packages/client/src/__tests__/runtime-tests/sqlite-variable-limit/index.js
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,87 @@ | ||
const { PrismaClient } = require('@prisma/client') | ||
const pMap = require('p-map') | ||
const zlib = require('zlib') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
module.exports = async () => { | ||
const prisma = new PrismaClient() | ||
const db = path.join(__dirname, 'dev.db') | ||
if (!fs.existsSync(db)) { | ||
await uncompressFile(db) | ||
} | ||
|
||
const result = await prisma.user.findMany({ | ||
include: { | ||
posts: true, | ||
}, | ||
}) | ||
|
||
prisma.disconnect() | ||
} | ||
|
||
if (require.main === module) { | ||
module.exports() | ||
// seed() | ||
// compress() | ||
} | ||
|
||
async function seed() { | ||
const prisma = new PrismaClient() | ||
const arr = new Array(100000).fill() | ||
await pMap( | ||
arr, | ||
async (_, i) => { | ||
await prisma.user.create({ | ||
data: { | ||
email: `a+${i}@hey.com`, | ||
name: `Bob`, | ||
posts: { | ||
create: new Array(1).fill(undefined).map((_, i) => ({ | ||
published: true, | ||
title: '', | ||
})), | ||
}, | ||
}, | ||
}) | ||
|
||
if (i % 1000 === 0) { | ||
console.log(`Done with ${i}`) | ||
} | ||
}, | ||
{ concurrency: 20 }, | ||
) | ||
prisma.disconnect() | ||
} | ||
|
||
async function compressFile(filename) { | ||
return new Promise((resolve, reject) => { | ||
const compress = zlib.createBrotliCompress() | ||
const input = fs.createReadStream(filename) | ||
const output = fs.createWriteStream(filename + '.br') | ||
|
||
input.pipe(compress).pipe(output) | ||
output.on('finish', () => { | ||
resolve() | ||
}) | ||
output.on('error', (ex) => { | ||
reject(ex) | ||
}) | ||
}) | ||
} | ||
|
||
async function uncompressFile(filename) { | ||
return new Promise((resolve, reject) => { | ||
const decompress = zlib.createBrotliDecompress() | ||
const input = fs.createReadStream(filename + '.br') | ||
const output = fs.createWriteStream(filename) | ||
|
||
input.pipe(decompress).pipe(output) | ||
output.on('finish', () => { | ||
resolve() | ||
}) | ||
output.on('error', (ex) => { | ||
reject(ex) | ||
}) | ||
}) | ||
} |
3 changes: 3 additions & 0 deletions
3
src/packages/client/src/__tests__/runtime-tests/sqlite-variable-limit/manifest.json
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,3 @@ | ||
{ | ||
"shouldSucceed": true | ||
} |
29 changes: 29 additions & 0 deletions
29
src/packages/client/src/__tests__/runtime-tests/sqlite-variable-limit/schema.prisma
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,29 @@ | ||
datasource db { | ||
provider = "sqlite" | ||
url = "file:dev.db" | ||
default = true | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
// / User model comment | ||
model User { | ||
id String @default(uuid()) @id | ||
email String @unique | ||
// / name comment | ||
name String? | ||
posts Post[] | ||
} | ||
|
||
model Post { | ||
id String @default(cuid()) @id | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
published Boolean | ||
title String | ||
content String? | ||
authorId String? | ||
author User? @relation(fields: [authorId], references: [id]) | ||
} |