mirror of
https://github.com/h-sphere/sql-seal.git
synced 2026-07-22 10:10:28 +00:00
fix: fixed issue with the better-sqlite3 files.
This commit is contained in:
parent
0440d0d1a7
commit
00a33e1732
9 changed files with 745 additions and 652 deletions
|
|
@ -4,15 +4,12 @@ import builtins from "builtin-modules";
|
|||
import replacePlugin from "esbuild-plugin-replace-regex";
|
||||
import fs from "fs";
|
||||
|
||||
const nodeFileBase64 = fs.readFileSync("node_modules/better-sqlite3/build/Release/better_sqlite3.node", { encoding: "base64" });
|
||||
const patchStr = `
|
||||
const os = require("os")
|
||||
const arch = os.arch()
|
||||
const platform = os.platform()
|
||||
const libPath = app.vault.adapter.getFullPath(app.vault.configDir)
|
||||
let addonBuffer;
|
||||
if (!fs.existsSync(path.resolve(libPath, "plugins/sqlseal/better_sqlite3.node"))) {
|
||||
addonBuffer = Buffer.from("${nodeFileBase64.replaceAll('"', '\\"')}", "base64");
|
||||
fs.writeFileSync(path.resolve(libPath, "plugins/sqlseal/better_sqlite3.node"), addonBuffer);
|
||||
}
|
||||
addon = DEFAULT_ADDON || (DEFAULT_ADDON = require(path.resolve(libPath, "plugins/sqlseal/better_sqlite3.node")));
|
||||
addon = DEFAULT_ADDON || (DEFAULT_ADDON = require(path.resolve(libPath, \`plugins/sqlseal/better_sqlite3-\${platform}-\${arch}.node\`)));
|
||||
`;
|
||||
|
||||
const banner =
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "sqlseal",
|
||||
"name": "SQLSeal",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Use SQL in your notes to query your vault files and CSV content.",
|
||||
"author": "hypersphere",
|
||||
|
|
|
|||
9
package-lock.json
generated
9
package-lock.json
generated
|
|
@ -9,7 +9,7 @@
|
|||
"version": "0.3.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^9.5.0",
|
||||
"better-sqlite3": "^11.2.1",
|
||||
"lodash": "^4.17.21",
|
||||
"node-sql-parser": "^5.0.0",
|
||||
"papaparse": "^5.4.1"
|
||||
|
|
@ -2007,10 +2007,11 @@
|
|||
]
|
||||
},
|
||||
"node_modules/better-sqlite3": {
|
||||
"version": "9.5.0",
|
||||
"resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-9.5.0.tgz",
|
||||
"integrity": "sha512-01qVcM4gPNwE+PX7ARNiHINwzVuD6nx0gdldaAAcu+MrzyIAukQ31ZDKEpzRO/CNA9sHpxoTZ8rdjoyAin4dyg==",
|
||||
"version": "11.2.1",
|
||||
"resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.2.1.tgz",
|
||||
"integrity": "sha512-Xbt1d68wQnUuFIEVsbt6V+RG30zwgbtCGQ4QOcXVrOH0FE4eHk64FWZ9NUfRHS4/x1PXqwz/+KOrnXD7f0WieA==",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bindings": "^1.5.0",
|
||||
"prebuild-install": "^7.1.1"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "sqlseal",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0",
|
||||
"description": "A plugin for Obsidian that allows you to run SQL queries on your notes.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
"vue": "^3.4.26"
|
||||
},
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^9.5.0",
|
||||
"better-sqlite3": "^11.2.1",
|
||||
"lodash": "^4.17.21",
|
||||
"node-sql-parser": "^5.0.0",
|
||||
"papaparse": "^5.4.1"
|
||||
|
|
|
|||
1301
pnpm-lock.yaml
1301
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
|
|
@ -130,7 +130,14 @@ export class SealFileSync {
|
|||
|
||||
const schema = await this.sqlSeal.db.createTableWithData('files', data)
|
||||
this.currentSchema = schema
|
||||
await this.sqlSeal.db.createTableWithData('tags', tags)
|
||||
if (tags && tags.length) {
|
||||
await this.sqlSeal.db.createTableWithData('tags', tags)
|
||||
} else {
|
||||
await this.sqlSeal.db.createTable('tags', {
|
||||
'tag': 'TEXT',
|
||||
'fileId': 'TEXT'
|
||||
})
|
||||
}
|
||||
this.sqlSeal.observer.fireObservers('table:files')
|
||||
this.sqlSeal.observer.fireObservers('table:tags')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import Papa from 'papaparse'
|
|||
import { prefixedIfNotGlobal } from "./sqlReparseTables"
|
||||
import { camelCase } from 'lodash'
|
||||
import { fetchBlobData } from "./utils"
|
||||
import os from 'os'
|
||||
import fs from 'fs'
|
||||
|
||||
function isNumeric(str: string) {
|
||||
if (typeof str != "string") return false // we only process strings!
|
||||
|
|
@ -71,7 +73,7 @@ export class SqlSealDatabase {
|
|||
private connectingPromise;
|
||||
private connectingPromiseResolve;
|
||||
constructor(private readonly app: App, private readonly verbose = false) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -88,24 +90,40 @@ export class SqlSealDatabase {
|
|||
this.connectingPromiseResolve = resolve
|
||||
})
|
||||
//@ts-ignore
|
||||
const dbPath = normalizePath(this.app.vault.adapter.basePath + '/' + this.app.vault.configDir + '/sqlseal.db')
|
||||
|
||||
// const dbPath = path.resolve(this.app.vault.adapter.basePath, this.app.vault.configDir, "plugins/sqlseal/better_sqlite3.node")
|
||||
// check if file "better_sqlite3.node" exists in the plugin folder, if not, download it from github release
|
||||
// if (!fs.existsSync(dbPath)) {
|
||||
// const url = 'https://github.com/h-sphere/sql-seal/releases/download/0.2.0/better_sqlite3.node' // my github release url
|
||||
// const dbPath = normalizePath(this.app.vault.adapter.basePath + '/' + this.app.vault.configDir + '/sqlseal.db')
|
||||
|
||||
// await fetchBlobData(url, dbPath)
|
||||
// }
|
||||
const arch = os.arch()
|
||||
const platform = os.platform()
|
||||
const better_sql_version = 'v11.2.1'
|
||||
|
||||
// await sleep(500)
|
||||
const dbNodeFilePath = path.resolve(this.app.vault.adapter.basePath, this.app.vault.configDir, `plugins/sqlseal/better_sqlite3-${platform}-${arch}.node`)
|
||||
// check if file "better_sqlite3.node" exists in the plugin folder, if not, download it from better sqlite release.
|
||||
try {
|
||||
if (!fs.existsSync(dbNodeFilePath)) {
|
||||
const url = `https://github.com/h-sphere/bettersql3-builds/releases/download/processed-${better_sql_version}/better-sqlite3-${better_sql_version}-electron-v${process.versions.modules}-${platform}-${arch}.node`
|
||||
|
||||
// //@ts-ignore
|
||||
// const defaultDbPath = path.resolve(this.app.vault.adapter.basePath, this.app.vault.configDir, "sqlseal.db")
|
||||
this.db = new Database(dbPath, { verbose: this.verbose ? console.log : undefined })
|
||||
await fetchBlobData(url, dbNodeFilePath)
|
||||
}
|
||||
|
||||
this.isConnected = true
|
||||
this.connectingPromiseResolve()
|
||||
await sleep(500)
|
||||
|
||||
|
||||
const dbPath = path.resolve(this.app.vault.adapter.basePath, this.app.vault.configDir, `plugins/sqlseal/database.sqlite`)
|
||||
|
||||
this.db = new Database(dbPath, { verbose: this.verbose ? console.log : undefined })
|
||||
|
||||
this.isConnected = true
|
||||
this.connectingPromiseResolve()
|
||||
|
||||
} catch (e) {
|
||||
console.error(`Error while loading SQLSeal. Please reload Obsiidan. If it repeats, please create new issue on GitHub: https://github.com/h-sphere/sql-seal/issues . Please quote following parameters:
|
||||
Architecture: ${arch}
|
||||
Platform: ${platform}
|
||||
Electron Version: ${process.versions.modules}
|
||||
BetterSQLite Version: ${better_sql_version}
|
||||
Error: ${e}
|
||||
`, e)
|
||||
}
|
||||
}
|
||||
|
||||
async disconect() {
|
||||
|
|
@ -272,7 +290,7 @@ export class SqlSealDatabase {
|
|||
// this.savedDatabases[name] = url
|
||||
await this.loadDataForDatabaseFromUrl(name, url)
|
||||
|
||||
|
||||
|
||||
return name
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"0.1.0": "0.15.0",
|
||||
"0.2.0": "0.15.0",
|
||||
"0.3.0": "0.15.0"
|
||||
"0.3.0": "0.15.0",
|
||||
"0.4.0": "0.15.0"
|
||||
}
|
||||
|
|
@ -825,10 +825,10 @@ base64-js@^1.3.1:
|
|||
resolved "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz"
|
||||
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
|
||||
|
||||
better-sqlite3@^9.5.0:
|
||||
version "9.5.0"
|
||||
resolved "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-9.5.0.tgz"
|
||||
integrity sha512-01qVcM4gPNwE+PX7ARNiHINwzVuD6nx0gdldaAAcu+MrzyIAukQ31ZDKEpzRO/CNA9sHpxoTZ8rdjoyAin4dyg==
|
||||
better-sqlite3@^11.2.1:
|
||||
version "11.2.1"
|
||||
resolved "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.2.1.tgz"
|
||||
integrity sha512-Xbt1d68wQnUuFIEVsbt6V+RG30zwgbtCGQ4QOcXVrOH0FE4eHk64FWZ9NUfRHS4/x1PXqwz/+KOrnXD7f0WieA==
|
||||
dependencies:
|
||||
bindings "^1.5.0"
|
||||
prebuild-install "^7.1.1"
|
||||
|
|
|
|||
Loading…
Reference in a new issue