MCPcopy Create free account
hub / github.com/TanStack/db / clearLocalState

Function clearLocalState

examples/react-native/shopping-list/src/db/collections.ts:119–147  ·  view source on GitHub ↗
(
  offline: ReturnType<typeof createOfflineExecutor> | null,
)

Source from the content-addressed store, hash-verified

117}
118
119export async function clearLocalState(
120 offline: ReturnType<typeof createOfflineExecutor> | null,
121): Promise<void> {
122 if (offline) {
123 await offline.clearOutbox()
124 } else {
125 await offlineStorage.clear()
126 }
127
128 const rows = extractRows(
129 await executeSql(
130 `SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%'`,
131 ),
132 )
133
134 await executeSql(`PRAGMA foreign_keys = OFF`)
135 try {
136 for (const row of rows) {
137 const tableName = row.name
138 if (typeof tableName === `string`) {
139 await executeSql(
140 `DROP TABLE IF EXISTS "${tableName.replace(/"/g, `""`)}"`,
141 )
142 }
143 }
144 } finally {
145 await executeSql(`PRAGMA foreign_keys = ON`)
146 }
147}
148
149export const listsCollection = createCollection(
150 persistedCollectionOptions<

Callers 1

HeaderControlsFunction · 0.85

Calls 4

extractRowsFunction · 0.85
executeSqlFunction · 0.85
clearOutboxMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected