bool modified;
};
-typedef struct AttachmentObj {
- int a;
-} AttachmentObj;
+typedef enum AttachmentType {
+ NOTE_ATTACHMENT_FILE = 0,
+ NOTE_ATTACHMENT_IMAGE
+} AttachmentType;
+
+typedef struct AttachmentModel {
+ UiContext *ctx;
+ const CxAllocator *note_allocator;
+
+ Note *parent_note;
+
+ int64_t resource_id;
+ AttachmentType type;
+ char *name;
+ char *temp_path;
+ char *temp_data;
+
+ void *data;
+} AttachmentModel;
void application_init();
"foreign key (parent_id) references collections(collection_id), " \
"unique (parent_id, name) " \
");"
+#define SQL_CREATE_TABLE_ATTACHMENTS "create table attachments( " \
+ "attachment_id integer primary key, " \
+ "resource_id integer, " \
+ "parent_id integer, " \
+ "type integer , " \
+ "foreign key (resource_id) references notes(note_id), " \
+ "foreign key (parent_id) references notes(note_id) " \
+ ");"
int store_sqlite_init_db(DBUConnection *connection) {
char *sql[] = {
SQL_CREATE_TABLE_REPOSITORIES,
SQL_CREATE_TABLE_COLLECTIONS,
SQL_CREATE_TABLE_USER_SETTINGS,
- SQL_CREATE_TABLE_NOTES
+ SQL_CREATE_TABLE_NOTES,
+ SQL_CREATE_TABLE_ATTACHMENTS
};
int nsql = sizeof(sql) / sizeof(char*);
DBUClass *repository_class;
DBUClass *collection_class;
DBUClass *notes_class;
+DBUClass *attachments_class;
DBUContext* get_dbu_context() {
return ctx;
dbuClassAdd(repository_class, Repository, default_key);
dbuClassAdd(repository_class, Repository, authmethod);
dbuClassAdd(repository_class, Repository, encryption);
+
+ attachments_class = dbuRegisterClass(ctx, "attachments", Attachment, attachment_id);
+ dbuClassAdd(attachments_class, Attachment, resource_id);
+ dbuClassAdd(attachments_class, Attachment, parent_id);
+ dbuClassAdd(attachments_class, Attachment, type);
}
typedef struct Repository Repository;
typedef struct Collection Collection;
typedef struct Note Note;
+typedef struct Attachment Attachment;
struct UserSettings {
char *host;
NoteModel *model;
};
+struct Attachment {
+ // db fields
+
+ int64_t attachment_id;
+ int64_t resource_id;
+ int64_t parent_id;
+ int type;
+
+ // temp fields
+ char *name;
+ cxmutstr bin_content;
+};
+
extern DBUClass *usersettings_class;
extern DBUClass *repository_class;
extern DBUClass *collection_class;