Files
OSIT-AE-App-Svelte/src/lib/db_posts.ts
2024-09-27 18:55:24 -04:00

118 lines
2.7 KiB
TypeScript

import Dexie, { type Table } from 'dexie';
import type { key_val } from './ae_stores';
// li = list
// kv = key value list
// Updated 2024-09-25
export interface Post {
id: string;
// id_random: string;
post_id: string;
// post_id_random: string;
account_id: string;
// account_id_random: string;
person_id?: null|string;
external_person_id?: null|string; // For IDAA this is the Novi UUID
user_id?: null|string;
topic_id?: string;
topic?: string; // or topic_name?
topic_name?: string;
// name: null|string;
// summary?: null|string;
title: null|string;
content?: null|string;
anonymous?: null|boolean;
full_name?: null|string;
email?: null|string;
enable_comments?: null|boolean;
archive?: null|boolean;
archive_on?: Date;
cfg_json?: null|key_val;
enable: null|boolean;
hide?: null|boolean;
priority?: null|boolean
sort?: null|number;
group?: null|string;
notes?: null|string;
created_on: Date;
updated_on?: null|Date;
// Additional fields for convenience (database views)
post_comment_count?: number;
}
// Updated 2024-09-25
export interface Post_Comment {
id: string;
// id_random: string;
post_comment_id: string;
// post_comment_id_random: string;
post_id: string;
// post_id_random: string;
// name: null|string;
// summary?: null|string;
title: null|string;
content?: null|string;
anonymous?: null|boolean;
full_name?: null|string;
email?: null|string;
cfg_json?: null|key_val;
enable: null|boolean;
hide?: null|boolean;
priority?: null|boolean
sort?: null|number;
group?: null|string;
notes?: null|string;
created_on: Date;
updated_on?: null|Date;
// Additional fields for convenience (database views)
}
// Updated 2024-09-25
export class MySubClassedDexie extends Dexie {
// We just tell the typing system this is the case
post!: Table<Post>;
comment!: Table<Post_Comment>;
constructor() {
super('ae_posts_db');
this.version(1).stores({
post: `
id, post_id,
account_id,
topic_id, topic,
title,
full_name, email,
archive, archive_on,
enable, hide, priority, sort, group, notes, created_on, updated_on`,
comment: `
id, post_comment_id,
post_id,
title,
full_name, email,
enable, hide, priority, sort, group, notes, created_on, updated_on`,
});
}
}
export const db_posts = new MySubClassedDexie();