forked from mengning/nezha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbapi.h
100 lines (83 loc) · 2.62 KB
/
dbapi.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/********************************************************************/
/* Copyright (C) MC2Lab-USTC, 2012 */
/* */
/* FILE NAME : dbapi.h */
/* PRINCIPAL AUTHOR : Mengning */
/* SUBSYSTEM NAME : DB */
/* MODULE NAME : dbapi */
/* LANGUAGE : C */
/* TARGET ENVIRONMENT : ANY */
/* DATE OF FIRST RELEASE : 2012/2/28 */
/* DESCRIPTION : Abstract Interface of NoSQL DB API */
/********************************************************************/
/*
* Revision log:
*
* Created by Mengning,2012/2/28
* add some input/output args comments by Mengning,2012/2/29
* Modify for Nezha project,by Mengning,2012/11/27
*
*/
#ifndef _DB_API_H_
#define _DB_API_H_
#ifdef __cplusplus
extern "C" {
#endif
/********************************************************/
/* Abstract Interface of NoSQL DB API */
/********************************************************/
#define SUCCESS 0
#define FAILURE (-1)
typedef void* tDatabase;
typedef unsigned int tKey;
typedef struct Value{
int len; /* Length of string */
char *str; /* Used for Value Content */
}tValue;
/*
* Create an Database
* input : filename
* output : None
* in/out : None
* return : if SUCCESS return (tDatabase *)Database handler
* : if FAILURE exit(-1)
*/
tDatabase DBCreate(const char * filename);
/*
* Delete the Database
* input : tDatabase db
* output : None
* in/out : None
* return : SUCCESS(0)/exit(-1)
*/
int DBDelete(tDatabase db);
/*
* Set key/value
* input : tKey key,tValue value - one key/value
* output : None
* in/out : None
* return : SUCCESS(0)/FAILURE(-1)
*/
int DBSetKeyValue(tDatabase db,tKey key,tValue value);
/*
* get key/value
* input : tKey key
* output : None
* in/out : tValue *pvalue MUST BE initialized,it means pvalue->str is malloced,
: and pvalue->len is the length of pvalue->str
: if return SUCCESS(0),value will stored in pvalue(str,len).
* return : SUCCESS(0)/FAILURE(-1)
*/
int DBGetKeyValue(tDatabase db,tKey key,tValue *pvalue);
/*
* delete key/value
* input : tKey key
* output : None
* in/out : None
* return : SUCCESS(0)/FAILURE(-1)
*/
int DBDelKeyValue(tDatabase db,tKey key);
#ifdef __cplusplus
}
#endif
#endif /* _DB_API_H_ */