Add Realm base

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2023-07-08 19:07:31 +03:00
parent 3cdf3c2295
commit c1c22145b2
7 changed files with 103 additions and 30 deletions

2
src/database/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export { MEME_TYPE, Meme } from './meme';
export { Tag } from './tag';

45
src/database/meme.ts Normal file
View File

@@ -0,0 +1,45 @@
import { Realm } from '@realm/react';
import { Tag } from './tag';
enum MEME_TYPE {
IMAGE = 'IMAGE',
GIF = 'GIF',
ALMBUM = 'ALMBUM',
VIDEO = 'VIDEO',
AUDIO = 'AUDIO',
TEXT = 'TEXT',
}
class Meme extends Realm.Object<Meme> {
id!: Realm.BSON.UUID;
type!: MEME_TYPE;
uri!: string;
title!: string;
description?: string;
isFavorite!: boolean;
tags!: Realm.List<Tag>;
dateCreated!: Date;
dateModified!: Date;
dateUsed?: Date;
timesUsed!: number;
static schema: Realm.ObjectSchema = {
name: 'Meme',
primaryKey: 'id',
properties: {
id: 'uuid',
type: { type: 'string', indexed: true },
uri: 'string',
title: 'string',
description: 'string?',
isFavorite: { type: 'bool', indexed: true, default: false },
tags: 'Tag[]',
dateCreated: 'date',
dateModified: 'date',
dateUsed: 'date?',
timesUsed: { type: 'int', default: 0 },
},
};
}
export { MEME_TYPE, Meme };

22
src/database/tag.ts Normal file
View File

@@ -0,0 +1,22 @@
import { Realm } from '@realm/react';
import { Meme } from './meme';
class Tag extends Realm.Object<Tag> {
id!: Realm.BSON.UUID;
name!: string;
color!: string;
memes!: Realm.List<Meme>;
static schema: Realm.ObjectSchema = {
name: 'Tag',
primaryKey: 'id',
properties: {
id: 'uuid',
name: 'string',
color: 'string',
memes: 'Meme[]',
},
};
}
export { Tag };