install sqlite3 and typeorm together with electron-rebuild, create first entities
This commit is contained in:
parent
3ca66d6958
commit
74f76a83fb
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,3 +4,6 @@ node_modules
|
||||
# generated code
|
||||
dist
|
||||
frontend
|
||||
|
||||
# databases
|
||||
database
|
||||
|
10
README.md
10
README.md
@ -1,6 +1,14 @@
|
||||
## Hello There
|
||||
## Development
|
||||
|
||||
- `npm install`
|
||||
- `npm run rebuild`
|
||||
- might need to install some build tools depending on your platform
|
||||
- `npm run tsc` for backend
|
||||
- `npm run webpack` for frontend
|
||||
- `npm dev`
|
||||
|
||||
## Donations
|
||||
|
||||
| | |
|
||||
| --- | ------------------------------------------------------ |
|
||||
| BCH | bitcoincash:qrm4v447q22nw8lyxmpam2eakd22vmsfagfxttznyc |
|
||||
|
5
ormconfig.yml
Normal file
5
ormconfig.yml
Normal file
@ -0,0 +1,5 @@
|
||||
library:
|
||||
type: sqlite
|
||||
database: ./database/library.db
|
||||
entities:
|
||||
- ./dist/main/entities/*.js
|
894
package-lock.json
generated
894
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -6,8 +6,10 @@
|
||||
"author": "Xymorot",
|
||||
"main": "dist/main.js",
|
||||
"scripts": {
|
||||
"postinstall": "npm run rebuild",
|
||||
"start": "electron .",
|
||||
"dev": "electron . --enable-logging",
|
||||
"rebuild": "electron-rebuild -f -b -t prod,dev,optional",
|
||||
"tsc": "tsc --watch",
|
||||
"webpack": "webpack --watch",
|
||||
"eslint-check": "eslint --print-config . | eslint-config-prettier-check",
|
||||
@ -20,17 +22,20 @@
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@types/webpack": "^4.4.32",
|
||||
"electron": "^5.0.4",
|
||||
"electron": "^5.0.5",
|
||||
"electron-rebuild": "^1.8.5",
|
||||
"eslint": "^5.16.0",
|
||||
"eslint-config-prettier": "^5.0.0",
|
||||
"eslint-plugin-prettier": "^3.1.0",
|
||||
"prettier": "^1.18.2",
|
||||
"sqlite3": "^4.0.9",
|
||||
"svelte": "^3.5.1",
|
||||
"svelte-loader": "^2.13.4",
|
||||
"ts-loader": "^6.0.2",
|
||||
"ts-loader": "^6.0.3",
|
||||
"tslint": "^5.17.0",
|
||||
"tslint-config-prettier": "^1.18.0",
|
||||
"tslint-plugin-prettier": "^2.0.1",
|
||||
"typeorm": "^0.2.18",
|
||||
"typescript": "^3.5.2",
|
||||
"typescript-tslint-plugin": "^0.5.0",
|
||||
"webpack": "^4.34.0",
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { app, BrowserWindow } from 'electron';
|
||||
|
||||
import './main/services/api';
|
||||
import './main/services/database';
|
||||
import session from './main/services/session';
|
||||
|
||||
let mainWindow: Electron.BrowserWindow;
|
||||
|
13
src/main/entities/author.ts
Normal file
13
src/main/entities/author.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Entity, ManyToMany } from 'typeorm';
|
||||
import { MultiNamed } from './bases/multiNamed';
|
||||
import { Book } from './book';
|
||||
|
||||
@Entity()
|
||||
export class Author extends MultiNamed {
|
||||
@ManyToMany(() => Book, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
public books: Promise<Book[]>;
|
||||
}
|
7
src/main/entities/bases/base.ts
Normal file
7
src/main/entities/bases/base.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
export abstract class Base {
|
||||
@PrimaryGeneratedColumn()
|
||||
public id: number;
|
||||
}
|
11
src/main/entities/bases/multiNamed.ts
Normal file
11
src/main/entities/bases/multiNamed.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { Base } from './base';
|
||||
|
||||
@Entity()
|
||||
export abstract class MultiNamed extends Base {
|
||||
@Column()
|
||||
public nameCanonical: string;
|
||||
|
||||
@Column('simple-array')
|
||||
public names: string[];
|
||||
}
|
40
src/main/entities/book.ts
Normal file
40
src/main/entities/book.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { Entity, JoinTable, ManyToMany, OneToMany } from 'typeorm';
|
||||
import { Author } from './author';
|
||||
import { MultiNamed } from './bases/multiNamed';
|
||||
import { Copy } from './copy';
|
||||
import { IntellectualProperty } from './intellectualProperty';
|
||||
import { Tag } from './tag';
|
||||
|
||||
@Entity()
|
||||
export class Book extends MultiNamed {
|
||||
@OneToMany(() => Copy, copy => copy.original, {
|
||||
nullable: true,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
public copies: Promise<Copy[]>;
|
||||
|
||||
@ManyToMany(() => Author, {
|
||||
nullable: true,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
@JoinTable()
|
||||
public authors: Promise<Author[]>;
|
||||
|
||||
@ManyToMany(() => IntellectualProperty, {
|
||||
nullable: true,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
@JoinTable()
|
||||
public intellectualProperties: Promise<IntellectualProperty[]>;
|
||||
|
||||
@ManyToMany(() => Tag, {
|
||||
nullable: true,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
@JoinTable()
|
||||
public tags: Promise<Tag[]>;
|
||||
}
|
57
src/main/entities/copy.ts
Normal file
57
src/main/entities/copy.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinTable,
|
||||
ManyToMany,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
} from 'typeorm';
|
||||
import { Base } from './bases/base';
|
||||
import { Book } from './book';
|
||||
import { CopyType } from './copyType';
|
||||
import { Language } from './language';
|
||||
import { Source } from './source';
|
||||
import { Translator } from './translator';
|
||||
|
||||
@Entity()
|
||||
export class Copy extends Base {
|
||||
@ManyToOne(() => Book, book => book.copies, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
public original: Promise<Book>;
|
||||
|
||||
@Column({ nullable: false, default: false })
|
||||
public favorites: boolean;
|
||||
|
||||
@OneToMany(() => CopyType, copyType => copyType.copy)
|
||||
public types: Promise<CopyType[]>;
|
||||
|
||||
@Column({ nullable: true })
|
||||
public isDigital: boolean;
|
||||
|
||||
@ManyToMany(() => Source, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
@JoinTable()
|
||||
public sources: Promise<Source[]>;
|
||||
|
||||
@ManyToMany(() => Language, {
|
||||
nullable: true,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
@JoinTable()
|
||||
public languages: Promise<Language[]>;
|
||||
|
||||
@ManyToMany(() => Translator, {
|
||||
nullable: true,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
@JoinTable()
|
||||
public translators: Promise<Translator[]>;
|
||||
}
|
26
src/main/entities/copyType.ts
Normal file
26
src/main/entities/copyType.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { Column, Entity, ManyToOne } from 'typeorm';
|
||||
import { Base } from './bases/base';
|
||||
import { Copy } from './copy';
|
||||
|
||||
const enum CopyTypes {
|
||||
ORIGINAL,
|
||||
TRANSLATED,
|
||||
UNCENSORED,
|
||||
OTHER,
|
||||
}
|
||||
|
||||
@Entity()
|
||||
export class CopyType extends Base {
|
||||
@ManyToOne(() => Copy, copy => copy.types, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
public copy: Promise<Copy>;
|
||||
|
||||
@Column({ nullable: false })
|
||||
public type: CopyTypes;
|
||||
|
||||
@Column({ nullable: true })
|
||||
public comment: string;
|
||||
}
|
13
src/main/entities/intellectualProperty.ts
Normal file
13
src/main/entities/intellectualProperty.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Entity, ManyToMany } from 'typeorm';
|
||||
import { MultiNamed } from './bases/multiNamed';
|
||||
import { Book } from './book';
|
||||
|
||||
@Entity()
|
||||
export class IntellectualProperty extends MultiNamed {
|
||||
@ManyToMany(() => Book, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
public books: Promise<Book[]>;
|
||||
}
|
19
src/main/entities/language.ts
Normal file
19
src/main/entities/language.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Column, Entity, ManyToMany } from 'typeorm';
|
||||
import { Base } from './bases/base';
|
||||
import { Copy } from './copy';
|
||||
|
||||
@Entity()
|
||||
export class Language extends Base {
|
||||
@Column({
|
||||
nullable: false,
|
||||
unique: true,
|
||||
})
|
||||
public code: string;
|
||||
|
||||
@ManyToMany(() => Copy, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
public copies: Promise<Copy[]>;
|
||||
}
|
13
src/main/entities/site.ts
Normal file
13
src/main/entities/site.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Entity, OneToMany } from 'typeorm';
|
||||
import { MultiNamed } from './bases/multiNamed';
|
||||
import { Source } from './source';
|
||||
|
||||
@Entity()
|
||||
export class Site extends MultiNamed {
|
||||
@OneToMany(() => Source, source => source.site, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
public sources: Promise<Source[]>;
|
||||
}
|
27
src/main/entities/source.ts
Normal file
27
src/main/entities/source.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { Column, Entity, ManyToMany, ManyToOne } from 'typeorm';
|
||||
import { Base } from './bases/base';
|
||||
import { Copy } from './copy';
|
||||
import { Site } from './site';
|
||||
|
||||
@Entity()
|
||||
export class Source extends Base {
|
||||
@Column({
|
||||
nullable: false,
|
||||
unique: true,
|
||||
})
|
||||
public uri: string;
|
||||
|
||||
@ManyToOne(() => Site, site => site.sources, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
public site: Promise<Site>;
|
||||
|
||||
@ManyToMany(() => Copy, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
public copies: Promise<Copy[]>;
|
||||
}
|
13
src/main/entities/tag.ts
Normal file
13
src/main/entities/tag.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Entity, ManyToMany } from 'typeorm';
|
||||
import { MultiNamed } from './bases/multiNamed';
|
||||
import { Book } from './book';
|
||||
|
||||
@Entity()
|
||||
export class Tag extends MultiNamed {
|
||||
@ManyToMany(() => Book, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
public books: Promise<Book[]>;
|
||||
}
|
13
src/main/entities/translator.ts
Normal file
13
src/main/entities/translator.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Entity, ManyToMany } from 'typeorm';
|
||||
import { MultiNamed } from './bases/multiNamed';
|
||||
import { Copy } from './copy';
|
||||
|
||||
@Entity()
|
||||
export class Translator extends MultiNamed {
|
||||
@ManyToMany(() => Copy, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
public copies: Promise<Copy[]>;
|
||||
}
|
22
src/main/services/database.ts
Normal file
22
src/main/services/database.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import 'reflect-metadata';
|
||||
import { Connection, createConnection } from 'typeorm';
|
||||
|
||||
let connection: Connection;
|
||||
|
||||
function init() {
|
||||
initConnection();
|
||||
}
|
||||
|
||||
function initConnection(): void {
|
||||
// createConnection method will automatically read connection options
|
||||
// from your ormconfig file or environment variables
|
||||
createConnection('library')
|
||||
.then(c => {
|
||||
connection = c;
|
||||
})
|
||||
.catch(reason => {
|
||||
throw reason;
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
@ -6,6 +6,8 @@
|
||||
"sourceMap": true,
|
||||
"allowJs": true,
|
||||
"preserveConstEnums": false,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"lib": ["es2017", "dom"],
|
||||
"plugins": [
|
||||
{
|
||||
|
@ -13,7 +13,8 @@
|
||||
"no-unused-expression": true,
|
||||
"await-promise": true,
|
||||
"no-inferrable-types": true,
|
||||
"prefer-for-of": true
|
||||
"prefer-for-of": true,
|
||||
"no-empty": [true, "allow-empty-functions"]
|
||||
},
|
||||
"jsRules": true
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user