Skip to content

Commit 3a70b2e

Browse files
committed
chore: move back to d1 and remove console.log
1 parent cef504e commit 3a70b2e

File tree

4 files changed

+9
-17
lines changed

4 files changed

+9
-17
lines changed

docs/nuxt.config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ export default defineNuxtConfig({
2828

2929
content: {
3030
database: {
31-
// type: 'd1',
32-
// binding: 'DB',
33-
type: 'libsql',
34-
url: process.env.TURSO_DATABASE_URL!,
35-
authToken: process.env.TURSO_AUTH_TOKEN!,
31+
type: 'd1',
32+
binding: 'DB',
33+
// type: 'libsql',
34+
// url: process.env.TURSO_DATABASE_URL!,
35+
// authToken: process.env.TURSO_AUTH_TOKEN!,
3636
},
3737
},
3838

src/runtime/adapters/libsql.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ export default createDatabaseAdapter<{ url: string, authToken: string }>((opts)
1212

1313
return {
1414
async all<T>(sql: string, params?: Array<number | string | boolean>): Promise<T[]> {
15-
const now = Date.now()
1615
const res = await client.execute({ sql, args: params || [] })
17-
console.log(`[all] ${res.rows.length} rows in ${Date.now() - now}ms`)
1816
return res.rows as T[]
1917
},
2018
async first<T>(sql: string, params?: Array<number | string | boolean>) {
21-
const now = Date.now()
2219
const res = await client.execute({ sql, args: params || [] })
23-
console.log(`[first] ${JSON.stringify(res.rows[0])} in ${Date.now() - now}ms`)
2420
return res.rows[0] as T
2521
},
2622
async exec(sql: string): Promise<void> {

src/runtime/internal/database.client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async function loadAdapter<T>(collection: T) {
7979
window.localStorage.setItem(`content_${dumpId}`, compressedDump!)
8080
}
8181
catch (error) {
82-
console.log('Database integrity check failed, rebuilding database', error)
82+
console.error('Database integrity check failed, rebuilding database', error)
8383
}
8484
perf.tick('Store Database')
8585
}
@@ -98,7 +98,7 @@ async function loadAdapter<T>(collection: T) {
9898
await db.exec(command)
9999
}
100100
catch (error) {
101-
console.log('Error executing command', error)
101+
console.error('Error executing command', error)
102102
}
103103
}
104104
perf.tick('Restore Dump')

src/runtime/internal/database.server.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function checkAndImportDatabaseIntegrity(event: H3Event, collection
4646
integrityCheckPromise[String(collection)] = integrityCheckPromise[String(collection)] || _checkAndImportDatabaseIntegrity(event, collection, checksums[String(collection)], config)
4747
.then((isValid) => { checkDatabaseIntegrity[String(collection)] = !isValid })
4848
.catch((error) => {
49-
console.log('Database integrity check failed', error)
49+
console.error('Database integrity check failed', error)
5050
checkDatabaseIntegrity[String(collection)] = true
5151
integrityCheckPromise[String(collection)] = null
5252
})
@@ -61,7 +61,6 @@ async function _checkAndImportDatabaseIntegrity(event: H3Event, collection: stri
6161
const db = await loadDatabaseAdapter(config)
6262

6363
const before = await db.first<{ version: string }>(`select * from ${tables.info} where id = 'checksum_${collection}'`).catch(() => ({ version: '' }))
64-
console.log(`checkAndImportDatabaseIntegrity: ${collection}, before: ${before?.version}, now: ${integrityVersion}`)
6564

6665
if (before?.version) {
6766
if (before?.version === integrityVersion) {
@@ -71,16 +70,13 @@ async function _checkAndImportDatabaseIntegrity(event: H3Event, collection: stri
7170
await db.exec(`DELETE FROM ${tables.info} WHERE id = 'checksum_${collection}'`)
7271
}
7372

74-
const now = Date.now()
7573
const dump = await loadDatabaseDump(event, collection).then(decompressSQLDump)
76-
console.log(`loadDatabaseDump: ${Date.now() - now}ms`)
7774

7875
await dump.reduce(async (prev: Promise<void>, sql: string) => {
7976
await prev
8077
await db.exec(sql).catch((err: Error) => {
8178
const message = err.message || 'Unknown error'
82-
// console.log('Failed to execute SQL', message.split(':').pop()?.trim())
83-
console.log(`Failed to execute SQL ${sql}: ${message}`)
79+
console.error(`Failed to execute SQL ${sql}: ${message}`)
8480
// throw error
8581
})
8682
}, Promise.resolve())

0 commit comments

Comments
 (0)