Lbug C API
Loading...
Searching...
No Matches
lbug.h
Go to the documentation of this file.
1#pragma once
2#include <stdbool.h>
3#include <stdint.h>
4#include <time.h>
5#ifdef _WIN32
6#include <windows.h>
7#endif
8
9/* Export header from common/api.h */
10// Helpers
11#if defined _WIN32 || defined __CYGWIN__
12#define LBUG_HELPER_DLL_IMPORT __declspec(dllimport)
13#define LBUG_HELPER_DLL_EXPORT __declspec(dllexport)
14#define LBUG_HELPER_DLL_LOCAL
15#define LBUG_HELPER_DEPRECATED __declspec(deprecated)
16#else
17#define LBUG_HELPER_DLL_IMPORT __attribute__((visibility("default")))
18#define LBUG_HELPER_DLL_EXPORT __attribute__((visibility("default")))
19#define LBUG_HELPER_DLL_LOCAL __attribute__((visibility("hidden")))
20#define LBUG_HELPER_DEPRECATED __attribute__((__deprecated__))
21#endif
22
23#ifdef LBUG_STATIC_DEFINE
24#define LBUG_API
25#define LBUG_NO_EXPORT
26#else
27#ifndef LBUG_API
28#ifdef LBUG_EXPORTS
29/* We are building this library */
30#define LBUG_API LBUG_HELPER_DLL_EXPORT
31#else
32/* We are using this library */
33#define LBUG_API LBUG_HELPER_DLL_IMPORT
34#endif
35#endif
36
37#endif
38
39#ifndef LBUG_DEPRECATED
40#define LBUG_DEPRECATED LBUG_HELPER_DEPRECATED
41#endif
42
43#ifndef LBUG_DEPRECATED_EXPORT
44#define LBUG_DEPRECATED_EXPORT LBUG_API LBUG_DEPRECATED
45#endif
46/* end export header */
47
48// The Arrow C data interface.
49// https://arrow.apache.org/docs/format/CDataInterface.html
50
51#include <stdint.h>
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57#ifndef ARROW_C_DATA_INTERFACE
58#define ARROW_C_DATA_INTERFACE
59
60#define ARROW_FLAG_DICTIONARY_ORDERED 1
61#define ARROW_FLAG_NULLABLE 2
62#define ARROW_FLAG_MAP_KEYS_SORTED 4
63
65 // Array type description
66 const char* format;
67 const char* name;
68 const char* metadata;
69 int64_t flags;
70 int64_t n_children;
73
74 // Release callback
75 void (*release)(struct ArrowSchema*);
76 // Opaque producer-specific data
78};
79
80struct ArrowArray {
81 // Array data description
82 int64_t length;
83 int64_t null_count;
84 int64_t offset;
85 int64_t n_buffers;
86 int64_t n_children;
87 const void** buffers;
90
91 // Release callback
92 void (*release)(struct ArrowArray*);
93 // Opaque producer-specific data
95};
96
97#endif // ARROW_C_DATA_INTERFACE
98
99#ifdef __cplusplus
100}
101#endif
102
103#ifdef __cplusplus
104#define LBUG_C_API extern "C" LBUG_API
105#else
106#define LBUG_C_API LBUG_API
107#endif
108
112typedef struct {
113 // bufferPoolSize Max size of the buffer pool in bytes.
114 // The larger the buffer pool, the more data from the database files is kept in memory,
115 // reducing the amount of File I/O
117 // The maximum number of threads to use during query execution
119 // Whether or not to compress data on-disk for supported types
121 // If true, open the database in read-only mode. No write transaction is allowed on the Database
122 // object. If false, open the database read-write.
124 // The maximum size of the database in bytes. Note that this is introduced temporarily for now
125 // to get around with the default 8TB mmap address space limit under some environment. This
126 // will be removed once we implemente a better solution later. The value is default to 1 << 43
127 // (8TB) under 64-bit environment and 1GB under 32-bit one (see `DEFAULT_VM_REGION_MAX_SIZE`).
128 uint64_t max_db_size;
129 // If true, the database will automatically checkpoint when the size of
130 // the WAL file exceeds the checkpoint threshold.
132 // The threshold of the WAL file size in bytes. When the size of the
133 // WAL file exceeds this threshold, the database will checkpoint if auto_checkpoint is true.
135
136#if defined(__APPLE__)
137 // The thread quality of service (QoS) for the worker threads.
138 // This works for Swift bindings on Apple platforms only.
139 uint32_t thread_qos;
140#endif
142
146typedef struct {
149
155typedef struct {
158
167
171typedef struct {
175
179typedef struct {
183
187typedef struct {
190
194typedef struct {
195 void* _value;
197} lbug_value;
198
202typedef struct {
203 uint64_t table_id;
204 uint64_t offset;
206
210typedef struct {
211 // Days since 1970-01-01 00:00:00 UTC.
212 int32_t days;
214
219typedef struct {
220 // Nanoseconds since 1970-01-01 00:00:00 UTC.
221 int64_t value;
223
228typedef struct {
229 // Milliseconds since 1970-01-01 00:00:00 UTC.
230 int64_t value;
232
237typedef struct {
238 // Seconds since 1970-01-01 00:00:00 UTC.
239 int64_t value;
241
246typedef struct {
247 // Microseconds since 1970-01-01 00:00:00 UTC.
248 int64_t value;
250
255typedef struct {
256 // Microseconds since 1970-01-01 00:00:00 UTC.
257 int64_t value;
259
263typedef struct {
264 int32_t months;
265 int32_t days;
266 int64_t micros;
268
273typedef struct {
276
277typedef struct {
278 uint64_t low;
279 int64_t high;
281
285typedef enum {
290 // SERIAL is a special data type that is used to represent a sequence of INT64 values that are
291 // incremented by 1 starting from 0.
293 // fixed size types
315 // variable size types
326
330typedef enum { LbugSuccess = 0, LbugError = 1 } lbug_state;
331
332// Database
342LBUG_C_API lbug_state lbug_database_init(const char* database_path,
343 lbug_system_config system_config, lbug_database* out_database);
349
351
352// Connection
361 lbug_connection* out_connection);
374 uint64_t num_threads);
375
384 uint64_t* out_result);
393 lbug_query_result* out_query_result);
402 lbug_prepared_statement* out_prepared_statement);
411 lbug_prepared_statement* prepared_statement, lbug_query_result* out_query_result);
424 uint64_t timeout_in_ms);
425
426// PreparedStatement
444 lbug_prepared_statement* prepared_statement);
453 const char* param_name, bool value);
462 lbug_prepared_statement* prepared_statement, const char* param_name, int64_t value);
471 lbug_prepared_statement* prepared_statement, const char* param_name, int32_t value);
480 lbug_prepared_statement* prepared_statement, const char* param_name, int16_t value);
489 const char* param_name, int8_t value);
498 lbug_prepared_statement* prepared_statement, const char* param_name, uint64_t value);
507 lbug_prepared_statement* prepared_statement, const char* param_name, uint32_t value);
516 lbug_prepared_statement* prepared_statement, const char* param_name, uint16_t value);
525 lbug_prepared_statement* prepared_statement, const char* param_name, uint8_t value);
526
535 lbug_prepared_statement* prepared_statement, const char* param_name, double value);
544 lbug_prepared_statement* prepared_statement, const char* param_name, float value);
553 const char* param_name, lbug_date_t value);
562 lbug_prepared_statement* prepared_statement, const char* param_name, lbug_timestamp_ns_t value);
571 lbug_prepared_statement* prepared_statement, const char* param_name,
581 lbug_prepared_statement* prepared_statement, const char* param_name, lbug_timestamp_tz_t value);
590 lbug_prepared_statement* prepared_statement, const char* param_name, lbug_timestamp_ms_t value);
599 lbug_prepared_statement* prepared_statement, const char* param_name, lbug_timestamp_t value);
608 lbug_prepared_statement* prepared_statement, const char* param_name, lbug_interval_t value);
617 lbug_prepared_statement* prepared_statement, const char* param_name, const char* value);
626 lbug_prepared_statement* prepared_statement, const char* param_name, lbug_value* value);
627
628// QueryResult
659 uint64_t index, char** out_column_name);
668 uint64_t index, lbug_logical_type* out_column_data_type);
681 lbug_query_summary* out_query_summary);
697 lbug_flat_tuple* out_flat_tuple);
712 lbug_query_result* out_next_query_result);
713
725
736 struct ArrowSchema* out_schema);
737
750 int64_t chunk_size, struct ArrowArray* out_arrow_array);
751
752// FlatTuple
766 lbug_value* out_value);
773
774// DataType
775// TODO(Chang): Refactor the datatype constructor to follow the cpp way of creating dataTypes.
786 uint64_t num_elements_in_array, lbug_logical_type* out_type);
817 uint64_t* out_result);
818
819// Value
840LBUG_C_API void lbug_value_set_null(lbug_value* value, bool is_null);
984LBUG_C_API lbug_state lbug_value_create_list(uint64_t num_elements, lbug_value** elements,
985 lbug_value** out_value);
998LBUG_C_API lbug_state lbug_value_create_struct(uint64_t num_fields, const char** field_names,
999 lbug_value** field_values, lbug_value** out_value);
1013 lbug_value** values, lbug_value** out_value);
1047 lbug_value* out_value);
1064 char** out_result);
1074 lbug_value* out_value);
1075
1092 lbug_value* out_key);
1102 lbug_value* out_value);
1111 lbug_value* out_value);
1112
1120 lbug_value* out_value);
1253 lbug_timestamp_ns_t* out_result);
1261 lbug_timestamp_ms_t* out_result);
1270 lbug_timestamp_sec_t* out_result);
1278 lbug_timestamp_tz_t* out_result);
1352 char** out_result);
1361 lbug_value* out_value);
1413 char** out_result);
1422 lbug_value* out_value);
1444LBUG_C_API void lbug_destroy_blob(uint8_t* blob);
1445
1446// QuerySummary
1462
1463// Utility functions
1485 struct tm* out_result);
1568LBUG_C_API void lbug_interval_to_difftime(lbug_interval_t interval, double* out_result);
1574LBUG_C_API void lbug_interval_from_difftime(double difftime, lbug_interval_t* out_result);
1575
1576// Version
1581
1586#undef LBUG_C_API
LBUG_C_API lbug_state lbug_rel_val_get_label_val(lbug_value *rel_val, lbug_value *out_value)
Returns the label value of the given rel value.
LBUG_C_API char * lbug_query_result_get_error_message(lbug_query_result *query_result)
Returns the error message if the query is failed. The caller is responsible for freeing the returned ...
LBUG_C_API lbug_state lbug_prepared_statement_bind_double(lbug_prepared_statement *prepared_statement, const char *param_name, double value)
Binds the given double value to the given parameter name in the prepared statement.
LBUG_C_API void lbug_interval_from_difftime(double difftime, lbug_interval_t *out_result)
Convert difftime value in seconds to interval.
LBUG_C_API lbug_state lbug_value_get_struct_field_name(lbug_value *value, uint64_t index, char **out_result)
Returns the field name at index of the given struct value. The value must be of physical type STRUCT ...
LBUG_C_API lbug_state lbug_value_get_string(lbug_value *value, char **out_result)
Returns the string value of the given value. The value must be of type STRING.
LBUG_C_API lbug_state lbug_value_get_timestamp_sec(lbug_value *value, lbug_timestamp_sec_t *out_result)
Returns the timestamp_sec value of the given value. The value must be of type TIMESTAMP_SEC.
LBUG_C_API lbug_state lbug_query_result_get_next_query_result(lbug_query_result *query_result, lbug_query_result *out_next_query_result)
Returns the next query result. Use this function to loop multiple query statements' results.
LBUG_C_API lbug_state lbug_value_get_list_element(lbug_value *value, uint64_t index, lbug_value *out_value)
Returns the element at index of the given value. The value must be of type LIST.
LBUG_C_API lbug_system_config lbug_default_system_config()
LBUG_C_API lbug_state lbug_value_get_float(lbug_value *value, float *out_result)
Returns the float value of the given value. The value must be of type FLOAT.
LBUG_C_API lbug_state lbug_timestamp_tz_from_tm(struct tm tm, lbug_timestamp_tz_t *out_result)
Convert tm struct to timestamp_tz value.
LBUG_C_API lbug_state lbug_query_result_get_column_name(lbug_query_result *query_result, uint64_t index, char **out_column_name)
Returns the column name at the given index.
LBUG_C_API lbug_state lbug_value_get_int16(lbug_value *value, int16_t *out_result)
Returns the int16 value of the given value. The value must be of type INT16.
LBUG_C_API lbug_state lbug_timestamp_ms_from_tm(struct tm tm, lbug_timestamp_ms_t *out_result)
Convert tm struct to timestamp_ms value.
LBUG_C_API void lbug_query_result_destroy(lbug_query_result *query_result)
Destroys the given query result instance.
LBUG_C_API lbug_value * lbug_value_create_uint32(uint32_t val_)
Creates a value with uint32 type and the given uint32 value. Caller is responsible for destroying the...
LBUG_C_API uint64_t lbug_get_storage_version()
Returns the storage version of the Lbug library.
LBUG_C_API lbug_state lbug_value_get_uuid(lbug_value *value, char **out_result)
Returns the uuid value of the given value. to a string. The value must be of type UUID.
LBUG_C_API lbug_state lbug_date_to_string(lbug_date_t date, char **out_result)
Convert date to corresponding string.
lbug_state
enum class for lbug function return state.
Definition lbug.h:330
@ LbugError
Definition lbug.h:330
@ LbugSuccess
Definition lbug.h:330
LBUG_C_API lbug_state lbug_prepared_statement_bind_interval(lbug_prepared_statement *prepared_statement, const char *param_name, lbug_interval_t value)
Binds the given interval value to the given parameter name in the prepared statement.
LBUG_C_API lbug_value * lbug_value_clone(lbug_value *value)
Creates a new value based on the given value. Caller is responsible for destroying the returned value...
LBUG_C_API char * lbug_prepared_statement_get_error_message(lbug_prepared_statement *prepared_statement)
Returns the error message if the prepared statement is not prepared successfully. The caller is respo...
LBUG_C_API lbug_state lbug_timestamp_tz_to_tm(lbug_timestamp_tz_t timestamp, struct tm *out_result)
Convert timestamp_tz to corresponding tm struct.
LBUG_C_API bool lbug_query_result_has_next(lbug_query_result *query_result)
Returns true if we have not consumed all tuples in the query result, false otherwise.
LBUG_C_API bool lbug_query_result_is_success(lbug_query_result *query_result)
Returns true if the query is executed successful, false otherwise.
LBUG_C_API lbug_state lbug_timestamp_from_tm(struct tm tm, lbug_timestamp_t *out_result)
Convert timestamp_ns to corresponding string.
LBUG_C_API void lbug_prepared_statement_destroy(lbug_prepared_statement *prepared_statement)
Destroys the prepared statement instance and frees the allocated memory.
LBUG_C_API char * lbug_query_result_to_string(lbug_query_result *query_result)
Returns the query result as a string.
LBUG_C_API lbug_state lbug_prepared_statement_bind_int32(lbug_prepared_statement *prepared_statement, const char *param_name, int32_t value)
Binds the given int32_t value to the given parameter name in the prepared statement.
LBUG_C_API lbug_state lbug_prepared_statement_bind_float(lbug_prepared_statement *prepared_statement, const char *param_name, float value)
Binds the given float value to the given parameter name in the prepared statement.
LBUG_C_API lbug_state lbug_value_get_struct_field_value(lbug_value *value, uint64_t index, lbug_value *out_value)
Returns the field value at index of the given struct value. The value must be of physical type STRUCT...
LBUG_C_API void lbug_database_destroy(lbug_database *database)
Destroys the lbug database instance and frees the allocated memory.
LBUG_C_API lbug_value * lbug_value_create_null_with_data_type(lbug_logical_type *data_type)
Creates a value of the given data type. Caller is responsible for destroying the returned value.
LBUG_C_API uint64_t lbug_query_result_get_num_tuples(lbug_query_result *query_result)
Returns the number of tuples in the query result.
LBUG_C_API lbug_state lbug_node_val_to_string(lbug_value *node_val, char **out_result)
Converts the given node value to string.
LBUG_C_API lbug_value * lbug_value_create_int8(int8_t val_)
Creates a value with int8 type and the given int8 value. Caller is responsible for destroying the ret...
LBUG_C_API lbug_state lbug_value_get_timestamp_tz(lbug_value *value, lbug_timestamp_tz_t *out_result)
Returns the timestamp_tz value of the given value. The value must be of type TIMESTAMP_TZ.
LBUG_C_API lbug_state lbug_connection_execute(lbug_connection *connection, lbug_prepared_statement *prepared_statement, lbug_query_result *out_query_result)
Executes the prepared_statement using connection.
LBUG_C_API bool lbug_data_type_equals(lbug_logical_type *data_type1, lbug_logical_type *data_type2)
Returns true if the given data type is equal to the other data type, false otherwise.
LBUG_C_API lbug_value * lbug_value_create_int128(lbug_int128_t val_)
Creates a value with int128 type and the given int128 value. Caller is responsible for destroying the...
LBUG_C_API lbug_state lbug_prepared_statement_bind_bool(lbug_prepared_statement *prepared_statement, const char *param_name, bool value)
Binds the given boolean value to the given parameter name in the prepared statement.
LBUG_C_API bool lbug_value_is_null(lbug_value *value)
Returns true if the given value is NULL, false otherwise.
LBUG_C_API lbug_state lbug_prepared_statement_bind_timestamp_ms(lbug_prepared_statement *prepared_statement, const char *param_name, lbug_timestamp_ms_t value)
Binds the given timestamp_ms value to the given parameter name in the prepared statement.
LBUG_C_API void lbug_query_result_reset_iterator(lbug_query_result *query_result)
Resets the iterator of the query result to the beginning of the query result.
LBUG_C_API bool lbug_query_result_has_next_query_result(lbug_query_result *query_result)
Returns true if we have not consumed all query results, false otherwise. Use this function for loop r...
LBUG_C_API lbug_value * lbug_value_create_timestamp(lbug_timestamp_t val_)
Creates a value with timestamp type and the given timestamp value. Caller is responsible for destroyi...
LBUG_C_API lbug_state lbug_data_type_get_num_elements_in_array(lbug_logical_type *data_type, uint64_t *out_result)
Returns the number of elements for array.
LBUG_C_API lbug_state lbug_node_val_get_property_name_at(lbug_value *node_val, uint64_t index, char **out_result)
Returns the property name of the given node value at the given index.
LBUG_C_API lbug_value * lbug_value_create_internal_id(lbug_internal_id_t val_)
Creates a value with internal_id type and the given internal_id value. Caller is responsible for dest...
LBUG_C_API lbug_state lbug_value_get_struct_num_fields(lbug_value *value, uint64_t *out_result)
Returns the number of fields of the given struct value. The value must be of type STRUCT.
LBUG_C_API lbug_state lbug_node_val_get_property_size(lbug_value *node_val, uint64_t *out_value)
Returns the number of properties of the given node value.
LBUG_C_API lbug_state lbug_value_get_int32(lbug_value *value, int32_t *out_result)
Returns the int32 value of the given value. The value must be of type INT32.
LBUG_C_API lbug_state lbug_value_get_uint32(lbug_value *value, uint32_t *out_result)
Returns the uint32 value of the given value. The value must be of type UINT32.
LBUG_C_API lbug_value * lbug_value_create_interval(lbug_interval_t val_)
Creates a value with interval type and the given interval value. Caller is responsible for destroying...
LBUG_C_API lbug_state lbug_value_get_timestamp_ns(lbug_value *value, lbug_timestamp_ns_t *out_result)
Returns the timestamp_ns value of the given value. The value must be of type TIMESTAMP_NS.
LBUG_C_API bool lbug_prepared_statement_is_success(lbug_prepared_statement *prepared_statement)
LBUG_C_API lbug_state lbug_prepared_statement_bind_timestamp(lbug_prepared_statement *prepared_statement, const char *param_name, lbug_timestamp_t value)
Binds the given timestamp value to the given parameter name in the prepared statement.
LBUG_C_API lbug_state lbug_node_val_get_id_val(lbug_value *node_val, lbug_value *out_value)
Returns the internal id value of the given node value as a lbug value.
LBUG_C_API lbug_state lbug_value_get_internal_id(lbug_value *value, lbug_internal_id_t *out_result)
Returns the internal id value of the given value. The value must be of type INTERNAL_ID.
lbug_data_type_id
enum class for lbug internal dataTypes.
Definition lbug.h:285
@ LBUG_UINT8
Definition lbug.h:302
@ LBUG_INT16
Definition lbug.h:297
@ LBUG_INTERNAL_ID
Definition lbug.h:314
@ LBUG_LIST
Definition lbug.h:318
@ LBUG_TIMESTAMP_MS
Definition lbug.h:309
@ LBUG_MAP
Definition lbug.h:321
@ LBUG_INT128
Definition lbug.h:303
@ LBUG_ANY
Definition lbug.h:286
@ LBUG_UNION
Definition lbug.h:322
@ LBUG_INT64
Definition lbug.h:295
@ LBUG_INT32
Definition lbug.h:296
@ LBUG_UINT64
Definition lbug.h:299
@ LBUG_BLOB
Definition lbug.h:317
@ LBUG_STRUCT
Definition lbug.h:320
@ LBUG_POINTER
Definition lbug.h:323
@ LBUG_DOUBLE
Definition lbug.h:304
@ LBUG_INTERVAL
Definition lbug.h:312
@ LBUG_NODE
Definition lbug.h:287
@ LBUG_UINT32
Definition lbug.h:300
@ LBUG_SERIAL
Definition lbug.h:292
@ LBUG_FLOAT
Definition lbug.h:305
@ LBUG_TIMESTAMP
Definition lbug.h:307
@ LBUG_DATE
Definition lbug.h:306
@ LBUG_INT8
Definition lbug.h:298
@ LBUG_BOOL
Definition lbug.h:294
@ LBUG_DECIMAL
Definition lbug.h:313
@ LBUG_TIMESTAMP_SEC
Definition lbug.h:308
@ LBUG_ARRAY
Definition lbug.h:319
@ LBUG_REL
Definition lbug.h:288
@ LBUG_RECURSIVE_REL
Definition lbug.h:289
@ LBUG_STRING
Definition lbug.h:316
@ LBUG_UINT16
Definition lbug.h:301
@ LBUG_TIMESTAMP_TZ
Definition lbug.h:311
@ LBUG_UUID
Definition lbug.h:324
@ LBUG_TIMESTAMP_NS
Definition lbug.h:310
LBUG_C_API lbug_state lbug_timestamp_ns_from_tm(struct tm tm, lbug_timestamp_ns_t *out_result)
Convert tm struct to timestamp_ns value.
LBUG_C_API lbug_state lbug_timestamp_sec_from_tm(struct tm tm, lbug_timestamp_sec_t *out_result)
Convert tm struct to timestamp_sec value.
LBUG_C_API lbug_state lbug_value_get_blob(lbug_value *value, uint8_t **out_result)
Returns the blob value of the given value. The returned buffer is null-terminated similar to a string...
LBUG_C_API lbug_state lbug_prepared_statement_bind_timestamp_tz(lbug_prepared_statement *prepared_statement, const char *param_name, lbug_timestamp_tz_t value)
Binds the given timestamp_tz value to the given parameter name in the prepared statement.
LBUG_C_API lbug_state lbug_value_get_int8(lbug_value *value, int8_t *out_result)
Returns the int8 value of the given value. The value must be of type INT8.
LBUG_C_API lbug_state lbug_value_get_recursive_rel_node_list(lbug_value *value, lbug_value *out_value)
Returns the list of nodes for recursive rel value. The value must be of type RECURSIVE_REL.
LBUG_C_API lbug_state lbug_query_result_get_query_summary(lbug_query_result *query_result, lbug_query_summary *out_query_summary)
Returns the query summary of the query result.
LBUG_C_API lbug_state lbug_prepared_statement_bind_timestamp_ns(lbug_prepared_statement *prepared_statement, const char *param_name, lbug_timestamp_ns_t value)
Binds the given timestamp_ns value to the given parameter name in the prepared statement.
LBUG_C_API lbug_state lbug_rel_val_get_property_name_at(lbug_value *rel_val, uint64_t index, char **out_result)
Returns the property name of the given rel value at the given index.
LBUG_C_API lbug_value * lbug_value_create_int32(int32_t val_)
Creates a value with int32 type and the given int32 value. Caller is responsible for destroying the r...
LBUG_C_API lbug_value * lbug_value_create_default(lbug_logical_type *data_type)
Creates a value of the given data type with default non-NULL value. Caller is responsible for destroy...
LBUG_C_API lbug_state lbug_value_get_map_value(lbug_value *value, uint64_t index, lbug_value *out_value)
Returns the field value at index of the given map value. The value must be of physical type MAP.
LBUG_C_API lbug_state lbug_connection_set_query_timeout(lbug_connection *connection, uint64_t timeout_in_ms)
Sets query timeout value in milliseconds for the connection.
LBUG_C_API lbug_state lbug_value_get_list_size(lbug_value *value, uint64_t *out_result)
Returns the number of elements per list of the given value. The value must be of type ARRAY.
LBUG_C_API lbug_state lbug_query_result_get_column_data_type(lbug_query_result *query_result, uint64_t index, lbug_logical_type *out_column_data_type)
Returns the data type of the column at the given index.
LBUG_C_API lbug_state lbug_node_val_get_property_value_at(lbug_value *node_val, uint64_t index, lbug_value *out_value)
Returns the property value of the given node value at the given index.
LBUG_C_API lbug_state lbug_value_get_date(lbug_value *value, lbug_date_t *out_result)
Returns the date value of the given value. The value must be of type DATE.
LBUG_C_API lbug_state lbug_value_create_list(uint64_t num_elements, lbug_value **elements, lbug_value **out_value)
Creates a list value with the given number of elements and the given elements. The caller needs to ma...
LBUG_C_API lbug_state lbug_prepared_statement_bind_date(lbug_prepared_statement *prepared_statement, const char *param_name, lbug_date_t value)
Binds the given date value to the given parameter name in the prepared statement.
LBUG_C_API lbug_state lbug_prepared_statement_bind_timestamp_sec(lbug_prepared_statement *prepared_statement, const char *param_name, lbug_timestamp_sec_t value)
Binds the given timestamp_sec value to the given parameter name in the prepared statement.
LBUG_C_API lbug_state lbug_value_get_interval(lbug_value *value, lbug_interval_t *out_result)
Returns the interval value of the given value. The value must be of type INTERVAL.
LBUG_C_API lbug_state lbug_query_result_get_arrow_schema(lbug_query_result *query_result, struct ArrowSchema *out_schema)
Returns the query result's schema as ArrowSchema.
LBUG_C_API void lbug_data_type_destroy(lbug_logical_type *data_type)
Destroys the given data type instance.
LBUG_C_API lbug_state lbug_date_to_tm(lbug_date_t date, struct tm *out_result)
Convert date to corresponding tm struct.
LBUG_C_API lbug_state lbug_flat_tuple_get_value(lbug_flat_tuple *flat_tuple, uint64_t index, lbug_value *out_value)
Returns the value at index of the flat tuple.
LBUG_C_API void lbug_flat_tuple_destroy(lbug_flat_tuple *flat_tuple)
Destroys the given flat tuple instance.
LBUG_C_API lbug_value * lbug_value_create_timestamp_ms(lbug_timestamp_ms_t val_)
Creates a value with timestamp_ms type and the given timestamp value. Caller is responsible for destr...
LBUG_C_API lbug_state lbug_prepared_statement_bind_uint32(lbug_prepared_statement *prepared_statement, const char *param_name, uint32_t value)
Binds the given uint32_t value to the given parameter name in the prepared statement.
LBUG_C_API lbug_value * lbug_value_create_double(double val_)
Creates a value with double type and the given double value. Caller is responsible for destroying the...
LBUG_C_API lbug_state lbug_connection_query(lbug_connection *connection, const char *query, lbug_query_result *out_query_result)
Executes the given query and returns the result.
LBUG_C_API void lbug_value_get_data_type(lbug_value *value, lbug_logical_type *out_type)
Returns internal type of the given value.
LBUG_C_API void lbug_destroy_string(char *str)
Destroys any string created by the Lbug C API, including both the error message and the values return...
LBUG_C_API lbug_state lbug_connection_get_max_num_thread_for_exec(lbug_connection *connection, uint64_t *out_result)
Returns the maximum number of threads of the connection to use for executing queries.
LBUG_C_API lbug_value * lbug_value_create_bool(bool val_)
Creates a value with boolean type and the given bool value. Caller is responsible for destroying the ...
LBUG_C_API lbug_state lbug_prepared_statement_bind_int64(lbug_prepared_statement *prepared_statement, const char *param_name, int64_t value)
Binds the given int64_t value to the given parameter name in the prepared statement.
LBUG_C_API void lbug_query_summary_destroy(lbug_query_summary *query_summary)
Destroys the given query summary.
LBUG_C_API lbug_state lbug_value_get_int64(lbug_value *value, int64_t *out_result)
Returns the int64 value of the given value. The value must be of type INT64 or SERIAL.
#define LBUG_C_API
Definition lbug.h:106
LBUG_C_API lbug_state lbug_date_from_string(const char *str, lbug_date_t *out_result)
Convert a string to date value.
LBUG_C_API lbug_state lbug_value_create_struct(uint64_t num_fields, const char **field_names, lbug_value **field_values, lbug_value **out_value)
Creates a struct value with the given number of fields and the given field names and values....
LBUG_C_API void lbug_connection_destroy(lbug_connection *connection)
Destroys the connection instance and frees the allocated memory.
LBUG_C_API lbug_state lbug_int128_t_to_string(lbug_int128_t val, char **out_result)
convert int128 to corresponding string.
LBUG_C_API lbug_state lbug_rel_val_get_property_size(lbug_value *rel_val, uint64_t *out_value)
Returns the number of properties of the given rel value.
LBUG_C_API lbug_state lbug_connection_prepare(lbug_connection *connection, const char *query, lbug_prepared_statement *out_prepared_statement)
Prepares the given query and returns the prepared statement.
LBUG_C_API lbug_state lbug_rel_val_get_dst_id_val(lbug_value *rel_val, lbug_value *out_value)
Returns the internal id value of the destination node of the given rel value as a lbug value.
LBUG_C_API lbug_state lbug_rel_val_to_string(lbug_value *rel_val, char **out_result)
Converts the given rel value to string.
LBUG_C_API lbug_state lbug_value_get_timestamp(lbug_value *value, lbug_timestamp_t *out_result)
Returns the timestamp value of the given value. The value must be of type TIMESTAMP.
LBUG_C_API lbug_state lbug_value_get_decimal_as_string(lbug_value *value, char **out_result)
Returns the decimal value of the given value as a string. The value must be of type DECIMAL.
LBUG_C_API lbug_state lbug_date_from_tm(struct tm tm, lbug_date_t *out_result)
Convert tm struct to date value.
LBUG_C_API lbug_state lbug_query_result_get_next(lbug_query_result *query_result, lbug_flat_tuple *out_flat_tuple)
Returns the next tuple in the query result. Throws an exception if there is no more tuple....
LBUG_C_API lbug_state lbug_database_init(const char *database_path, lbug_system_config system_config, lbug_database *out_database)
Allocates memory and creates a lbug database instance at database_path with bufferPoolSize=buffer_poo...
LBUG_C_API void lbug_value_destroy(lbug_value *value)
Destroys the value.
LBUG_C_API void lbug_value_set_null(lbug_value *value, bool is_null)
Sets the given value to NULL or not.
LBUG_C_API lbug_value * lbug_value_create_timestamp_tz(lbug_timestamp_tz_t val_)
Creates a value with timestamp_tz type and the given timestamp value. Caller is responsible for destr...
LBUG_C_API lbug_state lbug_value_get_uint64(lbug_value *value, uint64_t *out_result)
Returns the uint64 value of the given value. The value must be of type UINT64.
LBUG_C_API void lbug_data_type_create(lbug_data_type_id id, lbug_logical_type *child_type, uint64_t num_elements_in_array, lbug_logical_type *out_type)
Creates a data type instance with the given id, childType and num_elements_in_array....
LBUG_C_API lbug_value * lbug_value_create_int64(int64_t val_)
Creates a value with int64 type and the given int64 value. Caller is responsible for destroying the r...
LBUG_C_API lbug_state lbug_int128_t_from_string(const char *str, lbug_int128_t *out_result)
convert a string to int128 value.
LBUG_C_API lbug_state lbug_rel_val_get_src_id_val(lbug_value *rel_val, lbug_value *out_value)
Returns the internal id value of the source node of the given rel value as a lbug value.
LBUG_C_API double lbug_query_summary_get_execution_time(lbug_query_summary *query_summary)
Returns the execution time of the given query summary in milliseconds.
LBUG_C_API uint64_t lbug_query_result_get_num_columns(lbug_query_result *query_result)
Returns the number of columns in the query result.
LBUG_C_API lbug_state lbug_value_get_int128(lbug_value *value, lbug_int128_t *out_result)
Returns the int128 value of the given value. The value must be of type INT128.
LBUG_C_API lbug_state lbug_timestamp_to_tm(lbug_timestamp_t timestamp, struct tm *out_result)
Convert timestamp to corresponding tm struct.
LBUG_C_API lbug_value * lbug_value_create_int16(int16_t val_)
Creates a value with int16 type and the given int16 value. Caller is responsible for destroying the r...
LBUG_C_API lbug_state lbug_rel_val_get_id_val(lbug_value *rel_val, lbug_value *out_value)
Returns the internal id value of the rel value as a lbug value.
LBUG_C_API lbug_state lbug_value_get_double(lbug_value *value, double *out_result)
Returns the double value of the given value. The value must be of type DOUBLE.
LBUG_C_API lbug_state lbug_prepared_statement_bind_uint64(lbug_prepared_statement *prepared_statement, const char *param_name, uint64_t value)
Binds the given uint64_t value to the given parameter name in the prepared statement.
LBUG_C_API lbug_state lbug_value_get_recursive_rel_rel_list(lbug_value *value, lbug_value *out_value)
Returns the list of rels for recursive rel value. The value must be of type RECURSIVE_REL.
LBUG_C_API lbug_state lbug_rel_val_get_property_value_at(lbug_value *rel_val, uint64_t index, lbug_value *out_value)
Returns the property of the given rel value at the given index as lbug value.
LBUG_C_API lbug_value * lbug_value_create_uint8(uint8_t val_)
Creates a value with uint8 type and the given uint8 value. Caller is responsible for destroying the r...
LBUG_C_API lbug_state lbug_value_get_bool(lbug_value *value, bool *out_result)
Returns the boolean value of the given value. The value must be of type BOOL.
LBUG_C_API lbug_state lbug_prepared_statement_bind_value(lbug_prepared_statement *prepared_statement, const char *param_name, lbug_value *value)
Binds the given lbug value to the given parameter name in the prepared statement.
LBUG_C_API lbug_state lbug_value_create_map(uint64_t num_fields, lbug_value **keys, lbug_value **values, lbug_value **out_value)
Creates a map value with the given number of fields and the given keys and values....
LBUG_C_API lbug_value * lbug_value_create_date(lbug_date_t val_)
Creates a value with date type and the given date value. Caller is responsible for destroying the ret...
LBUG_C_API lbug_state lbug_prepared_statement_bind_uint16(lbug_prepared_statement *prepared_statement, const char *param_name, uint16_t value)
Binds the given uint16_t value to the given parameter name in the prepared statement.
LBUG_C_API char * lbug_flat_tuple_to_string(lbug_flat_tuple *flat_tuple)
Converts the flat tuple to a string.
LBUG_C_API void lbug_data_type_clone(lbug_logical_type *data_type, lbug_logical_type *out_type)
Creates a new data type instance by cloning the given data type instance.
LBUG_C_API lbug_state lbug_prepared_statement_bind_int16(lbug_prepared_statement *prepared_statement, const char *param_name, int16_t value)
Binds the given int16_t value to the given parameter name in the prepared statement.
LBUG_C_API lbug_value * lbug_value_create_string(const char *val_)
Creates a value with string type and the given string value. Caller is responsible for destroying the...
LBUG_C_API lbug_state lbug_value_get_uint8(lbug_value *value, uint8_t *out_result)
Returns the uint8 value of the given value. The value must be of type UINT8.
LBUG_C_API void lbug_connection_interrupt(lbug_connection *connection)
Interrupts the current query execution in the connection.
LBUG_C_API lbug_state lbug_value_get_timestamp_ms(lbug_value *value, lbug_timestamp_ms_t *out_result)
Returns the timestamp_ms value of the given value. The value must be of type TIMESTAMP_MS.
LBUG_C_API lbug_value * lbug_value_create_uint16(uint16_t val_)
Creates a value with uint16 type and the given uint16 value. Caller is responsible for destroying the...
LBUG_C_API lbug_state lbug_node_val_get_label_val(lbug_value *node_val, lbug_value *out_value)
Returns the label value of the given node value as a label value.
LBUG_C_API lbug_data_type_id lbug_data_type_get_id(lbug_logical_type *data_type)
Returns the enum type id of the given data type.
LBUG_C_API double lbug_query_summary_get_compiling_time(lbug_query_summary *query_summary)
Returns the compilation time of the given query summary in milliseconds.
LBUG_C_API void lbug_value_copy(lbug_value *value, lbug_value *other)
Copies the other value to the value.
LBUG_C_API lbug_state lbug_prepared_statement_bind_uint8(lbug_prepared_statement *prepared_statement, const char *param_name, uint8_t value)
Binds the given int8_t value to the given parameter name in the prepared statement.
LBUG_C_API lbug_value * lbug_value_create_uint64(uint64_t val_)
Creates a value with uint64 type and the given uint64 value. Caller is responsible for destroying the...
LBUG_C_API lbug_state lbug_timestamp_ns_to_tm(lbug_timestamp_ns_t timestamp, struct tm *out_result)
Convert timestamp_ns to corresponding tm struct.
LBUG_C_API void lbug_interval_to_difftime(lbug_interval_t interval, double *out_result)
Convert interval to corresponding difftime value in seconds.
LBUG_C_API lbug_state lbug_prepared_statement_bind_string(lbug_prepared_statement *prepared_statement, const char *param_name, const char *value)
Binds the given string value to the given parameter name in the prepared statement.
LBUG_C_API lbug_value * lbug_value_create_float(float val_)
Creates a value with float type and the given float value. Caller is responsible for destroying the r...
LBUG_C_API lbug_state lbug_value_get_map_key(lbug_value *value, uint64_t index, lbug_value *out_key)
Returns the key at index of the given map value. The value must be of physical type MAP.
LBUG_C_API lbug_state lbug_connection_set_max_num_thread_for_exec(lbug_connection *connection, uint64_t num_threads)
Sets the maximum number of threads to use for executing queries.
LBUG_C_API lbug_state lbug_value_get_uint16(lbug_value *value, uint16_t *out_result)
Returns the uint16 value of the given value. The value must be of type UINT16.
LBUG_C_API lbug_state lbug_connection_init(lbug_database *database, lbug_connection *out_connection)
Allocates memory and creates a connection to the database. Caller is responsible for calling lbug_con...
LBUG_C_API lbug_state lbug_query_result_get_next_arrow_chunk(lbug_query_result *query_result, int64_t chunk_size, struct ArrowArray *out_arrow_array)
Returns the next chunk of the query result as ArrowArray.
LBUG_C_API lbug_state lbug_prepared_statement_bind_int8(lbug_prepared_statement *prepared_statement, const char *param_name, int8_t value)
Binds the given int8_t value to the given parameter name in the prepared statement.
LBUG_C_API lbug_value * lbug_value_create_null()
Creates a NULL value of ANY type. Caller is responsible for destroying the returned value.
LBUG_C_API lbug_value * lbug_value_create_timestamp_sec(lbug_timestamp_sec_t val_)
Creates a value with timestamp_sec type and the given timestamp value. Caller is responsible for dest...
LBUG_C_API lbug_state lbug_timestamp_sec_to_tm(lbug_timestamp_sec_t timestamp, struct tm *out_result)
Convert timestamp_sec to corresponding tm struct.
LBUG_C_API char * lbug_get_version()
Returns the version of the Lbug library.
LBUG_C_API char * lbug_value_to_string(lbug_value *value)
Converts the given value to string.
LBUG_C_API lbug_state lbug_value_get_map_size(lbug_value *value, uint64_t *out_result)
Returns the size of the given map value. The value must be of type MAP.
LBUG_C_API lbug_state lbug_timestamp_ms_to_tm(lbug_timestamp_ms_t timestamp, struct tm *out_result)
Convert timestamp_ms to corresponding tm struct.
LBUG_C_API lbug_value * lbug_value_create_timestamp_ns(lbug_timestamp_ns_t val_)
Creates a value with timestamp_ns type and the given timestamp value. Caller is responsible for destr...
LBUG_C_API void lbug_destroy_blob(uint8_t *blob)
Destroys any blob created by the Lbug C API. This function is provided to avoid the inconsistency bet...
Definition lbug.h:80
void(* release)(struct ArrowArray *)
Definition lbug.h:92
void * private_data
Definition lbug.h:94
int64_t n_children
Definition lbug.h:86
int64_t null_count
Definition lbug.h:83
struct ArrowArray ** children
Definition lbug.h:88
int64_t offset
Definition lbug.h:84
struct ArrowArray * dictionary
Definition lbug.h:89
const void ** buffers
Definition lbug.h:87
int64_t n_buffers
Definition lbug.h:85
int64_t length
Definition lbug.h:82
Definition lbug.h:64
int64_t flags
Definition lbug.h:69
const char * metadata
Definition lbug.h:68
int64_t n_children
Definition lbug.h:70
const char * name
Definition lbug.h:67
void * private_data
Definition lbug.h:77
const char * format
Definition lbug.h:66
struct ArrowSchema * dictionary
Definition lbug.h:72
void(* release)(struct ArrowSchema *)
Definition lbug.h:75
struct ArrowSchema ** children
Definition lbug.h:71
lbug_connection is used to interact with a Database instance. Each connection is thread-safe....
Definition lbug.h:155
void * _connection
Definition lbug.h:156
lbug_database manages all database components.
Definition lbug.h:146
void * _database
Definition lbug.h:147
lbug internal date type which stores the number of days since 1970-01-01 00:00:00 UTC.
Definition lbug.h:210
int32_t days
Definition lbug.h:212
lbug_flat_tuple stores a vector of values.
Definition lbug.h:179
bool _is_owned_by_cpp
Definition lbug.h:181
void * _flat_tuple
Definition lbug.h:180
Definition lbug.h:277
uint64_t low
Definition lbug.h:278
int64_t high
Definition lbug.h:279
lbug internal internal_id type which stores the table_id and offset of a node/rel.
Definition lbug.h:202
uint64_t offset
Definition lbug.h:204
uint64_t table_id
Definition lbug.h:203
lbug internal interval type which stores the months, days and microseconds.
Definition lbug.h:263
int64_t micros
Definition lbug.h:266
int32_t days
Definition lbug.h:265
int32_t months
Definition lbug.h:264
lbug_logical_type is the lbug internal representation of data types.
Definition lbug.h:187
void * _data_type
Definition lbug.h:188
lbug_prepared_statement is a parameterized query which can avoid planning the same query for repeated...
Definition lbug.h:163
void * _bound_values
Definition lbug.h:165
void * _prepared_statement
Definition lbug.h:164
lbug_query_result stores the result of a query.
Definition lbug.h:171
bool _is_owned_by_cpp
Definition lbug.h:173
void * _query_result
Definition lbug.h:172
lbug_query_summary stores the execution time, plan, compiling time and query options of a query.
Definition lbug.h:273
void * _query_summary
Definition lbug.h:274
Stores runtime configuration for creating or opening a Database.
Definition lbug.h:112
bool read_only
Definition lbug.h:123
uint64_t checkpoint_threshold
Definition lbug.h:134
bool auto_checkpoint
Definition lbug.h:131
uint64_t buffer_pool_size
Definition lbug.h:116
bool enable_compression
Definition lbug.h:120
uint64_t max_num_threads
Definition lbug.h:118
uint64_t max_db_size
Definition lbug.h:128
lbug internal timestamp_ms type which stores the number of milliseconds since 1970-01-01 00:00:00 UTC...
Definition lbug.h:228
int64_t value
Definition lbug.h:230
lbug internal timestamp_ns type which stores the number of nanoseconds since 1970-01-01 00:00:00 UTC.
Definition lbug.h:219
int64_t value
Definition lbug.h:221
lbug internal timestamp_sec_t type which stores the number of seconds since 1970-01-01 00:00:00 UTC.
Definition lbug.h:237
int64_t value
Definition lbug.h:239
lbug internal timestamp type which stores the number of microseconds since 1970-01-01 00:00:00 UTC.
Definition lbug.h:255
int64_t value
Definition lbug.h:257
lbug internal timestamp_tz type which stores the number of microseconds since 1970-01-01 with timezon...
Definition lbug.h:246
int64_t value
Definition lbug.h:248
lbug_value is used to represent a value with any lbug internal dataType.
Definition lbug.h:194
bool _is_owned_by_cpp
Definition lbug.h:196
void * _value
Definition lbug.h:195