@rip-lang/db 1.3.76 → 1.3.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db.rip +32 -3
- package/package.json +2 -2
package/db.rip
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import { get, post, read, start, use } from '@rip-lang/server'
|
|
23
23
|
import { cors } from '@rip-lang/server/middleware'
|
|
24
24
|
import { version as VERSION } from './package.json'
|
|
25
|
+
import { existsSync, unlinkSync } from 'fs'
|
|
25
26
|
|
|
26
27
|
# Database access via pure Bun FFI
|
|
27
28
|
duckdb = import!('./lib/duckdb.mjs')
|
|
@@ -102,13 +103,41 @@ portArg = do ->
|
|
|
102
103
|
null
|
|
103
104
|
port = parseInt(process.env.DB_PORT or portArg) or 4213
|
|
104
105
|
|
|
105
|
-
# Open database
|
|
106
|
-
|
|
106
|
+
# Open database (with WAL recovery on failure)
|
|
107
|
+
try
|
|
108
|
+
db = open path
|
|
109
|
+
catch e
|
|
110
|
+
walPath = "#{path}.wal"
|
|
111
|
+
if existsSync walPath
|
|
112
|
+
console.warn "[rip-db] WAL replay failed — deleting #{walPath} and retrying"
|
|
113
|
+
unlinkSync walPath
|
|
114
|
+
db = open path
|
|
115
|
+
else
|
|
116
|
+
throw e
|
|
117
|
+
|
|
107
118
|
conn = db.connect()
|
|
108
119
|
console.log "rip-db: DuckDB #{duckdbVersion()}"
|
|
109
120
|
console.log "rip-db: rip-db v#{VERSION}"
|
|
110
121
|
console.log "rip-db: source #{path}"
|
|
111
122
|
|
|
123
|
+
# Periodic checkpoint (flush WAL to main file every 5 minutes)
|
|
124
|
+
checkpoint = -> try conn.query 'CHECKPOINT'
|
|
125
|
+
checkpointTimer = setInterval checkpoint, 5 * 60 * 1000
|
|
126
|
+
|
|
127
|
+
# Graceful shutdown: checkpoint, disconnect, close
|
|
128
|
+
shuttingDown = false
|
|
129
|
+
shutdown = ->
|
|
130
|
+
return if shuttingDown
|
|
131
|
+
shuttingDown = true
|
|
132
|
+
clearInterval checkpointTimer if checkpointTimer
|
|
133
|
+
checkpoint()
|
|
134
|
+
try conn.close!
|
|
135
|
+
try db.close!
|
|
136
|
+
exit!
|
|
137
|
+
|
|
138
|
+
process.on 'SIGINT', shutdown
|
|
139
|
+
process.on 'SIGTERM', shutdown
|
|
140
|
+
|
|
112
141
|
# ==============================================================================
|
|
113
142
|
# Helpers
|
|
114
143
|
# ==============================================================================
|
|
@@ -294,7 +323,7 @@ post '/ddb/run' ->
|
|
|
294
323
|
|
|
295
324
|
# POST /shutdown — Gracefully close the database and exit
|
|
296
325
|
post '/shutdown' ->
|
|
297
|
-
setImmediate
|
|
326
|
+
setImmediate shutdown
|
|
298
327
|
{ ok: true }
|
|
299
328
|
|
|
300
329
|
# POST /ddb/interrupt — Cancel running query
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rip-lang/db",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.78",
|
|
4
4
|
"description": "DuckDB server with official DuckDB UI - pure Bun FFI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "db.rip",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"author": "Steve Shreeve <steve.shreeve@gmail.com>",
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"rip-lang": ">=3.13.
|
|
41
|
+
"rip-lang": ">=3.13.91",
|
|
42
42
|
"@rip-lang/server": ">=1.3.0"
|
|
43
43
|
},
|
|
44
44
|
"files": [
|