-
Notifications
You must be signed in to change notification settings - Fork 1
/
cozo_c.h
131 lines (115 loc) · 4.11 KB
/
cozo_c.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
Copyright 2022, The Cozo Project Authors.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef COZO_C_H
#define COZO_C_H
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/**
* Open a database.
*
* `engine`: which storage engine to use, can be "mem", "sqlite" or "rocksdb".
* `path`: should contain the UTF-8 encoded path name as a null-terminated C-string.
* `db_id`: will contain the id of the database opened.
* `options`: options for the DB constructor: engine dependent.
*
* When the function is successful, null pointer is returned,
* otherwise a pointer to a C-string containing the error message will be returned.
* The returned C-string must be freed with `cozo_free_str`.
*/
char *cozo_open_db(const char *engine, const char *path, const char *options, int32_t *db_id);
/**
* Close a database.
*
* `id`: the ID representing the database to close.
*
* Returns `true` if the database is closed,
* `false` if it has already been closed, or does not exist.
*/
bool cozo_close_db(int32_t id);
/**
* Run query against a database.
*
* `db_id`: the ID representing the database to run the query.
* `script_raw`: a UTF-8 encoded C-string for the CozoScript to execute.
* `params_raw`: a UTF-8 encoded C-string for the params of the query,
* in JSON format. You must always pass in a valid JSON map,
* even if you do not use params in your query
* (pass "{}" in this case).
* `errored`: will point to `false` if the query is successful,
* `true` if an error occurred.
*
* Returns a UTF-8-encoded C-string that **must** be freed with `cozo_free_str`.
* The string contains the JSON return value of the query.
*/
char *cozo_run_query(int32_t db_id, const char *script_raw, const char *params_raw);
/**
* Import data into relations
*
* `db_id`: the ID representing the database.
* `json_payload`: a UTF-8 encoded JSON payload, in the same form as returned by exporting relations.
*
* Returns a UTF-8-encoded C-string indicating the result that **must** be freed with `cozo_free_str`.
*/
char *cozo_import_relations(int32_t db_id,
const char *json_payload);
/**
* Export relations into JSON
*
* `db_id`: the ID representing the database.
* `json_payload`: a UTF-8 encoded JSON payload, see the manual for the expected fields.
*
* Returns a UTF-8-encoded C-string indicating the result that **must** be freed with `cozo_free_str`.
*/
char *cozo_export_relations(int32_t db_id,
const char *json_payload);
/**
* Backup the database.
*
* `db_id`: the ID representing the database.
* `out_path`: path of the output file.
*
* Returns a UTF-8-encoded C-string indicating the result that **must** be freed with `cozo_free_str`.
*/
char *cozo_backup(int32_t db_id,
const char *out_path);
/**
* Restore the database from a backup.
*
* `db_id`: the ID representing the database.
* `in_path`: path of the input file.
*
* Returns a UTF-8-encoded C-string indicating the result that **must** be freed with `cozo_free_str`.
*/
char *cozo_restore(int32_t db_id,
const char *in_path);
/**
* Import data into relations from a backup
*
* `db_id`: the ID representing the database.
* `json_payload`: a UTF-8 encoded JSON payload: `{"path": ..., "relations": [...]}`
*
* Returns a UTF-8-encoded C-string indicating the result that **must** be freed with `cozo_free_str`.
*/
char *cozo_import_from_backup(int32_t db_id,
const char *json_payload);
/**
* Free any C-string returned from the Cozo C API.
* Must be called exactly once for each returned C-string.
*
* `s`: the C-string to free.
*/
void cozo_free_str(char *s);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif /* COZO_C_H */