MCPcopy Create free account
hub / github.com/AlexErrant/Pentive / createDriver

Method createDriver

app/src/sqlite/dialect.ts:23–64  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21 }
22
23 createDriver() {
24 const load = this.database
25 const waiter = mutex()
26
27 let db: CRDatabase
28 let connection: DatabaseConnection
29
30 return {
31 async init() {
32 db = await load()
33 connection = {
34 async executeQuery<O>(query: CompiledQuery) {
35 return {
36 rows: (await db.execO(query.sql, query.parameters)) as O[],
37 }
38 },
39 async *streamQuery() {
40 throw new Error("Sqlite driver doesn't support streaming")
41 },
42 }
43 },
44 async acquireConnection() {
45 await waiter.lock()
46 return connection
47 },
48 async beginTransaction(connection: DatabaseConnection) {
49 await connection.executeQuery(CompiledQuery.raw('begin'))
50 },
51 async commitTransaction(connection: DatabaseConnection) {
52 await connection.executeQuery(CompiledQuery.raw('commit'))
53 },
54 async rollbackTransaction(connection: DatabaseConnection) {
55 await connection.executeQuery(CompiledQuery.raw('rollback'))
56 },
57 async releaseConnection() {
58 waiter.unlock()
59 },
60 async destroy() {
61 db.close()
62 },
63 }
64 }
65}
66
67function mutex() {

Callers

nothing calls this directly

Calls 1

mutexFunction · 0.85

Tested by

no test coverage detected