Skip to main content

Electron

This backend uses better-sqlite3.

This guide is for https://www.electronforge.io/ , but it still will be helpful if you have custom electron configuration.

Installation

Install Kikko packages :

yarn add @kikko-land/sql.js @kikko-land/electron-better-sqlite3-backend

Fix native modules webpack issue in webpack.plugins.js:

const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const relocateLoader = require("@vercel/webpack-asset-relocator-loader");

module.exports = [
new ForkTsCheckerWebpackPlugin(),
{
apply(compiler) {
compiler.hooks.compilation.tap(
"webpack-asset-relocator-loader",
(compilation) => {
relocateLoader.initAssetCache(compilation, "native_modules");
}
);
},
},
];

Add this to preload.ts:

// See https://github.com/import-js/eslint-plugin-import/issues/1810
// eslint-disable-next-line import/no-unresolved
import { initSqliteBridge } from "@kikko-land/electron-better-sqlite3-backend/preload";

initSqliteBridge();

And init Kikko:

import { electronBetterSqlite3Backend } from "@kikko-land/electron-better-sqlite3-backend";

const config: IInitDbClientConfig = {
dbName: "helloWorld",
dbBackend: electronBetterSqlite3Backend((dbName) => `${dbName}.db`),
plugins: [migrationsPlugin({ migrations: [] }), reactiveQueriesPlugin()],
};

Usage example repo: https://github.com/kikko-land/kikko-electron-better-sqlite3-example