-
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
ee04272
commit ae5cb1e
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({ | ||
Check failure on line 20 in test/node/src/async-dispose.test.ts GitHub Actions / Older TypeScript version (^4.7)
Check failure on line 20 in test/node/src/async-dispose.test.ts GitHub Actions / Older TypeScript version (^4.8)
|
||
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