plan to switch to better-sqlite3, drop node-sqlite3
This commit is contained in:
		
							parent
							
								
									a02edf1b4f
								
							
						
					
					
						commit
						2f50fc4c00
					
				
					 4 changed files with 351 additions and 10437 deletions
				
			
		|  | @ -2,10 +2,10 @@ | ||||||
| FROM node:14-alpine3.12 AS release | FROM node:14-alpine3.12 AS release | ||||||
| WORKDIR /app | WORKDIR /app | ||||||
| 
 | 
 | ||||||
| # split the sqlite install here, so that it can caches the arm prebuilt | # split the sqlite install here, so that it can caches the prebuilt | ||||||
| RUN apk add --no-cache --virtual .build-deps make g++ python3 python3-dev && \ | RUN apk add --no-cache --virtual .build-deps make g++ python3 python3-dev && \ | ||||||
|             ln -s /usr/bin/python3 /usr/bin/python && \ |             ln -s /usr/bin/python3 /usr/bin/python && \ | ||||||
|             npm install @louislam/sqlite3@5.0.3 bcrypt@5.0.1 && \ |             npm install better-sqlite3@7.4.3 bcrypt@5.0.1 && \ | ||||||
|             apk del .build-deps && \ |             apk del .build-deps && \ | ||||||
|             rm -f /usr/bin/python |             rm -f /usr/bin/python | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										10724
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										10724
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -19,7 +19,7 @@ | ||||||
|         "vite-preview-dist": "vite preview --host", |         "vite-preview-dist": "vite preview --host", | ||||||
|         "build-docker": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma -t louislam/uptime-kuma:1 -t louislam/uptime-kuma:1.3.2 --target release . --push", |         "build-docker": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma -t louislam/uptime-kuma:1 -t louislam/uptime-kuma:1.3.2 --target release . --push", | ||||||
|         "build-docker-nightly": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly --target nightly . --push", |         "build-docker-nightly": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly --target nightly . --push", | ||||||
|         "build-docker-nightly-amd64": "docker buildx build --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push", |         "build-docker-nightly-amd64": "docker buildx build --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain", | ||||||
|         "setup": "git checkout 1.3.2 && npm install && npm run build", |         "setup": "git checkout 1.3.2 && npm install && npm run build", | ||||||
|         "update-version": "node extra/update-version.js", |         "update-version": "node extra/update-version.js", | ||||||
|         "mark-as-nightly": "node extra/mark-as-nightly.js", |         "mark-as-nightly": "node extra/mark-as-nightly.js", | ||||||
|  | @ -36,11 +36,11 @@ | ||||||
|         "@fortawesome/free-regular-svg-icons": "^5.15.4", |         "@fortawesome/free-regular-svg-icons": "^5.15.4", | ||||||
|         "@fortawesome/free-solid-svg-icons": "^5.15.4", |         "@fortawesome/free-solid-svg-icons": "^5.15.4", | ||||||
|         "@fortawesome/vue-fontawesome": "^3.0.0-4", |         "@fortawesome/vue-fontawesome": "^3.0.0-4", | ||||||
|         "@louislam/sqlite3": "^5.0.3", |  | ||||||
|         "@popperjs/core": "^2.9.3", |         "@popperjs/core": "^2.9.3", | ||||||
|         "args-parser": "^1.3.0", |         "args-parser": "^1.3.0", | ||||||
|         "axios": "^0.21.1", |         "axios": "^0.21.1", | ||||||
|         "bcrypt": "^5.0.1", |         "bcrypt": "^5.0.1", | ||||||
|  |         "better-sqlite3": "^7.4.3", | ||||||
|         "bootstrap": "^5.1.0", |         "bootstrap": "^5.1.0", | ||||||
|         "chart.js": "^3.5.0", |         "chart.js": "^3.5.0", | ||||||
|         "chartjs-adapter-dayjs": "^1.0.0", |         "chartjs-adapter-dayjs": "^1.0.0", | ||||||
|  | @ -56,7 +56,7 @@ | ||||||
|         "password-hash": "^1.2.2", |         "password-hash": "^1.2.2", | ||||||
|         "prom-client": "^13.2.0", |         "prom-client": "^13.2.0", | ||||||
|         "prometheus-api-metrics": "^3.2.0", |         "prometheus-api-metrics": "^3.2.0", | ||||||
|         "redbean-node": "0.0.21", |         "redbean-node": "0.1.1", | ||||||
|         "socket.io": "^4.1.3", |         "socket.io": "^4.1.3", | ||||||
|         "socket.io-client": "^4.1.3", |         "socket.io-client": "^4.1.3", | ||||||
|         "tcp-ping": "^0.1.1", |         "tcp-ping": "^0.1.1", | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ const { sleep, debug, isDev } = require("../src/util"); | ||||||
| const { R } = require("redbean-node"); | const { R } = require("redbean-node"); | ||||||
| const { setSetting, setting } = require("./util-server"); | const { setSetting, setting } = require("./util-server"); | ||||||
| const knex = require("knex"); | const knex = require("knex"); | ||||||
| const sqlite3 = require("@louislam/sqlite3"); |  | ||||||
| 
 | 
 | ||||||
| class Database { | class Database { | ||||||
| 
 | 
 | ||||||
|  | @ -14,50 +13,23 @@ class Database { | ||||||
|     static sqliteInstance = null; |     static sqliteInstance = null; | ||||||
| 
 | 
 | ||||||
|     static async connect() { |     static async connect() { | ||||||
| 
 |  | ||||||
|         if (! this.sqliteInstance) { |  | ||||||
|             this.sqliteInstance = new sqlite3.Database(Database.path); |  | ||||||
|             this.sqliteInstance.run("PRAGMA journal_mode = WAL"); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         const Dialect = require("knex/lib/dialects/sqlite3/index.js"); |  | ||||||
|         Dialect.prototype._driver = () => sqlite3; |  | ||||||
| 
 |  | ||||||
|         if (isDev) { |  | ||||||
|             Dialect.prototype.acquireConnectionOrg = Dialect.prototype.acquireConnection; |  | ||||||
| 
 |  | ||||||
|             Dialect.prototype.acquireConnection = async function () { |  | ||||||
|                 let a = await this.acquireConnectionOrg(); |  | ||||||
|                 debug("acquired Connection"); |  | ||||||
|                 return a; |  | ||||||
|             }; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         // Always return same connection.
 |  | ||||||
|         Dialect.prototype.acquireRawConnection = async function () { |  | ||||||
|             return Database.sqliteInstance; |  | ||||||
|         }; |  | ||||||
| 
 |  | ||||||
|         Dialect.prototype.destroyRawConnection = async () => { } |  | ||||||
| 
 |  | ||||||
|         const acquireConnectionTimeout = 120 * 1000; |         const acquireConnectionTimeout = 120 * 1000; | ||||||
| 
 | 
 | ||||||
|         const knexInstance = knex({ |         R.useBetterSQLite3 = true; | ||||||
|             client: Dialect, |         R.betterSQLite3Options.timeout = acquireConnectionTimeout; | ||||||
|             connection: { },        // Do not remove, Leave it empty is ok
 | 
 | ||||||
|  |         R.setup("sqlite", { | ||||||
|  |             filename: Database.path, | ||||||
|             useNullAsDefault: true, |             useNullAsDefault: true, | ||||||
|             acquireConnectionTimeout: acquireConnectionTimeout, |             acquireConnectionTimeout: acquireConnectionTimeout, | ||||||
|             pool: { |         }, { | ||||||
|                 min: 1, |             min: 1, | ||||||
|                 max: 1, |             max: 1, | ||||||
|                 idleTimeoutMillis: 120 * 1000, |             idleTimeoutMillis: 120 * 1000, | ||||||
|                 propagateCreateError: false, |             propagateCreateError: false, | ||||||
|                 acquireTimeoutMillis: acquireConnectionTimeout, |             acquireTimeoutMillis: acquireConnectionTimeout, | ||||||
|             } |  | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         R.setup(knexInstance); |  | ||||||
| 
 |  | ||||||
|         if (process.env.SQL_LOG === "1") { |         if (process.env.SQL_LOG === "1") { | ||||||
|             R.debug(true); |             R.debug(true); | ||||||
|         } |         } | ||||||
|  | @ -65,6 +37,10 @@ class Database { | ||||||
|         // Auto map the model to a bean object
 |         // Auto map the model to a bean object
 | ||||||
|         R.freeze(true) |         R.freeze(true) | ||||||
|         await R.autoloadModels("./server/model"); |         await R.autoloadModels("./server/model"); | ||||||
|  | 
 | ||||||
|  |         // Change to WAL
 | ||||||
|  |         await R.exec("PRAGMA journal_mode = WAL"); | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     static async patch() { |     static async patch() { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue