File tree 8 files changed +133
-0
lines changed
8 files changed +133
-0
lines changed Original file line number Diff line number Diff line change
1
+ node_modules
2
+ database.sqlite
Original file line number Diff line number Diff line change
1
+ # Example how to use TypeORM with Electron using JavaScript
2
+
3
+ 1 . clone repository
4
+ 2 . run ` npm i `
5
+ 3 . run ` npm start `
6
+ 4 . enjoy!
7
+
8
+ ![ typeorm-electron-example] ( ./resources/screen.png )
Original file line number Diff line number Diff line change
1
+ {
2
+ "type" : " sqlite" ,
3
+ "synchronize" : true ,
4
+ "logging" : true ,
5
+ "logger" : " simple-console" ,
6
+ "database" : " database.sqlite" ,
7
+ "entities" : [
8
+ " src/entity/*.js"
9
+ ]
10
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " typeorm-electron-javascript-example" ,
3
+ "version" : " 0.0.1" ,
4
+ "description" : " " ,
5
+ "license" : " MIT" ,
6
+ "readmeFilename" : " README.md" ,
7
+ "author" : {
8
+ "name" : " Umed Khudoiberdiev" ,
9
+
10
+ },
11
+ "repository" : {
12
+ "type" : " git" ,
13
+ "url" : " https://github.com/typeorm/electron-javascript-example.git"
14
+ },
15
+ "bugs" : {
16
+ "url" : " https://github.com/typeorm/electron-javascript-example/issues"
17
+ },
18
+ "tags" : [
19
+ " orm" ,
20
+ " typescript" ,
21
+ " typescript-orm" ,
22
+ " electron-orm" ,
23
+ " typeorm-sample" ,
24
+ " typeorm-example"
25
+ ],
26
+ "dependencies" : {
27
+ "electron" : " ^1.8.4" ,
28
+ "sqlite3" : " ^4.0.0" ,
29
+ "typeorm" : " ^0.2.0-alpha.46"
30
+ },
31
+ "devDependencies" : {
32
+ "electron-builder" : " ^20.8.1"
33
+ },
34
+ "scripts" : {
35
+ "start" : " electron src/index.js" ,
36
+ "postinstall" : " install-app-deps"
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ var EntitySchema = require ( "typeorm" ) . EntitySchema ;
2
+
3
+ module . exports = new EntitySchema ( {
4
+ name : "Post" ,
5
+ columns : {
6
+ id : {
7
+ type : Number ,
8
+ primary : true ,
9
+ generated : true
10
+ } ,
11
+ title : {
12
+ type : String
13
+ } ,
14
+ text : {
15
+ type : String
16
+ }
17
+ }
18
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Electron App</ title >
6
+ </ head >
7
+ < body >
8
+
9
+ < h1 > Posts:</ h1 >
10
+
11
+ < ul id ="postList "> </ ul >
12
+
13
+ < small > Refresh and you'll see a new post added.</ small >
14
+
15
+ < script >
16
+ var typeorm = require ( "typeorm" ) ;
17
+ typeorm . createConnection ( ) . then ( ( ) => {
18
+ var post = {
19
+ title : "post title" ,
20
+ text : "post text"
21
+
22
+ } ;
23
+ return typeorm . getRepository ( "Post" ) . save ( post ) ;
24
+
25
+ } ) . then ( ( ) => {
26
+ console . log ( "Saved successfully!" ) ;
27
+ return typeorm . getRepository ( "Post" ) . find ( ) ;
28
+
29
+ } ) . then ( posts => {
30
+ console . log ( "Posts: " , posts ) ;
31
+
32
+ let ul = document . getElementById ( "postList" ) ;
33
+ posts . forEach ( post => {
34
+ var li = document . createElement ( 'li' ) ;
35
+ li . innerText = post . id + ". " + post . title ;
36
+ ul . appendChild ( li ) ;
37
+ } ) ;
38
+
39
+ } ) . catch ( error => {
40
+ console . error ( "Error: " , error ) ;
41
+ } ) ;
42
+ </ script >
43
+
44
+ </ body >
45
+ </ html >
Original file line number Diff line number Diff line change
1
+ var electron = require ( "electron" ) ;
2
+ var url = require ( "url" ) ;
3
+
4
+ electron . app . on ( "ready" , ( ) => {
5
+ var mainWindow = new electron . BrowserWindow ( { } ) ;
6
+ mainWindow . loadURL ( url . format ( {
7
+ pathname : __dirname + "/index.html" ,
8
+ protocol : "file:" ,
9
+ slashes : true
10
+ } ) ) ;
11
+ mainWindow . toggleDevTools ( ) ;
12
+ } ) ;
You can’t perform that action at this time.
0 commit comments