mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-11 19:17:09 +03:00
Replaced Sqlite3 with better-sqlite3
This commit is contained in:
parent
8a1ca117ff
commit
ff14af4c00
@ -53,6 +53,7 @@
|
||||
"background-tips": "file:packages/background-tips",
|
||||
"base16-tomorrow-dark-theme": "file:packages/base16-tomorrow-dark-theme",
|
||||
"base16-tomorrow-light-theme": "file:packages/base16-tomorrow-light-theme",
|
||||
"better-sqlite3": "^11.1.2",
|
||||
"bookmarks": "file:packages/bookmarks",
|
||||
"bracket-matcher": "file:packages/bracket-matcher",
|
||||
"chai": "4.3.4",
|
||||
@ -165,7 +166,6 @@
|
||||
"solarized-dark-syntax": "file:packages/solarized-dark-syntax",
|
||||
"solarized-light-syntax": "file:packages/solarized-light-syntax",
|
||||
"spell-check": "file:packages/spell-check",
|
||||
"sqlite3": "^5.1.7",
|
||||
"status-bar": "file:packages/status-bar",
|
||||
"styleguide": "file:./packages/styleguide",
|
||||
"superstring": "github:pulsar-edit/superstring#de97b496663fce40050bf2d66e1466ccfbd00943",
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const sqlite3 = require('better-sqlite3');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = class SQLStateStore {
|
||||
@ -12,7 +12,7 @@ module.exports = class SQLStateStore {
|
||||
const dbPath = path.join(atom.getConfigDirPath(), 'session-store.db');
|
||||
let db;
|
||||
try {
|
||||
db = new sqlite3.Database(dbPath);
|
||||
db = sqlite3(dbPath);
|
||||
} catch(error) {
|
||||
atom.notifications.addFatalError('Error loading database', {
|
||||
stack: new Error('Error loading SQLite database for state storage').stack,
|
||||
@ -21,10 +21,11 @@ module.exports = class SQLStateStore {
|
||||
console.error('Error loading SQLite database', error);
|
||||
return null
|
||||
}
|
||||
await getOne(db,
|
||||
db.pragma('journal_mode = WAL');
|
||||
db.exec(
|
||||
`CREATE TABLE IF NOT EXISTS ${this.tableName} (key VARCHAR, value JSON)`
|
||||
);
|
||||
await getOne(db,
|
||||
db.exec(
|
||||
`CREATE UNIQUE INDEX IF NOT EXISTS "${table}_index" ON ${this.tableName}(key)`
|
||||
);
|
||||
return db;
|
||||
@ -44,7 +45,7 @@ module.exports = class SQLStateStore {
|
||||
save(key, value) {
|
||||
return this.dbPromise.then(db => {
|
||||
if(!db) return null;
|
||||
return getOne(db,
|
||||
return exec(db,
|
||||
`REPLACE INTO ${this.tableName} VALUES (?, ?)`,
|
||||
key,
|
||||
JSON.stringify({ value: value, storedAt: new Date().toString() })
|
||||
@ -67,13 +68,13 @@ module.exports = class SQLStateStore {
|
||||
|
||||
delete(key) {
|
||||
return this.dbPromise.then(db =>
|
||||
getOne(db, `DELETE FROM ${this.tableName} WHERE key = ?`, key )
|
||||
exec(db, `DELETE FROM ${this.tableName} WHERE key = ?`, key )
|
||||
);
|
||||
}
|
||||
|
||||
clear() {
|
||||
return this.dbPromise.then(db =>
|
||||
getOne(db, `DELETE FROM ${this.tableName}`)
|
||||
exec(db, `DELETE FROM ${this.tableName}`)
|
||||
);
|
||||
}
|
||||
|
||||
@ -86,15 +87,13 @@ module.exports = class SQLStateStore {
|
||||
};
|
||||
|
||||
function getOne(db, sql, ...params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.get(sql, ...params, (error, result) => {
|
||||
if(error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
const stmt = db.prepare(sql);
|
||||
return stmt.get(params)
|
||||
}
|
||||
|
||||
function exec(db, sql, ...params) {
|
||||
const stmt = db.prepare(sql);
|
||||
stmt.run(params)
|
||||
}
|
||||
|
||||
function awaitForAtomGlobal() {
|
||||
|
43
yarn.lock
43
yarn.lock
@ -2517,6 +2517,14 @@ bcrypt-pbkdf@^1.0.0:
|
||||
dependencies:
|
||||
tweetnacl "^0.14.3"
|
||||
|
||||
better-sqlite3@^11.1.2:
|
||||
version "11.1.2"
|
||||
resolved "https://registry.yarnpkg.com/better-sqlite3/-/better-sqlite3-11.1.2.tgz#6c9d064c9f1ff2a7f507477648ca0ba67bf564a3"
|
||||
integrity sha512-gujtFwavWU4MSPT+h9B+4pkvZdyOUkH54zgLdIrMmmmd4ZqiBIrRNBzNzYVFO417xo882uP5HBu4GjOfaSrIQw==
|
||||
dependencies:
|
||||
bindings "^1.5.0"
|
||||
prebuild-install "^7.1.1"
|
||||
|
||||
binary-extensions@^2.0.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
|
||||
@ -6524,11 +6532,6 @@ loglevel@^1.6.0:
|
||||
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.8.1.tgz#5c621f83d5b48c54ae93b6156353f555963377b4"
|
||||
integrity sha512-tCRIJM51SHjAayKwC+QAg8hT8vg6z7GSgLJKGvzuPb1Wc+hLzqtuVLxp6/HzSPOozuK+8ErAhy7U/sVzw8Dgfg==
|
||||
|
||||
loophole@^1:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/loophole/-/loophole-1.1.0.tgz#37949fea453b6256acc725c320ce0c5a7f70a2bd"
|
||||
integrity sha512-zgLykD4MuL9HJRsoeKuGRXz4L9t1C0oDZPjFeUg5MLQyZjxWdxIbPHgRijVGN98DieVWJuo2fi9nEUDcdDbEiQ==
|
||||
|
||||
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
|
||||
@ -7147,11 +7150,6 @@ node-addon-api@^3.1.0:
|
||||
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161"
|
||||
integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==
|
||||
|
||||
node-addon-api@^7.0.0:
|
||||
version "7.1.0"
|
||||
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-7.1.0.tgz#71f609369379c08e251c558527a107107b5e0fdb"
|
||||
integrity sha512-mNcltoe1R8o7STTegSOHdnJNN7s5EUvhoS7ShnTHDyOSd+8H+UdWODq6qSv67PjC8Zc5JRT8+oLAMCr0SIXw7g==
|
||||
|
||||
node-api-version@^0.1.4:
|
||||
version "0.1.4"
|
||||
resolved "https://registry.yarnpkg.com/node-api-version/-/node-api-version-0.1.4.tgz#1ed46a485e462d55d66b5aa1fe2821720dedf080"
|
||||
@ -7194,7 +7192,7 @@ node-gyp-build@^4.2.1:
|
||||
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.5.0.tgz#7a64eefa0b21112f89f58379da128ac177f20e40"
|
||||
integrity sha512-2iGbaQBV+ITgCz76ZEjmhUKAKVf7xfY1sRl4UiKQspfZMH2h06SyhNsnSVy50cwkFQDGLyif6m/6uFXHkOZ6rg==
|
||||
|
||||
node-gyp@8.x, node-gyp@^8.4.0:
|
||||
node-gyp@^8.4.0:
|
||||
version "8.4.1"
|
||||
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-8.4.1.tgz#3d49308fc31f768180957d6b5746845fbd429937"
|
||||
integrity sha512-olTJRgUtAb/hOXG0E93wZDs5YiJlgbXxTwQAFHyNlRsXQnYzUaF2aGgujZbw+hR8aF4ZG/rST57bWMWD16jr9w==
|
||||
@ -7640,10 +7638,10 @@ pause-stream@0.0.11:
|
||||
dependencies:
|
||||
through "~2.3"
|
||||
|
||||
pegjs@~0.8.0:
|
||||
version "0.8.0"
|
||||
resolved "https://registry.yarnpkg.com/pegjs/-/pegjs-0.8.0.tgz#976f067da13e5c5b1501c017925668a253811561"
|
||||
integrity sha512-GtAFD5WLxE0LjyhlpKwAnbi3NLJDrYsOvil95UCUQ6pzxlUtUGP/k0FnKGypTpM1WWdmoclfXb0dmMd5UUDkvA==
|
||||
pegjs@^0.10.0:
|
||||
version "0.10.0"
|
||||
resolved "https://registry.yarnpkg.com/pegjs/-/pegjs-0.10.0.tgz#cf8bafae6eddff4b5a7efb185269eaaf4610ddbd"
|
||||
integrity sha512-qI5+oFNEGi3L5HAxDwN2LA4Gg7irF70Zs25edhjld9QemOgp0CbvMtbFcMvFtEo1OityPrcCzkQFB8JP/hxgow==
|
||||
|
||||
pend@~1.2.0:
|
||||
version "1.2.0"
|
||||
@ -8722,8 +8720,7 @@ smart-buffer@^4.0.2, smart-buffer@^4.2.0:
|
||||
dependencies:
|
||||
async "~0.2.6"
|
||||
atom-select-list "^0.7.0"
|
||||
loophole "^1"
|
||||
pegjs "~0.8.0"
|
||||
pegjs "^0.10.0"
|
||||
scoped-property-store "^0.17.0"
|
||||
season "^6.0.2"
|
||||
temp "~0.8.0"
|
||||
@ -8875,18 +8872,6 @@ sprintf-js@~1.0.2:
|
||||
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
|
||||
integrity sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==
|
||||
|
||||
sqlite3@^5.1.7:
|
||||
version "5.1.7"
|
||||
resolved "https://registry.yarnpkg.com/sqlite3/-/sqlite3-5.1.7.tgz#59ca1053c1ab38647396586edad019b1551041b7"
|
||||
integrity sha512-GGIyOiFaG+TUra3JIfkI/zGP8yZYLPQ0pl1bH+ODjiX57sPhrLU5sQJn1y9bDKZUFYkX1crlrPfSYt0BKKdkog==
|
||||
dependencies:
|
||||
bindings "^1.5.0"
|
||||
node-addon-api "^7.0.0"
|
||||
prebuild-install "^7.1.1"
|
||||
tar "^6.1.11"
|
||||
optionalDependencies:
|
||||
node-gyp "8.x"
|
||||
|
||||
sshpk@^1.7.0:
|
||||
version "1.17.0"
|
||||
resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.17.0.tgz#578082d92d4fe612b13007496e543fa0fbcbe4c5"
|
||||
|
Loading…
Reference in New Issue
Block a user