Skip to content

Commit 50a40e9

Browse files
committed
Created the first version, testing SQLite3, KnexJs, ElectronJs
0 parents commit 50a40e9

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

database.sqlite

4 KB
Binary file not shown.

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { app, BrowserWindow, ipcMain } = require("electron")
2+
3+
var knex = require("knex")({
4+
client: "sqlite3",
5+
connection: {
6+
filename: "./database.sqlite"
7+
}
8+
});
9+
10+
app.on("ready", () => {
11+
let mainWindow = new BrowserWindow({ height: 800, width: 800, show: false })
12+
mainWindow.loadURL(`file://${__dirname}/main.html`)
13+
mainWindow.once("ready-to-show", () => { mainWindow.show() })
14+
15+
ipcMain.on("mainWindowLoaded", function () {
16+
let result = knex.select("FirstName").from("User")
17+
result.then(function(rows){
18+
mainWindow.webContents.send("resultSent", rows);
19+
})
20+
});
21+
});
22+
23+
24+
25+
app.on("window-all-closed", () => { app.quit() })

main.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<html>
2+
<head>
3+
<title></title>
4+
<script>
5+
const electron = require("electron");
6+
const ipc = electron.ipcRenderer;
7+
document.addEventListener("DOMContentLoaded", function(){
8+
ipc.send("mainWindowLoaded")
9+
ipc.on("resultSent", function(evt, result){
10+
let resultEl = document.getElementById("result");
11+
console.log(result);
12+
for(var i = 0; i < result.length;i++){
13+
resultEl.innerHTML += "First Name: " + result[i].FirstName.toString() + "<br/>";
14+
}
15+
});
16+
});
17+
</script>
18+
</head>
19+
<body>
20+
<p id="result"></p>
21+
</body>
22+
</html>

package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "electron-test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "electron .",
8+
"rebuild": "electron-rebuild -f -w sqlite3",
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"keywords": [],
12+
"author": "",
13+
"license": "ISC",
14+
"dependencies": {
15+
"electron": "^1.6.6",
16+
"knex": "^0.13.0",
17+
"sqlite3": "^3.1.8"
18+
},
19+
"devDependencies": {
20+
"electron-rebuild": "^1.5.7"
21+
}
22+
}

0 commit comments

Comments
 (0)