-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinydb_object.c
37 lines (32 loc) · 899 Bytes
/
tinydb_object.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "tinydb_object.h"
#include "tinydb_database_entry_destructor.h"
DB_Object*
CreateDBObject()
{
DB_Object* obj = (DB_Object*)malloc(sizeof(DB_Object));
obj->fields = HM_Create(Database_Entry_Destructor);
return obj;
}
int32_t
DBObject_AddField(DB_Object* obj,
const char* field_name,
DB_Value value,
DB_ENTRY_TYPE type)
{
DatabaseEntry* new_entry = (DatabaseEntry*)malloc(sizeof(DatabaseEntry));
new_entry->key = strdup(field_name);
new_entry->value = value;
new_entry->type = type;
int8_t state = HM_Put(obj->fields, new_entry->key, new_entry);
return state;
}
DatabaseEntry*
DBObject_GetField(DB_Object* obj, const char* field_name)
{
return (DatabaseEntry*)HM_Get(obj->fields, field_name);
}
int32_t
DBObject_RemoveField(DB_Object* obj, const char* field_name)
{
return HM_Remove(obj->fields, field_name);
}