MCPcopy Index your code
hub / github.com/TanStack/db / ExpoSQLiteDriver

Class ExpoSQLiteDriver

packages/expo-db-sqlite-persistence/src/expo-sqlite-driver.ts:78–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78export class ExpoSQLiteDriver implements SQLiteDriver {
79 private readonly databasePromise: Promise<ExpoSQLiteDatabaseLike>
80 private readonly ownsDatabase: boolean
81 private queue: Promise<void> = Promise.resolve()
82 private nextSavepointId = 1
83
84 constructor(options: ExpoSQLiteDriverOptions) {
85 if (hasExistingDatabase(options)) {
86 if (!isExpoSQLiteDatabaseLike(options.database)) {
87 throw new InvalidPersistedCollectionConfigError(
88 `Expo SQLite database must provide execAsync/getAllAsync/runAsync/withExclusiveTransactionAsync`,
89 )
90 }
91
92 this.databasePromise = Promise.resolve(options.database)
93 this.ownsDatabase = false
94 return
95 }
96
97 this.databasePromise = Promise.resolve(options.openDatabase()).then(
98 (database) => {
99 if (!isExpoSQLiteDatabaseLike(database)) {
100 throw new InvalidPersistedCollectionConfigError(
101 `Expo SQLite openDatabase() must resolve a database with execAsync/getAllAsync/runAsync/withExclusiveTransactionAsync`,
102 )
103 }
104
105 return database
106 },
107 )
108 this.ownsDatabase = true
109 }
110
111 async exec(sql: string): Promise<void> {
112 await this.enqueue(async () => {
113 const database = await this.getDatabase()
114 await database.execAsync(sql)
115 })
116 }
117
118 async query<T>(
119 sql: string,
120 params: ReadonlyArray<unknown> = [],
121 ): Promise<ReadonlyArray<T>> {
122 return this.enqueue(async () => {
123 const database = await this.getDatabase()
124 return database.getAllAsync<T>(sql, normalizeParams(params))
125 })
126 }
127
128 async run(sql: string, params: ReadonlyArray<unknown> = []): Promise<void> {
129 await this.enqueue(async () => {
130 const database = await this.getDatabase()
131 await database.runAsync(sql, normalizeParams(params))
132 })
133 }
134
135 async transaction<T>(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…