2015-01-23 04:59:47 +00:00
|
|
|
#ifndef __LIBRETRODB_H__
|
|
|
|
#define __LIBRETRODB_H__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <direct.h>
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include "rmsgpack_dom.h"
|
|
|
|
|
|
|
|
#define MAGIC_NUMBER "RARCHDB"
|
|
|
|
|
2015-01-23 05:05:54 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-01-23 04:59:47 +00:00
|
|
|
typedef struct libretrodb_query libretrodb_query_t;
|
|
|
|
|
|
|
|
typedef struct libretrodb
|
|
|
|
{
|
2015-09-17 04:12:57 +00:00
|
|
|
int fd;
|
2015-01-23 04:59:47 +00:00
|
|
|
uint64_t root;
|
|
|
|
uint64_t count;
|
|
|
|
uint64_t first_index_offset;
|
2015-01-27 03:16:05 +00:00
|
|
|
char path[1024];
|
2015-01-23 04:59:47 +00:00
|
|
|
} libretrodb_t;
|
|
|
|
|
|
|
|
typedef struct libretrodb_index
|
|
|
|
{
|
|
|
|
char name[50];
|
|
|
|
uint64_t key_size;
|
|
|
|
uint64_t next;
|
|
|
|
} libretrodb_index_t;
|
|
|
|
|
|
|
|
typedef struct libretrodb_metadata
|
|
|
|
{
|
|
|
|
uint64_t count;
|
|
|
|
} libretrodb_metadata_t;
|
|
|
|
|
|
|
|
typedef struct libretrodb_header
|
|
|
|
{
|
|
|
|
char magic_number[sizeof(MAGIC_NUMBER)-1];
|
|
|
|
uint64_t metadata_offset;
|
|
|
|
} libretrodb_header_t;
|
|
|
|
|
|
|
|
typedef struct libretrodb_cursor
|
|
|
|
{
|
|
|
|
int is_valid;
|
2015-09-17 04:12:57 +00:00
|
|
|
int fd;
|
2015-01-23 04:59:47 +00:00
|
|
|
int eof;
|
2015-09-17 07:33:24 +00:00
|
|
|
libretrodb_query_t *query;
|
|
|
|
libretrodb_t *db;
|
2015-01-23 04:59:47 +00:00
|
|
|
} libretrodb_cursor_t;
|
|
|
|
|
2015-09-17 07:33:24 +00:00
|
|
|
typedef int (*libretrodb_value_provider)(void *ctx,
|
|
|
|
struct rmsgpack_dom_value *out);
|
2015-01-23 04:59:47 +00:00
|
|
|
|
2015-09-17 07:33:24 +00:00
|
|
|
int libretrodb_create(int fd,
|
|
|
|
libretrodb_value_provider value_provider, void *ctx);
|
2015-01-23 04:59:47 +00:00
|
|
|
|
2015-09-17 07:33:24 +00:00
|
|
|
void libretrodb_close(libretrodb_t *db);
|
2015-01-23 04:59:47 +00:00
|
|
|
|
2015-09-17 07:33:24 +00:00
|
|
|
int libretrodb_open(const char *path, libretrodb_t *db);
|
2015-01-24 03:04:56 +00:00
|
|
|
|
2015-09-17 07:33:24 +00:00
|
|
|
int libretrodb_create_index(libretrodb_t *db, const char *name,
|
2015-01-24 03:04:56 +00:00
|
|
|
const char *field_name);
|
2015-01-23 04:59:47 +00:00
|
|
|
|
2015-09-17 07:33:24 +00:00
|
|
|
int libretrodb_find_entry(libretrodb_t *db, const char *index_name,
|
|
|
|
const void *key, struct rmsgpack_dom_value *out);
|
2015-01-23 04:59:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* libretrodb_cursor_open:
|
|
|
|
* @db : Handle to database.
|
|
|
|
* @cursor : Handle to database cursor.
|
|
|
|
* @q : Query to execute.
|
|
|
|
*
|
|
|
|
* Opens cursor to database based on query @q.
|
|
|
|
*
|
|
|
|
* Returns: 0 if successful, otherwise negative.
|
|
|
|
**/
|
|
|
|
int libretrodb_cursor_open(
|
|
|
|
libretrodb_t *db,
|
|
|
|
libretrodb_cursor_t *cursor,
|
|
|
|
libretrodb_query_t *query
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* libretrodb_cursor_reset:
|
|
|
|
* @cursor : Handle to database cursor.
|
|
|
|
*
|
|
|
|
* Resets cursor.
|
|
|
|
*
|
|
|
|
* Returns: ???.
|
|
|
|
**/
|
2015-09-17 07:33:24 +00:00
|
|
|
int libretrodb_cursor_reset(libretrodb_cursor_t *cursor);
|
2015-01-23 04:59:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* libretrodb_cursor_close:
|
|
|
|
* @cursor : Handle to database cursor.
|
|
|
|
*
|
|
|
|
* Closes cursor and frees up allocated memory.
|
|
|
|
**/
|
2015-09-17 07:33:24 +00:00
|
|
|
void libretrodb_cursor_close(libretrodb_cursor_t *cursor);
|
2015-01-23 04:59:47 +00:00
|
|
|
|
2015-09-17 07:33:24 +00:00
|
|
|
void *libretrodb_query_compile(libretrodb_t *db, const char *query,
|
|
|
|
size_t buff_len, const char **error);
|
2015-01-23 04:59:47 +00:00
|
|
|
|
|
|
|
void libretrodb_query_free(void *q);
|
|
|
|
|
2015-09-17 07:33:24 +00:00
|
|
|
int libretrodb_cursor_read_item(libretrodb_cursor_t *cursor,
|
|
|
|
struct rmsgpack_dom_value *out);
|
2015-01-23 04:59:47 +00:00
|
|
|
|
2015-01-23 05:05:54 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-23 04:59:47 +00:00
|
|
|
#endif
|