Skip to content

Commit

Permalink
chore: prefix dollar
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Aug 3, 2020
1 parent c45e790 commit 5f1c7df
Show file tree
Hide file tree
Showing 30 changed files with 245 additions and 167 deletions.
4 changes: 2 additions & 2 deletions src/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"prisma2": "build/index.js"
},
"prisma": {
"version": "8337329d29aec488119918879493ab6fd38c880e",
"version": "4c91943360cd3d09eb0a9d55286c2670ed9e5e88",
"prismaCommit": "ea9742f3efa0953531e4205edeb1460184231154"
},
"devDependencies": {
Expand Down Expand Up @@ -161,4 +161,4 @@
"eslint"
]
}
}
}
10 changes: 2 additions & 8 deletions src/packages/client/fixtures/blog/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ import { PrismaClient } from './@prisma/client'

const prisma = new PrismaClient({
errorFormat: 'pretty',
__internal: {
engine: {
enableEngineDebugMode: true,
},
},
} as any)

async function main() {
await prisma.connect()
const result = await (prisma as any).__internal_triggerPanic(true)
// const result = await prisma.queryRaw(`SELECT 1`)
// const result = await (prisma as any).__internal_triggerPanic(true)
const result = await prisma.$queryRaw(`SELECT 1`)
console.log(result)
}

Expand Down
12 changes: 6 additions & 6 deletions src/packages/client/src/__tests__/batching.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('batching', () => {
const requests: any[] = []

const fetcher = new PrismaClientFetcher({
connect: () => Promise.resolve(),
engine: {
$connect: () => Promise.resolve(),
_engine: {
requestBatch: (batch) => {
batches.push(batch)
return batch.map(() => ({ data: { data: null }, elapsed: 0.2 }))
Expand Down Expand Up @@ -105,8 +105,8 @@ describe('batching', () => {
const requests: any[] = []

const fetcher = new PrismaClientFetcher({
connect: () => Promise.resolve(),
engine: {
$connect: () => Promise.resolve(),
_engine: {
requestBatch: (batch) => {
batches.push(batch)
return batch.map(() => ({ data: { data: null }, elapsed: 0.2 }))
Expand Down Expand Up @@ -197,8 +197,8 @@ describe('batching', () => {
const requests: any[] = []

const fetcher = new PrismaClientFetcher({
connect: () => Promise.resolve(),
engine: {
$connect: () => Promise.resolve(),
_engine: {
requestBatch: (batch) => {
batches.push(batch)
return batch.map(() => ({ data: { data: null }, elapsed: 0.2 }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = async () => {
sum: { age: 800 },
})

prisma.disconnect()
prisma.$disconnect()
}

if (require.main === module) {
Expand All @@ -54,5 +54,5 @@ async function seed() {
},
})
}
prisma.disconnect()
prisma.$disconnect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ module.exports = async () => {
const prisma = new PrismaClient()

let asyncId
prisma.use(async (params, fetch) => {
prisma.$use(async (params, fetch) => {
asyncId = executionAsyncId()
return fetch(params)
})

await prisma.user.findMany()
assert(asyncId > 0)

prisma.disconnect()
prisma.$disconnect()
}

if (require.main === module) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = async () => {
errorFormat: 'colorless',
})
try {
await prisma.connect()
await prisma.$connect()
} catch (e) {
throw e
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ module.exports = async () => {

// Test connecting and disconnecting all the time
await prisma.user.findMany()
prisma.disconnect()
prisma.$disconnect()
assert(requests.length === 1)

await prisma.user.findMany()
prisma.disconnect()
prisma.$disconnect()

// flakyness :shrug:
await new Promise((r) => setTimeout(r, 200))
Expand All @@ -112,54 +112,54 @@ module.exports = async () => {
const count = await prisma.user.count()
assert(typeof count === 'number')

prisma.connect()
await prisma.disconnect()
prisma.$connect()
await prisma.$disconnect()

await new Promise((r) => setTimeout(r, 200))
prisma.connect()
prisma.$connect()

const userPromise = prisma.user.findMany()
await userPromise
// @ts-ignore

await prisma.disconnect()
await prisma.$disconnect()

await prisma.connect()
await prisma.$connect()

// Test queryRaw(string)
const rawQuery = await prisma.queryRaw('SELECT 1')
const rawQuery = await prisma.$queryRaw('SELECT 1')
assert.equal(
rawQuery[0]['?column?'],
1,
"prisma.queryRaw('SELECT 1') result should be [ { '?column?': 1 } ]",
"prisma.$queryRaw('SELECT 1') result should be [ { '?column?': 1 } ]",
)

// Test queryRaw``
const rawQueryTemplate = await prisma.queryRaw`SELECT 1`
const rawQueryTemplate = await prisma.$queryRaw`SELECT 1`
assert.equal(
rawQueryTemplate[0]['?column?'],
1,
"prisma.queryRaw`SELECT 1` result should be [ { '?column?': 1 } ]",
)

// Test queryRaw`` with ${param}
const rawQueryTemplateWithParams = await prisma.queryRaw`SELECT * FROM "public"."User" WHERE name = ${'Alice'}`
const rawQueryTemplateWithParams = await prisma.$queryRaw`SELECT * FROM "public"."User" WHERE name = ${'Alice'}`
assert.equal(
rawQueryTemplateWithParams[0].name,
'Alice',
"prisma.queryRaw`SELECT * FROM User WHERE name = ${'Alice'}` result should be [{ email: 'a@a.de', id: 11233, name: 'Alice' }]",
)

// Test executeRaw(string)
const rawexecute = await prisma.executeRaw('SELECT 1')
const rawexecute = await prisma.$executeRaw('SELECT 1')
assert.equal(rawexecute, 1, 'executeRaw SELECT 1 must return 0')

// Test executeRaw``
const rawexecuteTemplate = await prisma.executeRaw`SELECT 1`
const rawexecuteTemplate = await prisma.$executeRaw`SELECT 1`
assert.equal(rawexecuteTemplate, 1, 'executeRaw SELECT 1 must return 0')

// Test executeRaw`` with ${param}
const rawexecuteTemplateWithParams = await prisma.executeRaw`SELECT * FROM "public"."User" WHERE name = ${'Alice'}`
const rawexecuteTemplateWithParams = await prisma.$executeRaw`SELECT * FROM "public"."User" WHERE name = ${'Alice'}`
assert.equal(
rawexecuteTemplateWithParams,
1,
Expand All @@ -183,7 +183,7 @@ module.exports = async () => {
}
}

prisma.on('error', (e) => {
prisma.$on('error', (e) => {
errorLogs.push(e)
})

Expand Down Expand Up @@ -239,7 +239,7 @@ module.exports = async () => {
where: { id: resultJsonArray.id },
})

prisma.disconnect()
prisma.$disconnect()
await db.query(`
DROP TABLE IF EXISTS "public"."Post" CASCADE;
DROP TABLE IF EXISTS "public"."User" CASCADE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = async () => {
errorFormat: 'colorless',
})
try {
await prisma.connect()
await prisma.$connect()
} catch (e) {
// make sure, that it's a PrismaClientInitializationError
if (e instanceof PrismaClientInitializationError) {
Expand Down
52 changes: 26 additions & 26 deletions src/packages/client/src/__tests__/runtime-tests/blog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ module.exports = async () => {
.posts()

assert.equal(posts.length, 0)
db.disconnect()
db.$disconnect()
assert.equal(requests.length, 2)

await db.user.findMany()
db.disconnect()
db.$disconnect()
assert.equal(requests.length, 3)

const count = await db.user.count()
Expand All @@ -52,58 +52,58 @@ module.exports = async () => {

assert(typeof paramCount === 'number')

db.connect()
await db.disconnect()
db.$connect()
await db.$disconnect()

await new Promise((r) => setTimeout(r, 200))
db.connect()
db.$connect()

const userPromise = db.user.findMany()
await userPromise
// @ts-ignore

await db.disconnect()
await db.$disconnect()

await db.connect()
await db.$connect()

/**
* queryRaw
*/

// Test queryRaw(string)
const rawQuery = await db.queryRaw('SELECT 1')
const rawQuery = await db.$queryRaw('SELECT 1')
assert(
rawQuery[0]['1'] === 1,
"prisma.queryRaw('SELECT 1') result should be [ { '1': 1 } ]",
"prisma.$queryRaw('SELECT 1') result should be [ { '1': 1 } ]",
)

// Test queryRaw(string, values)
const rawQueryWithValues = await db.queryRaw(
const rawQueryWithValues = await db.$queryRaw(
'SELECT $1 AS name, $2 AS id',
'Alice',
42,
)
assert(
rawQueryWithValues[0].name === 'Alice' && rawQueryWithValues[0].id === 42,
"prisma.queryRaw('SELECT $1 AS name, $2 AS id', 'Alice', 42) result should be [ { name: 'Alice', id: 42 } ]",
"prisma.$queryRaw('SELECT $1 AS name, $2 AS id', 'Alice', 42) result should be [ { name: 'Alice', id: 42 } ]",
)

// Test queryRaw``
const rawQueryTemplate = await db.queryRaw`SELECT 1`
const rawQueryTemplate = await db.$queryRaw`SELECT 1`
assert(
rawQueryTemplate[0]['1'] === 1,
"prisma.queryRaw`SELECT 1` result should be [ { '1': 1 } ]",
)

// Test queryRaw`` with ${param}
const rawQueryTemplateWithParams = await db.queryRaw`SELECT * FROM User WHERE name = ${'Alice'}`
const rawQueryTemplateWithParams = await db.$queryRaw`SELECT * FROM User WHERE name = ${'Alice'}`
assert(
rawQueryTemplateWithParams[0].name === 'Alice',
"prisma.queryRaw`SELECT * FROM User WHERE name = ${'Alice'}` result should be [{ email: 'a@a.de', id: '576eddf9-2434-421f-9a86-58bede16fd95', name: 'Alice' }]",
)

// Test queryRaw`` with prisma.sql``
const rawQueryTemplateFromSqlTemplate = await db.queryRaw(
const rawQueryTemplateFromSqlTemplate = await db.$queryRaw(
sql`
SELECT ${join([raw('email'), raw('id'), raw('name')])}
FROM ${raw('User')}
Expand All @@ -113,38 +113,38 @@ module.exports = async () => {
)
assert(
rawQueryTemplateFromSqlTemplate[0].name === 'Alice',
"prisma.queryRaw(prisma.sql`SELECT * FROM ${join([raw('email'),raw('id'),raw('name')])} ${sql`WHERE name = ${'Alice'}`} ${empty}` result should be [{ email: 'a@a.de', id: '576eddf9-2434-421f-9a86-58bede16fd95', name: 'Alice' }]",
"prisma.$queryRaw(prisma.sql`SELECT * FROM ${join([raw('email'),raw('id'),raw('name')])} ${sql`WHERE name = ${'Alice'}`} ${empty}` result should be [{ email: 'a@a.de', id: '576eddf9-2434-421f-9a86-58bede16fd95', name: 'Alice' }]",
)

/**
* executeRaw
* .$executeRaw(
*/

// Test executeRaw(string)
const executeRaw = await db.executeRaw(
// Test .$executeRaw((string)
const executeRaw = await db.$executeRaw(
'UPDATE User SET name = $1 WHERE id = $2',
'name',
'id',
)
assert(
executeRaw === 0,
"prisma.executeRaw('UPDATE User SET name = $1 WHERE id = $2') result should be 0",
"prisma.$executeRaw(('UPDATE User SET name = $1 WHERE id = $2') result should be 0",
)

// Test executeRaw(string, values)
const executeRawWithValues = await db.executeRaw(
// Test .$executeRaw((string, values)
const executeRawWithValues = await db.$executeRaw(
'UPDATE User SET name = $1 WHERE id = $2',
'Alice',
'id',
)
assert(
executeRawWithValues === 0,
"prisma.executeRaw('UPDATE User SET name = $1 WHERE id = $2', 'Alice', 42) result should be 0",
"prisma.$.$executeRaw(('UPDATE User SET name = $1 WHERE id = $2', 'Alice', 42) result should be 0",
)

// Test executeRaw``
const executeRawTemplate = await db.executeRaw`UPDATE User SET name = ${'name'} WHERE id = ${'id'}`
assert.equal(executeRawTemplate, 0)
// Test .$executeRaw(``
const $executeRawTemplate = await db.$executeRaw`UPDATE User SET name = ${'name'} WHERE id = ${'id'}`
assert.equal($executeRawTemplate, 0)

// Test validation errors
let validationError
Expand Down Expand Up @@ -187,7 +187,7 @@ module.exports = async () => {
}
}

db.disconnect()
db.$disconnect()
}

if (require.main === module) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = async () => {

await prisma.user.findMany()

prisma.disconnect()
prisma.$disconnect()
}

if (require.main === module) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = async () => {

const data = await prisma.user.findMany()

prisma.disconnect()
prisma.$disconnect()
} catch (e) {
if (!e.message.includes('not found')) {
throw new Error(`Invalid error message for binary corruption: ${e}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = async () => {

assert.equal(result.length, 1)

prisma.disconnect()
prisma.$disconnect()
}

if (require.main === module) {
Expand Down

0 comments on commit 5f1c7df

Please sign in to comment.