-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
await using kysely = new Kysely()
support. (#1167)
- Loading branch information
1 parent
477f8c5
commit 66c0e57
Showing
3 changed files
with
75 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { | ||
CompiledQuery, | ||
DatabaseConnection, | ||
DummyDriver, | ||
Kysely, | ||
PostgresAdapter, | ||
PostgresIntrospector, | ||
PostgresQueryCompiler, | ||
QueryResult, | ||
RootOperationNode, | ||
sql, | ||
} from '../../..' | ||
import { expect } from './test-setup' | ||
|
||
describe('async dispose', function () { | ||
it('should call destroy ', async () => { | ||
const steps: string[] = [] | ||
|
||
{ | ||
await using db = new Kysely({ | ||
dialect: { | ||
createAdapter: () => new PostgresAdapter(), | ||
createDriver: () => | ||
new (class extends DummyDriver { | ||
async acquireConnection() { | ||
return new (class implements DatabaseConnection { | ||
async executeQuery<R>(): Promise<QueryResult<R>> { | ||
steps.push('executed') | ||
return { rows: [] } | ||
} | ||
streamQuery<R>(): AsyncIterableIterator<QueryResult<R>> { | ||
throw new Error('Method not implemented.') | ||
} | ||
})() | ||
} | ||
async destroy(): Promise<void> { | ||
steps.push('destroyed') | ||
} | ||
})(), | ||
createIntrospector: (db) => new PostgresIntrospector(db), | ||
createQueryCompiler: () => | ||
new (class extends PostgresQueryCompiler { | ||
compileQuery(node: RootOperationNode): CompiledQuery<unknown> { | ||
const compiled = super.compileQuery(node) | ||
steps.push('compiled') | ||
return compiled | ||
} | ||
})(), | ||
}, | ||
}) | ||
|
||
await sql`select 1`.execute(db) | ||
} | ||
|
||
steps.push('after runScope') | ||
|
||
expect(steps).to.length.to.be.greaterThan(1) | ||
expect(steps).to.deep.equal([ | ||
'compiled', | ||
'executed', | ||
'destroyed', | ||
'after runScope', | ||
]) | ||
}) | ||
}) |
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