You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.2 KiB
83 lines
2.2 KiB
import {Model} from './Model';
|
|
|
|
export interface IDatabaseEntry {
|
|
id?: number;
|
|
DatabaseId: string;
|
|
RowDataJSON: string;
|
|
UUID: string;
|
|
needsServerUpdate?: boolean;
|
|
deleted?: boolean;
|
|
}
|
|
|
|
export class DatabaseEntry extends Model<IDatabaseEntry> implements IDatabaseEntry {
|
|
id?: number;
|
|
DatabaseId: string;
|
|
RowDataJSON: string;
|
|
UUID: string;
|
|
needsServerUpdate?: boolean;
|
|
deleted?: boolean;
|
|
|
|
public static getTableName() {
|
|
return 'databaseEntries';
|
|
}
|
|
|
|
public static getSchema() {
|
|
return '++id, DatabaseId, RowDataJSON, UUID, needsServerUpdate, deleted';
|
|
}
|
|
|
|
constructor(
|
|
DatabaseId: string,
|
|
RowDataJSON: string,
|
|
UUID: string,
|
|
needsServerUpdate?: boolean,
|
|
deleted?: boolean,
|
|
id?: number
|
|
) {
|
|
super();
|
|
|
|
this.DatabaseId = DatabaseId;
|
|
this.RowDataJSON = RowDataJSON;
|
|
this.UUID = UUID;
|
|
|
|
if ( typeof needsServerUpdate !== 'undefined' ) {
|
|
this.needsServerUpdate = needsServerUpdate;
|
|
}
|
|
|
|
if ( typeof deleted !== 'undefined' ) {
|
|
this.deleted = deleted;
|
|
}
|
|
|
|
if ( id ) {
|
|
this.id = id;
|
|
}
|
|
}
|
|
|
|
public fillFromRecord(record: any) {
|
|
this.DatabaseId = record.DatabaseId;
|
|
this.RowDataJSON = JSON.stringify(record.RowData);
|
|
this.UUID = record.UUID;
|
|
}
|
|
|
|
public inflateToRecord() {
|
|
const record = this.getSaveRecord();
|
|
record.RowData = record.RowDataJSON ? JSON.parse(record.RowDataJSON) : {};
|
|
delete record.RowDataJSON;
|
|
return record;
|
|
}
|
|
|
|
public getSaveRecord(): any {
|
|
return {
|
|
...(this.id ? { id: this.id } : {}),
|
|
DatabaseId: this.DatabaseId,
|
|
RowDataJSON: this.RowDataJSON,
|
|
UUID: this.UUID,
|
|
...(typeof this.needsServerUpdate === 'undefined' ? {} : { needsServerUpdate: this.needsServerUpdate }),
|
|
...(typeof this.deleted === 'undefined' ? {} : { deleted: this.deleted }),
|
|
};
|
|
}
|
|
|
|
public getDatabase(): Dexie.Table<IDatabaseEntry, number> {
|
|
return this.staticClass().dbService.table('databaseEntries') as Dexie.Table<IDatabaseEntry, number>;
|
|
}
|
|
}
|