From 4cb4057876df25269a80f1f285ae0303b3d81c22 Mon Sep 17 00:00:00 2001 From: Austin Barrington Date: Wed, 31 Dec 2025 10:17:29 +0000 Subject: [PATCH 1/2] feat(docs): add rust docs --- src/arg.rs | 53 ++++- src/bindings.rs | 463 ++++++++++++++++---------------------------- src/connection.rs | 128 +++++++++++- src/error.rs | 25 +++ src/format.rs | 38 +++- src/lib.rs | 80 +++++++- src/log_level.rs | 15 ++ src/query_result.rs | 174 +++++++++++++++++ src/session.rs | 213 +++++++++++++++++++- 9 files changed, 871 insertions(+), 318 deletions(-) diff --git a/src/arg.rs b/src/arg.rs index c303600..9fd0dd9 100644 --- a/src/arg.rs +++ b/src/arg.rs @@ -1,3 +1,8 @@ +//! Query argument definitions for chDB. +//! +//! This module provides types for specifying query arguments such as output format, +//! log level, and custom command-line arguments. + use std::borrow::Cow; use std::ffi::CString; @@ -5,13 +10,35 @@ use crate::error::Error; use crate::format::OutputFormat; use crate::log_level::LogLevel; +/// Query arguments that can be passed when executing queries. +/// +/// `Arg` represents various command-line arguments that can be used to configure +/// query execution. Most commonly, you'll use `OutputFormat` to specify the +/// desired output format. +/// +/// # Examples +/// +/// ```no_run +/// use chdb_rust::arg::Arg; +/// use chdb_rust::format::OutputFormat; +/// use chdb_rust::log_level::LogLevel; +/// +/// // Specify output format +/// let args = &[Arg::OutputFormat(OutputFormat::JSONEachRow)]; +/// +/// // Specify log level +/// let args = &[Arg::LogLevel(LogLevel::Debug)]; +/// +/// // Use custom arguments +/// let args = &[Arg::Custom("path".into(), Some("/tmp/db".into()))]; +/// ``` #[derive(Debug)] pub enum Arg<'a> { - /// --config-file= + /// `--config-file=` ConfigFilePath(Cow<'a, str>), - /// --log-level= + /// `--log-level=` LogLevel(LogLevel), - /// --output-format= + /// `--output-format=` OutputFormat(OutputFormat), /// --multiquery MultiQuery, @@ -26,7 +53,7 @@ pub enum Arg<'a> { /// 2. Arg::Custom("multiline".into(), None). /// /// We should tell user where to look for officially supported arguments. - /// Here is some hint for now: https://github.com/fixcik/chdb-rs/blob/master/OPTIONS.md . + /// Here is some hint for now: . Custom(Cow<'a, str>, Option>), } @@ -45,7 +72,10 @@ impl<'a> Arg<'a> { }?) } - /// Extract OutputFormat from an Arg if it is an OutputFormat variant. + /// Extract `OutputFormat` from an `Arg` if it is an `OutputFormat` variant. + /// + /// This is a helper method used internally to extract output format information + /// from query arguments. pub(crate) fn as_output_format(&self) -> Option { match self { Self::OutputFormat(f) => Some(*f), @@ -54,7 +84,18 @@ impl<'a> Arg<'a> { } } -/// Extract OutputFormat from a slice of Args, returns the first one found or default. +/// Extract `OutputFormat` from a slice of `Arg`s. +/// +/// This function searches through the provided arguments and returns the first +/// `OutputFormat` found, or the default `TabSeparated` format if none is found. +/// +/// # Arguments +/// +/// * `args` - Optional slice of query arguments +/// +/// # Returns +/// +/// Returns the first `OutputFormat` found, or `OutputFormat::TabSeparated` as default. pub(crate) fn extract_output_format(args: Option<&[Arg]>) -> OutputFormat { args.and_then(|args| args.iter().find_map(|a| a.as_output_format())) .unwrap_or(OutputFormat::TabSeparated) diff --git a/src/bindings.rs b/src/bindings.rs index 8bc2242..4f43e8b 100644 --- a/src/bindings.rs +++ b/src/bindings.rs @@ -1,341 +1,207 @@ /* automatically generated by rust-bindgen 0.70.1 */ -pub const __bool_true_false_are_defined: u32 = 1; pub const true_: u32 = 1; pub const false_: u32 = 0; +pub const __bool_true_false_are_defined: u32 = 1; +pub const _STDINT_H: u32 = 1; +pub const _FEATURES_H: u32 = 1; +pub const _DEFAULT_SOURCE: u32 = 1; +pub const __GLIBC_USE_ISOC2X: u32 = 0; +pub const __USE_ISOC11: u32 = 1; +pub const __USE_ISOC99: u32 = 1; +pub const __USE_ISOC95: u32 = 1; +pub const __USE_POSIX_IMPLICITLY: u32 = 1; +pub const _POSIX_SOURCE: u32 = 1; +pub const _POSIX_C_SOURCE: u32 = 200809; +pub const __USE_POSIX: u32 = 1; +pub const __USE_POSIX2: u32 = 1; +pub const __USE_POSIX199309: u32 = 1; +pub const __USE_POSIX199506: u32 = 1; +pub const __USE_XOPEN2K: u32 = 1; +pub const __USE_XOPEN2K8: u32 = 1; +pub const _ATFILE_SOURCE: u32 = 1; +pub const __USE_MISC: u32 = 1; +pub const __USE_ATFILE: u32 = 1; +pub const __USE_FORTIFY_LEVEL: u32 = 0; +pub const __GLIBC_USE_DEPRECATED_GETS: u32 = 0; +pub const __GLIBC_USE_DEPRECATED_SCANF: u32 = 0; +pub const _STDC_PREDEF_H: u32 = 1; +pub const __STDC_IEC_559__: u32 = 1; +pub const __STDC_IEC_559_COMPLEX__: u32 = 1; +pub const __STDC_ISO_10646__: u32 = 201706; +pub const __GNU_LIBRARY__: u32 = 6; +pub const __GLIBC__: u32 = 2; +pub const __GLIBC_MINOR__: u32 = 31; +pub const _SYS_CDEFS_H: u32 = 1; +pub const __glibc_c99_flexarr_available: u32 = 1; pub const __WORDSIZE: u32 = 64; -pub const __has_safe_buffers: u32 = 1; -pub const __DARWIN_ONLY_64_BIT_INO_T: u32 = 1; -pub const __DARWIN_ONLY_UNIX_CONFORMANCE: u32 = 1; -pub const __DARWIN_ONLY_VERS_1050: u32 = 1; -pub const __DARWIN_UNIX03: u32 = 1; -pub const __DARWIN_64_BIT_INO_T: u32 = 1; -pub const __DARWIN_VERS_1050: u32 = 1; -pub const __DARWIN_NON_CANCELABLE: u32 = 0; -pub const __DARWIN_SUF_EXTSN: &[u8; 14] = b"$DARWIN_EXTSN\0"; -pub const __DARWIN_C_ANSI: u32 = 4096; -pub const __DARWIN_C_FULL: u32 = 900000; -pub const __DARWIN_C_LEVEL: u32 = 900000; -pub const __STDC_WANT_LIB_EXT1__: u32 = 1; -pub const __DARWIN_NO_LONG_LONG: u32 = 0; -pub const _DARWIN_FEATURE_64_BIT_INODE: u32 = 1; -pub const _DARWIN_FEATURE_ONLY_64_BIT_INODE: u32 = 1; -pub const _DARWIN_FEATURE_ONLY_VERS_1050: u32 = 1; -pub const _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE: u32 = 1; -pub const _DARWIN_FEATURE_UNIX_CONFORMANCE: u32 = 3; -pub const __has_ptrcheck: u32 = 0; -pub const USE_CLANG_TYPES: u32 = 0; -pub const __PTHREAD_SIZE__: u32 = 8176; -pub const __PTHREAD_ATTR_SIZE__: u32 = 56; -pub const __PTHREAD_MUTEXATTR_SIZE__: u32 = 8; -pub const __PTHREAD_MUTEX_SIZE__: u32 = 56; -pub const __PTHREAD_CONDATTR_SIZE__: u32 = 8; -pub const __PTHREAD_COND_SIZE__: u32 = 40; -pub const __PTHREAD_ONCE_SIZE__: u32 = 8; -pub const __PTHREAD_RWLOCK_SIZE__: u32 = 192; -pub const __PTHREAD_RWLOCKATTR_SIZE__: u32 = 16; -pub const INT8_MAX: u32 = 127; -pub const INT16_MAX: u32 = 32767; -pub const INT32_MAX: u32 = 2147483647; -pub const INT64_MAX: u64 = 9223372036854775807; +pub const __WORDSIZE_TIME64_COMPAT32: u32 = 1; +pub const __SYSCALL_WORDSIZE: u32 = 64; +pub const __LONG_DOUBLE_USES_FLOAT128: u32 = 0; +pub const __HAVE_GENERIC_SELECTION: u32 = 1; +pub const __GLIBC_USE_LIB_EXT2: u32 = 0; +pub const __GLIBC_USE_IEC_60559_BFP_EXT: u32 = 0; +pub const __GLIBC_USE_IEC_60559_BFP_EXT_C2X: u32 = 0; +pub const __GLIBC_USE_IEC_60559_FUNCS_EXT: u32 = 0; +pub const __GLIBC_USE_IEC_60559_FUNCS_EXT_C2X: u32 = 0; +pub const __GLIBC_USE_IEC_60559_TYPES_EXT: u32 = 0; +pub const _BITS_TYPES_H: u32 = 1; +pub const __TIMESIZE: u32 = 64; +pub const _BITS_TYPESIZES_H: u32 = 1; +pub const __OFF_T_MATCHES_OFF64_T: u32 = 1; +pub const __INO_T_MATCHES_INO64_T: u32 = 1; +pub const __RLIM_T_MATCHES_RLIM64_T: u32 = 1; +pub const __STATFS_MATCHES_STATFS64: u32 = 1; +pub const __FD_SETSIZE: u32 = 1024; +pub const _BITS_TIME64_H: u32 = 1; +pub const _BITS_WCHAR_H: u32 = 1; +pub const _BITS_STDINT_INTN_H: u32 = 1; +pub const _BITS_STDINT_UINTN_H: u32 = 1; pub const INT8_MIN: i32 = -128; pub const INT16_MIN: i32 = -32768; pub const INT32_MIN: i32 = -2147483648; -pub const INT64_MIN: i64 = -9223372036854775808; +pub const INT8_MAX: u32 = 127; +pub const INT16_MAX: u32 = 32767; +pub const INT32_MAX: u32 = 2147483647; pub const UINT8_MAX: u32 = 255; pub const UINT16_MAX: u32 = 65535; pub const UINT32_MAX: u32 = 4294967295; -pub const UINT64_MAX: i32 = -1; pub const INT_LEAST8_MIN: i32 = -128; pub const INT_LEAST16_MIN: i32 = -32768; pub const INT_LEAST32_MIN: i32 = -2147483648; -pub const INT_LEAST64_MIN: i64 = -9223372036854775808; pub const INT_LEAST8_MAX: u32 = 127; pub const INT_LEAST16_MAX: u32 = 32767; pub const INT_LEAST32_MAX: u32 = 2147483647; -pub const INT_LEAST64_MAX: u64 = 9223372036854775807; pub const UINT_LEAST8_MAX: u32 = 255; pub const UINT_LEAST16_MAX: u32 = 65535; pub const UINT_LEAST32_MAX: u32 = 4294967295; -pub const UINT_LEAST64_MAX: i32 = -1; pub const INT_FAST8_MIN: i32 = -128; -pub const INT_FAST16_MIN: i32 = -32768; -pub const INT_FAST32_MIN: i32 = -2147483648; -pub const INT_FAST64_MIN: i64 = -9223372036854775808; +pub const INT_FAST16_MIN: i64 = -9223372036854775808; +pub const INT_FAST32_MIN: i64 = -9223372036854775808; pub const INT_FAST8_MAX: u32 = 127; -pub const INT_FAST16_MAX: u32 = 32767; -pub const INT_FAST32_MAX: u32 = 2147483647; -pub const INT_FAST64_MAX: u64 = 9223372036854775807; +pub const INT_FAST16_MAX: u64 = 9223372036854775807; +pub const INT_FAST32_MAX: u64 = 9223372036854775807; pub const UINT_FAST8_MAX: u32 = 255; -pub const UINT_FAST16_MAX: u32 = 65535; -pub const UINT_FAST32_MAX: u32 = 4294967295; -pub const UINT_FAST64_MAX: i32 = -1; -pub const INTPTR_MAX: u64 = 9223372036854775807; +pub const UINT_FAST16_MAX: i32 = -1; +pub const UINT_FAST32_MAX: i32 = -1; pub const INTPTR_MIN: i64 = -9223372036854775808; +pub const INTPTR_MAX: u64 = 9223372036854775807; pub const UINTPTR_MAX: i32 = -1; -pub const SIZE_MAX: i32 = -1; -pub const RSIZE_MAX: i32 = -1; -pub const WINT_MIN: i32 = -2147483648; -pub const WINT_MAX: u32 = 2147483647; +pub const PTRDIFF_MIN: i64 = -9223372036854775808; +pub const PTRDIFF_MAX: u64 = 9223372036854775807; pub const SIG_ATOMIC_MIN: i32 = -2147483648; pub const SIG_ATOMIC_MAX: u32 = 2147483647; +pub const SIZE_MAX: i32 = -1; +pub const WINT_MIN: u32 = 0; +pub const WINT_MAX: u32 = 4294967295; pub type wchar_t = ::std::os::raw::c_int; -pub type max_align_t = f64; -pub type int_least8_t = i8; -pub type int_least16_t = i16; -pub type int_least32_t = i32; -pub type int_least64_t = i64; -pub type uint_least8_t = u8; -pub type uint_least16_t = u16; -pub type uint_least32_t = u32; -pub type uint_least64_t = u64; -pub type int_fast8_t = i8; -pub type int_fast16_t = i16; -pub type int_fast32_t = i32; -pub type int_fast64_t = i64; -pub type uint_fast8_t = u8; -pub type uint_fast16_t = u16; -pub type uint_fast32_t = u32; -pub type uint_fast64_t = u64; -pub type __int8_t = ::std::os::raw::c_schar; -pub type __uint8_t = ::std::os::raw::c_uchar; -pub type __int16_t = ::std::os::raw::c_short; -pub type __uint16_t = ::std::os::raw::c_ushort; -pub type __int32_t = ::std::os::raw::c_int; -pub type __uint32_t = ::std::os::raw::c_uint; -pub type __int64_t = ::std::os::raw::c_longlong; -pub type __uint64_t = ::std::os::raw::c_ulonglong; -pub type __darwin_intptr_t = ::std::os::raw::c_long; -pub type __darwin_natural_t = ::std::os::raw::c_uint; -pub type __darwin_ct_rune_t = ::std::os::raw::c_int; -#[repr(C)] -#[derive(Copy, Clone)] -pub union __mbstate_t { - pub __mbstate8: [::std::os::raw::c_char; 128usize], - pub _mbstateL: ::std::os::raw::c_longlong, -} -#[allow(clippy::unnecessary_operation, clippy::identity_op)] -const _: () = { - ["Size of __mbstate_t"][::std::mem::size_of::<__mbstate_t>() - 128usize]; - ["Alignment of __mbstate_t"][::std::mem::align_of::<__mbstate_t>() - 8usize]; - ["Offset of field: __mbstate_t::__mbstate8"] - [::std::mem::offset_of!(__mbstate_t, __mbstate8) - 0usize]; - ["Offset of field: __mbstate_t::_mbstateL"] - [::std::mem::offset_of!(__mbstate_t, _mbstateL) - 0usize]; -}; -pub type __darwin_mbstate_t = __mbstate_t; -pub type __darwin_ptrdiff_t = ::std::os::raw::c_long; -pub type __darwin_size_t = ::std::os::raw::c_ulong; -pub type __darwin_va_list = __builtin_va_list; -pub type __darwin_wchar_t = ::std::os::raw::c_int; -pub type __darwin_rune_t = __darwin_wchar_t; -pub type __darwin_wint_t = ::std::os::raw::c_int; -pub type __darwin_clock_t = ::std::os::raw::c_ulong; -pub type __darwin_socklen_t = __uint32_t; -pub type __darwin_ssize_t = ::std::os::raw::c_long; -pub type __darwin_time_t = ::std::os::raw::c_long; -pub type __darwin_blkcnt_t = __int64_t; -pub type __darwin_blksize_t = __int32_t; -pub type __darwin_dev_t = __int32_t; -pub type __darwin_fsblkcnt_t = ::std::os::raw::c_uint; -pub type __darwin_fsfilcnt_t = ::std::os::raw::c_uint; -pub type __darwin_gid_t = __uint32_t; -pub type __darwin_id_t = __uint32_t; -pub type __darwin_ino64_t = __uint64_t; -pub type __darwin_ino_t = __darwin_ino64_t; -pub type __darwin_mach_port_name_t = __darwin_natural_t; -pub type __darwin_mach_port_t = __darwin_mach_port_name_t; -pub type __darwin_mode_t = __uint16_t; -pub type __darwin_off_t = __int64_t; -pub type __darwin_pid_t = __int32_t; -pub type __darwin_sigset_t = __uint32_t; -pub type __darwin_suseconds_t = __int32_t; -pub type __darwin_uid_t = __uint32_t; -pub type __darwin_useconds_t = __uint32_t; -pub type __darwin_uuid_t = [::std::os::raw::c_uchar; 16usize]; -pub type __darwin_uuid_string_t = [::std::os::raw::c_char; 37usize]; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct __darwin_pthread_handler_rec { - pub __routine: ::std::option::Option, - pub __arg: *mut ::std::os::raw::c_void, - pub __next: *mut __darwin_pthread_handler_rec, -} -#[allow(clippy::unnecessary_operation, clippy::identity_op)] -const _: () = { - ["Size of __darwin_pthread_handler_rec"] - [::std::mem::size_of::<__darwin_pthread_handler_rec>() - 24usize]; - ["Alignment of __darwin_pthread_handler_rec"] - [::std::mem::align_of::<__darwin_pthread_handler_rec>() - 8usize]; - ["Offset of field: __darwin_pthread_handler_rec::__routine"] - [::std::mem::offset_of!(__darwin_pthread_handler_rec, __routine) - 0usize]; - ["Offset of field: __darwin_pthread_handler_rec::__arg"] - [::std::mem::offset_of!(__darwin_pthread_handler_rec, __arg) - 8usize]; - ["Offset of field: __darwin_pthread_handler_rec::__next"] - [::std::mem::offset_of!(__darwin_pthread_handler_rec, __next) - 16usize]; -}; #[repr(C)] +#[repr(align(16))] #[derive(Debug, Copy, Clone)] -pub struct _opaque_pthread_attr_t { - pub __sig: ::std::os::raw::c_long, - pub __opaque: [::std::os::raw::c_char; 56usize], +pub struct max_align_t { + pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, + pub __bindgen_padding_0: u64, + pub __clang_max_align_nonce2: u128, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { - ["Size of _opaque_pthread_attr_t"][::std::mem::size_of::<_opaque_pthread_attr_t>() - 64usize]; - ["Alignment of _opaque_pthread_attr_t"] - [::std::mem::align_of::<_opaque_pthread_attr_t>() - 8usize]; - ["Offset of field: _opaque_pthread_attr_t::__sig"] - [::std::mem::offset_of!(_opaque_pthread_attr_t, __sig) - 0usize]; - ["Offset of field: _opaque_pthread_attr_t::__opaque"] - [::std::mem::offset_of!(_opaque_pthread_attr_t, __opaque) - 8usize]; -}; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _opaque_pthread_cond_t { - pub __sig: ::std::os::raw::c_long, - pub __opaque: [::std::os::raw::c_char; 40usize], -} -#[allow(clippy::unnecessary_operation, clippy::identity_op)] -const _: () = { - ["Size of _opaque_pthread_cond_t"][::std::mem::size_of::<_opaque_pthread_cond_t>() - 48usize]; - ["Alignment of _opaque_pthread_cond_t"] - [::std::mem::align_of::<_opaque_pthread_cond_t>() - 8usize]; - ["Offset of field: _opaque_pthread_cond_t::__sig"] - [::std::mem::offset_of!(_opaque_pthread_cond_t, __sig) - 0usize]; - ["Offset of field: _opaque_pthread_cond_t::__opaque"] - [::std::mem::offset_of!(_opaque_pthread_cond_t, __opaque) - 8usize]; -}; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _opaque_pthread_condattr_t { - pub __sig: ::std::os::raw::c_long, - pub __opaque: [::std::os::raw::c_char; 8usize], -} -#[allow(clippy::unnecessary_operation, clippy::identity_op)] -const _: () = { - ["Size of _opaque_pthread_condattr_t"] - [::std::mem::size_of::<_opaque_pthread_condattr_t>() - 16usize]; - ["Alignment of _opaque_pthread_condattr_t"] - [::std::mem::align_of::<_opaque_pthread_condattr_t>() - 8usize]; - ["Offset of field: _opaque_pthread_condattr_t::__sig"] - [::std::mem::offset_of!(_opaque_pthread_condattr_t, __sig) - 0usize]; - ["Offset of field: _opaque_pthread_condattr_t::__opaque"] - [::std::mem::offset_of!(_opaque_pthread_condattr_t, __opaque) - 8usize]; -}; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _opaque_pthread_mutex_t { - pub __sig: ::std::os::raw::c_long, - pub __opaque: [::std::os::raw::c_char; 56usize], -} -#[allow(clippy::unnecessary_operation, clippy::identity_op)] -const _: () = { - ["Size of _opaque_pthread_mutex_t"][::std::mem::size_of::<_opaque_pthread_mutex_t>() - 64usize]; - ["Alignment of _opaque_pthread_mutex_t"] - [::std::mem::align_of::<_opaque_pthread_mutex_t>() - 8usize]; - ["Offset of field: _opaque_pthread_mutex_t::__sig"] - [::std::mem::offset_of!(_opaque_pthread_mutex_t, __sig) - 0usize]; - ["Offset of field: _opaque_pthread_mutex_t::__opaque"] - [::std::mem::offset_of!(_opaque_pthread_mutex_t, __opaque) - 8usize]; -}; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _opaque_pthread_mutexattr_t { - pub __sig: ::std::os::raw::c_long, - pub __opaque: [::std::os::raw::c_char; 8usize], -} -#[allow(clippy::unnecessary_operation, clippy::identity_op)] -const _: () = { - ["Size of _opaque_pthread_mutexattr_t"] - [::std::mem::size_of::<_opaque_pthread_mutexattr_t>() - 16usize]; - ["Alignment of _opaque_pthread_mutexattr_t"] - [::std::mem::align_of::<_opaque_pthread_mutexattr_t>() - 8usize]; - ["Offset of field: _opaque_pthread_mutexattr_t::__sig"] - [::std::mem::offset_of!(_opaque_pthread_mutexattr_t, __sig) - 0usize]; - ["Offset of field: _opaque_pthread_mutexattr_t::__opaque"] - [::std::mem::offset_of!(_opaque_pthread_mutexattr_t, __opaque) - 8usize]; -}; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _opaque_pthread_once_t { - pub __sig: ::std::os::raw::c_long, - pub __opaque: [::std::os::raw::c_char; 8usize], -} -#[allow(clippy::unnecessary_operation, clippy::identity_op)] -const _: () = { - ["Size of _opaque_pthread_once_t"][::std::mem::size_of::<_opaque_pthread_once_t>() - 16usize]; - ["Alignment of _opaque_pthread_once_t"] - [::std::mem::align_of::<_opaque_pthread_once_t>() - 8usize]; - ["Offset of field: _opaque_pthread_once_t::__sig"] - [::std::mem::offset_of!(_opaque_pthread_once_t, __sig) - 0usize]; - ["Offset of field: _opaque_pthread_once_t::__opaque"] - [::std::mem::offset_of!(_opaque_pthread_once_t, __opaque) - 8usize]; -}; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _opaque_pthread_rwlock_t { - pub __sig: ::std::os::raw::c_long, - pub __opaque: [::std::os::raw::c_char; 192usize], -} -#[allow(clippy::unnecessary_operation, clippy::identity_op)] -const _: () = { - ["Size of _opaque_pthread_rwlock_t"] - [::std::mem::size_of::<_opaque_pthread_rwlock_t>() - 200usize]; - ["Alignment of _opaque_pthread_rwlock_t"] - [::std::mem::align_of::<_opaque_pthread_rwlock_t>() - 8usize]; - ["Offset of field: _opaque_pthread_rwlock_t::__sig"] - [::std::mem::offset_of!(_opaque_pthread_rwlock_t, __sig) - 0usize]; - ["Offset of field: _opaque_pthread_rwlock_t::__opaque"] - [::std::mem::offset_of!(_opaque_pthread_rwlock_t, __opaque) - 8usize]; -}; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _opaque_pthread_rwlockattr_t { - pub __sig: ::std::os::raw::c_long, - pub __opaque: [::std::os::raw::c_char; 16usize], -} -#[allow(clippy::unnecessary_operation, clippy::identity_op)] -const _: () = { - ["Size of _opaque_pthread_rwlockattr_t"] - [::std::mem::size_of::<_opaque_pthread_rwlockattr_t>() - 24usize]; - ["Alignment of _opaque_pthread_rwlockattr_t"] - [::std::mem::align_of::<_opaque_pthread_rwlockattr_t>() - 8usize]; - ["Offset of field: _opaque_pthread_rwlockattr_t::__sig"] - [::std::mem::offset_of!(_opaque_pthread_rwlockattr_t, __sig) - 0usize]; - ["Offset of field: _opaque_pthread_rwlockattr_t::__opaque"] - [::std::mem::offset_of!(_opaque_pthread_rwlockattr_t, __opaque) - 8usize]; + ["Size of max_align_t"][::std::mem::size_of::() - 32usize]; + ["Alignment of max_align_t"][::std::mem::align_of::() - 16usize]; + ["Offset of field: max_align_t::__clang_max_align_nonce1"] + [::std::mem::offset_of!(max_align_t, __clang_max_align_nonce1) - 0usize]; + ["Offset of field: max_align_t::__clang_max_align_nonce2"] + [::std::mem::offset_of!(max_align_t, __clang_max_align_nonce2) - 16usize]; }; +pub type __u_char = ::std::os::raw::c_uchar; +pub type __u_short = ::std::os::raw::c_ushort; +pub type __u_int = ::std::os::raw::c_uint; +pub type __u_long = ::std::os::raw::c_ulong; +pub type __int8_t = ::std::os::raw::c_schar; +pub type __uint8_t = ::std::os::raw::c_uchar; +pub type __int16_t = ::std::os::raw::c_short; +pub type __uint16_t = ::std::os::raw::c_ushort; +pub type __int32_t = ::std::os::raw::c_int; +pub type __uint32_t = ::std::os::raw::c_uint; +pub type __int64_t = ::std::os::raw::c_long; +pub type __uint64_t = ::std::os::raw::c_ulong; +pub type __int_least8_t = __int8_t; +pub type __uint_least8_t = __uint8_t; +pub type __int_least16_t = __int16_t; +pub type __uint_least16_t = __uint16_t; +pub type __int_least32_t = __int32_t; +pub type __uint_least32_t = __uint32_t; +pub type __int_least64_t = __int64_t; +pub type __uint_least64_t = __uint64_t; +pub type __quad_t = ::std::os::raw::c_long; +pub type __u_quad_t = ::std::os::raw::c_ulong; +pub type __intmax_t = ::std::os::raw::c_long; +pub type __uintmax_t = ::std::os::raw::c_ulong; +pub type __dev_t = ::std::os::raw::c_ulong; +pub type __uid_t = ::std::os::raw::c_uint; +pub type __gid_t = ::std::os::raw::c_uint; +pub type __ino_t = ::std::os::raw::c_ulong; +pub type __ino64_t = ::std::os::raw::c_ulong; +pub type __mode_t = ::std::os::raw::c_uint; +pub type __nlink_t = ::std::os::raw::c_ulong; +pub type __off_t = ::std::os::raw::c_long; +pub type __off64_t = ::std::os::raw::c_long; +pub type __pid_t = ::std::os::raw::c_int; #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct _opaque_pthread_t { - pub __sig: ::std::os::raw::c_long, - pub __cleanup_stack: *mut __darwin_pthread_handler_rec, - pub __opaque: [::std::os::raw::c_char; 8176usize], +pub struct __fsid_t { + pub __val: [::std::os::raw::c_int; 2usize], } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { - ["Size of _opaque_pthread_t"][::std::mem::size_of::<_opaque_pthread_t>() - 8192usize]; - ["Alignment of _opaque_pthread_t"][::std::mem::align_of::<_opaque_pthread_t>() - 8usize]; - ["Offset of field: _opaque_pthread_t::__sig"] - [::std::mem::offset_of!(_opaque_pthread_t, __sig) - 0usize]; - ["Offset of field: _opaque_pthread_t::__cleanup_stack"] - [::std::mem::offset_of!(_opaque_pthread_t, __cleanup_stack) - 8usize]; - ["Offset of field: _opaque_pthread_t::__opaque"] - [::std::mem::offset_of!(_opaque_pthread_t, __opaque) - 16usize]; + ["Size of __fsid_t"][::std::mem::size_of::<__fsid_t>() - 8usize]; + ["Alignment of __fsid_t"][::std::mem::align_of::<__fsid_t>() - 4usize]; + ["Offset of field: __fsid_t::__val"][::std::mem::offset_of!(__fsid_t, __val) - 0usize]; }; -pub type __darwin_pthread_attr_t = _opaque_pthread_attr_t; -pub type __darwin_pthread_cond_t = _opaque_pthread_cond_t; -pub type __darwin_pthread_condattr_t = _opaque_pthread_condattr_t; -pub type __darwin_pthread_key_t = ::std::os::raw::c_ulong; -pub type __darwin_pthread_mutex_t = _opaque_pthread_mutex_t; -pub type __darwin_pthread_mutexattr_t = _opaque_pthread_mutexattr_t; -pub type __darwin_pthread_once_t = _opaque_pthread_once_t; -pub type __darwin_pthread_rwlock_t = _opaque_pthread_rwlock_t; -pub type __darwin_pthread_rwlockattr_t = _opaque_pthread_rwlockattr_t; -pub type __darwin_pthread_t = *mut _opaque_pthread_t; -pub type intmax_t = ::std::os::raw::c_long; -pub type uintmax_t = ::std::os::raw::c_ulong; +pub type __clock_t = ::std::os::raw::c_long; +pub type __rlim_t = ::std::os::raw::c_ulong; +pub type __rlim64_t = ::std::os::raw::c_ulong; +pub type __id_t = ::std::os::raw::c_uint; +pub type __time_t = ::std::os::raw::c_long; +pub type __useconds_t = ::std::os::raw::c_uint; +pub type __suseconds_t = ::std::os::raw::c_long; +pub type __daddr_t = ::std::os::raw::c_int; +pub type __key_t = ::std::os::raw::c_int; +pub type __clockid_t = ::std::os::raw::c_int; +pub type __timer_t = *mut ::std::os::raw::c_void; +pub type __blksize_t = ::std::os::raw::c_long; +pub type __blkcnt_t = ::std::os::raw::c_long; +pub type __blkcnt64_t = ::std::os::raw::c_long; +pub type __fsblkcnt_t = ::std::os::raw::c_ulong; +pub type __fsblkcnt64_t = ::std::os::raw::c_ulong; +pub type __fsfilcnt_t = ::std::os::raw::c_ulong; +pub type __fsfilcnt64_t = ::std::os::raw::c_ulong; +pub type __fsword_t = ::std::os::raw::c_long; +pub type __ssize_t = ::std::os::raw::c_long; +pub type __syscall_slong_t = ::std::os::raw::c_long; +pub type __syscall_ulong_t = ::std::os::raw::c_ulong; +pub type __loff_t = __off64_t; +pub type __caddr_t = *mut ::std::os::raw::c_char; +pub type __intptr_t = ::std::os::raw::c_long; +pub type __socklen_t = ::std::os::raw::c_uint; +pub type __sig_atomic_t = ::std::os::raw::c_int; +pub type int_least8_t = __int_least8_t; +pub type int_least16_t = __int_least16_t; +pub type int_least32_t = __int_least32_t; +pub type int_least64_t = __int_least64_t; +pub type uint_least8_t = __uint_least8_t; +pub type uint_least16_t = __uint_least16_t; +pub type uint_least32_t = __uint_least32_t; +pub type uint_least64_t = __uint_least64_t; +pub type int_fast8_t = ::std::os::raw::c_schar; +pub type int_fast16_t = ::std::os::raw::c_long; +pub type int_fast32_t = ::std::os::raw::c_long; +pub type int_fast64_t = ::std::os::raw::c_long; +pub type uint_fast8_t = ::std::os::raw::c_uchar; +pub type uint_fast16_t = ::std::os::raw::c_ulong; +pub type uint_fast32_t = ::std::os::raw::c_ulong; +pub type uint_fast64_t = ::std::os::raw::c_ulong; +pub type intmax_t = __intmax_t; +pub type uintmax_t = __uintmax_t; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct local_result { @@ -699,4 +565,3 @@ extern "C" { table_name: *const ::std::os::raw::c_char, ) -> chdb_state; } -pub type __builtin_va_list = *mut ::std::os::raw::c_char; diff --git a/src/connection.rs b/src/connection.rs index f810f94..0428132 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -1,3 +1,7 @@ +//! Connection management for chDB. +//! +//! This module provides the [`Connection`] type for managing connections to chDB databases. + use std::ffi::{c_char, CString}; use crate::bindings; @@ -5,7 +9,32 @@ use crate::error::{Error, Result}; use crate::format::OutputFormat; use crate::query_result::QueryResult; -/// A connection to chDB database. +/// A connection to a chDB database. +/// +/// A `Connection` represents an active connection to a chDB database instance. +/// Connections can be created for in-memory databases or persistent databases +/// stored on disk. +/// +/// # Thread Safety +/// +/// `Connection` implements `Send`, meaning it can be safely transferred between threads. +/// However, the underlying chDB library may have limitations on concurrent access. +/// It's recommended to use one connection per thread or implement proper synchronization. +/// +/// # Examples +/// +/// ```no_run +/// use chdb_rust::connection::Connection; +/// use chdb_rust::format::OutputFormat; +/// +/// // Create an in-memory connection +/// let conn = Connection::open_in_memory()?; +/// +/// // Execute a query +/// let result = conn.query("SELECT 1", OutputFormat::JSONEachRow)?; +/// println!("{}", result.data_utf8_lossy()); +/// # Ok::<(), chdb_rust::error::Error>(()) +/// ``` #[derive(Debug)] pub struct Connection { // Pointer to chdb_connection (which is *mut chdb_connection_) @@ -13,11 +42,34 @@ pub struct Connection { } // Safety: Connection is safe to send between threads +// The underlying chDB library is thread-safe for query execution unsafe impl Send for Connection {} impl Connection { - /// Connect to chDB with the given arguments. - /// Use `--path=` to specify database location, default is `:memory:`. + /// Connect to chDB with the given command-line arguments. + /// + /// This is a low-level function that allows you to pass arbitrary arguments + /// to the chDB connection. For most use cases, prefer [`open_in_memory`](Self::open_in_memory) + /// or [`open_with_path`](Self::open_with_path). + /// + /// # Arguments + /// + /// * `args` - Array of command-line arguments (e.g., `["clickhouse", "--path=/tmp/db"]`) + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::connection::Connection; + /// + /// // Connect with custom arguments + /// let conn = Connection::open(&["clickhouse", "--path=/tmp/mydb"])?; + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` + /// + /// # Errors + /// + /// Returns [`Error::ConnectionFailed`] if the + /// connection cannot be established. pub fn open(args: &[&str]) -> Result { let c_args: Vec = args .iter() @@ -42,17 +94,87 @@ impl Connection { } /// Connect to an in-memory database. + /// + /// Creates a connection to a temporary in-memory database. Data stored in this + /// database will be lost when the connection is closed. + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::connection::Connection; + /// + /// let conn = Connection::open_in_memory()?; + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` + /// + /// # Errors + /// + /// Returns [`Error::ConnectionFailed`] if the + /// connection cannot be established. pub fn open_in_memory() -> Result { Self::open(&["clickhouse"]) } /// Connect to a database at the given path. + /// + /// Creates a connection to a persistent database stored at the specified path. + /// The directory will be created if it doesn't exist. + /// + /// # Arguments + /// + /// * `path` - The filesystem path where the database should be stored + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::connection::Connection; + /// + /// let conn = Connection::open_with_path("/tmp/mydb")?; + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` + /// + /// # Errors + /// + /// Returns [`Error::ConnectionFailed`] if the + /// connection cannot be established. pub fn open_with_path(path: &str) -> Result { let path_arg = format!("--path={}", path); Self::open(&["clickhouse", &path_arg]) } /// Execute a query and return the result. + /// + /// Executes a SQL query against the database and returns the result in the + /// specified output format. + /// + /// # Arguments + /// + /// * `sql` - The SQL query string to execute + /// * `format` - The desired output format for the result + /// + /// # Returns + /// + /// Returns a [`QueryResult`] containing the query output, or an [`Error`] + /// if the query fails. + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::connection::Connection; + /// use chdb_rust::format::OutputFormat; + /// + /// let conn = Connection::open_in_memory()?; + /// let result = conn.query("SELECT 1 + 1 AS sum", OutputFormat::JSONEachRow)?; + /// println!("{}", result.data_utf8_lossy()); + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` + /// + /// # Errors + /// + /// Returns an error if: + /// - The query syntax is invalid + /// - The query references non-existent tables or columns + /// - The query execution fails for any other reason pub fn query(&self, sql: &str, format: OutputFormat) -> Result { let query_cstr = CString::new(sql)?; let format_cstr = CString::new(format.as_str())?; diff --git a/src/error.rs b/src/error.rs index 0d25327..9c53812 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,28 +1,53 @@ +//! Error types for chdb-rust. +//! +//! This module defines the error types used throughout the crate. + use std::ffi::NulError; use std::string::FromUtf8Error; +/// Errors that can occur when using chdb-rust. +/// +/// This enum represents all possible errors that can be returned by the library. +/// Most errors are self-explanatory, with `QueryError` containing the actual error +/// message from the underlying chDB library. #[derive(Debug, thiserror::Error)] pub enum Error { + /// An unknown error has occurred. #[error("An unknown error has occurred")] Unknown, + /// No result was returned from the query. #[error("No result")] NoResult, + /// Failed to establish a connection to chDB. #[error("Connection failed")] ConnectionFailed, + /// Invalid data was encountered. #[error("Invalid data: {0}")] InvalidData(String), + /// Invalid path was provided. #[error("Invalid path")] PathError, + /// An I/O error occurred. #[error(transparent)] Io(#[from] std::io::Error), + /// A null byte was found in a string where it's not allowed. #[error(transparent)] Nul(#[from] NulError), + /// Insufficient permissions to access the directory. #[error("Insufficient dir permissions")] InsufficientPermissions, + /// The data contains invalid UTF-8 sequences. #[error("Non UTF-8 sequence: {0}")] NonUtf8Sequence(FromUtf8Error), + /// A query execution error occurred. + /// + /// This contains the error message from the underlying chDB library, + /// which typically includes details about SQL syntax errors, missing tables, etc. #[error("{0}")] QueryError(String), } +/// A type alias for `Result`. +/// +/// This is the standard result type used throughout the crate. pub type Result = std::result::Result; diff --git a/src/format.rs b/src/format.rs index fc2ec24..64dfdac 100644 --- a/src/format.rs +++ b/src/format.rs @@ -1,3 +1,13 @@ +//! Input and output format definitions for chDB queries. +//! +//! This module defines the various data formats supported by chDB for reading +//! input data and formatting query results. + +/// Input formats for reading data into chDB. +/// +/// These formats specify how data should be parsed when reading from files or +/// other sources. See the [ClickHouse documentation](https://clickhouse.com/docs/en/interfaces/formats/) +/// for details on each format. #[derive(Debug, Clone, Copy)] pub enum InputFormat { TabSeparated, @@ -41,8 +51,6 @@ pub enum InputFormat { AvroConfluent, Parquet, ParquetMetadata, - Arrow, - ArrowStream, ORC, One, Npy, @@ -61,6 +69,11 @@ pub enum InputFormat { Form, } +/// Output formats for query results. +/// +/// These formats specify how query results should be formatted when returned. +/// See the [ClickHouse documentation](https://clickhouse.com/docs/en/interfaces/formats/) +/// for details on each format. #[derive(Debug, Clone, Copy)] pub enum OutputFormat { TabSeparated, @@ -116,8 +129,6 @@ pub enum OutputFormat { ProtobufList, Avro, Parquet, - Arrow, - ArrowStream, ORC, Npy, RowBinary, @@ -135,6 +146,14 @@ pub enum OutputFormat { } impl InputFormat { + /// Get the string representation of the input format. + /// + /// This returns the format name as it should be used in SQL queries + /// (e.g., in `file()` function calls). + /// + /// # Returns + /// + /// Returns the format name as a static string slice. pub const fn as_str(self) -> &'static str { match self { Self::TabSeparated => "TabSeparated", @@ -180,8 +199,6 @@ impl InputFormat { Self::AvroConfluent => "AvroConfluent", Self::Parquet => "Parquet", Self::ParquetMetadata => "ParquetMetadata", - Self::Arrow => "Arrow", - Self::ArrowStream => "ArrowStream", Self::ORC => "ORC", Self::One => "One", Self::Npy => "Npy", @@ -203,6 +220,13 @@ impl InputFormat { } impl OutputFormat { + /// Get the string representation of the output format. + /// + /// This returns the format name as it should be used when executing queries. + /// + /// # Returns + /// + /// Returns the format name as a static string slice. pub const fn as_str(self) -> &'static str { match self { Self::TabSeparated => "TabSeparated", @@ -260,8 +284,6 @@ impl OutputFormat { Self::ProtobufList => "ProtobufList", Self::Avro => "Avro", Self::Parquet => "Parquet", - Self::Arrow => "Arrow", - Self::ArrowStream => "ArrowStream", Self::ORC => "ORC", Self::Npy => "Npy", Self::RowBinary => "RowBinary", diff --git a/src/lib.rs b/src/lib.rs index 5668e3f..067dba0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,41 @@ +//! # chdb-rust +//! +//! Rust FFI bindings for [chDB](https://github.com/chdb-io/chdb), an embedded ClickHouse database. +//! +//! ## Overview +//! +//! This crate provides a safe Rust interface to chDB, allowing you to execute ClickHouse SQL queries +//! either statelessly (in-memory) or with persistent storage using sessions. +//! +//! ## Quick Start +//! +//! ```no_run +//! use chdb_rust::execute; +//! use chdb_rust::arg::Arg; +//! use chdb_rust::format::OutputFormat; +//! +//! // Execute a simple query +//! let result = execute("SELECT 1 + 1 AS sum", None)?; +//! println!("Result: {}", result.data_utf8_lossy()); +//! # Ok::<(), chdb_rust::error::Error>(()) +//! ``` +//! +//! ## Features +//! +//! - **Stateless queries**: Execute one-off queries without persistent storage +//! - **Stateful sessions**: Create databases and tables with persistent storage +//! - **Multiple output formats**: JSON, CSV, TabSeparated, and more +//! - **Thread-safe**: Connections and results can be safely sent between threads +//! +//! ## Examples +//! +//! See the [`examples`](https://github.com/chdb-io/chdb-rust/tree/main/examples) directory for more detailed examples. +//! +//! ## Safety +//! +//! This crate uses `unsafe` code to interface with the C library, but provides a safe Rust API. +//! All public functions are safe to call, and the crate ensures proper resource cleanup. + pub mod arg; #[allow( dead_code, @@ -7,7 +45,7 @@ pub mod arg; non_upper_case_globals )] mod bindings; -mod connection; +pub mod connection; pub mod error; pub mod format; pub mod log_level; @@ -20,6 +58,46 @@ use crate::error::Result; use crate::query_result::QueryResult; /// Execute a one-off query using an in-memory connection. +/// +/// This function creates a temporary in-memory database connection, executes the query, +/// and returns the result. It's suitable for queries that don't require persistent storage. +/// +/// # Arguments +/// +/// * `query` - The SQL query string to execute +/// * `query_args` - Optional array of query arguments (e.g., output format) +/// +/// # Returns +/// +/// Returns a [`QueryResult`] containing the query output, or an [`Error`](error::Error) if +/// the query fails. +/// +/// # Examples +/// +/// ```no_run +/// use chdb_rust::execute; +/// use chdb_rust::arg::Arg; +/// use chdb_rust::format::OutputFormat; +/// +/// // Simple query with default format +/// let result = execute("SELECT 1 + 1 AS sum", None)?; +/// println!("{}", result.data_utf8_lossy()); +/// +/// // Query with JSON output format +/// let result = execute( +/// "SELECT 'Hello' AS greeting, 42 AS answer", +/// Some(&[Arg::OutputFormat(OutputFormat::JSONEachRow)]) +/// )?; +/// println!("{}", result.data_utf8_lossy()); +/// # Ok::<(), chdb_rust::error::Error>(()) +/// ``` +/// +/// # Errors +/// +/// This function will return an error if: +/// - The query syntax is invalid +/// - The connection cannot be established +/// - The query execution fails pub fn execute(query: &str, query_args: Option<&[Arg]>) -> Result { let conn = Connection::open_in_memory()?; let fmt = extract_output_format(query_args); diff --git a/src/log_level.rs b/src/log_level.rs index ebe8c09..d2f95d7 100644 --- a/src/log_level.rs +++ b/src/log_level.rs @@ -1,3 +1,11 @@ +//! Log level definitions for chDB. +//! +//! This module defines the log levels that can be used to configure chDB's logging behavior. + +/// Log levels for chDB. +/// +/// These correspond to the standard log levels used by chDB for controlling +/// the verbosity of log output. #[derive(Debug, Clone, Copy)] pub enum LogLevel { Trace, @@ -8,6 +16,13 @@ pub enum LogLevel { } impl LogLevel { + /// Get the string representation of the log level. + /// + /// This returns the log level name as expected by chDB. + /// + /// # Returns + /// + /// Returns the log level name as a static string slice. pub const fn as_str(self) -> &'static str { match self { Self::Trace => "trace", diff --git a/src/query_result.rs b/src/query_result.rs index 3ed51b3..d5b29d0 100644 --- a/src/query_result.rs +++ b/src/query_result.rs @@ -1,3 +1,7 @@ +//! Query result handling for chDB. +//! +//! This module provides the [`QueryResult`] type for accessing query execution results. + use core::slice; use std::borrow::Cow; use std::ffi::CStr; @@ -7,12 +11,43 @@ use crate::bindings; use crate::error::Error; use crate::error::Result; +/// The result of a query execution. +/// +/// `QueryResult` contains the output data from a query execution, along with +/// metadata such as execution time and number of rows read. +/// +/// # Thread Safety +/// +/// `QueryResult` implements `Send`, meaning it can be safely transferred between threads. +/// +/// # Examples +/// +/// ```no_run +/// use chdb_rust::execute; +/// use chdb_rust::format::OutputFormat; +/// use chdb_rust::arg::Arg; +/// +/// let result = execute( +/// "SELECT number FROM numbers(10)", +/// Some(&[Arg::OutputFormat(OutputFormat::JSONEachRow)]) +/// )?; +/// +/// // Access the data as a string +/// println!("Data: {}", result.data_utf8_lossy()); +/// +/// // Access metadata +/// println!("Rows read: {}", result.rows_read()); +/// println!("Bytes read: {}", result.bytes_read()); +/// println!("Elapsed time: {:?}", result.elapsed()); +/// # Ok::<(), chdb_rust::error::Error>(()) +/// ``` #[derive(Debug)] pub struct QueryResult { inner: *mut bindings::chdb_result, } // Safety: QueryResult is safe to send between threads +// The underlying chDB result structure is thread-safe for read access unsafe impl Send for QueryResult {} impl QueryResult { @@ -20,19 +55,104 @@ impl QueryResult { Self { inner } } + /// Get the result data as a UTF-8 string. + /// + /// This method validates that the data is valid UTF-8. If the data contains + /// invalid UTF-8 sequences, it returns an error. + /// + /// # Returns + /// + /// Returns a `String` containing the query result, or an error if the data + /// contains invalid UTF-8 sequences. + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::execute; + /// + /// let result = execute("SELECT 'Hello, World!' AS greeting", None)?; + /// let data = result.data_utf8()?; + /// println!("{}", data); + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` + /// + /// # Errors + /// + /// Returns [`Error::NonUtf8Sequence`] if the + /// result data contains invalid UTF-8 sequences. Use [`data_utf8_lossy`](Self::data_utf8_lossy) + /// if you want to handle invalid UTF-8 gracefully. pub fn data_utf8(&self) -> Result { let buf = self.data_ref(); String::from_utf8(buf.to_vec()).map_err(Error::NonUtf8Sequence) } + /// Get the result data as a UTF-8 string, replacing invalid sequences. + /// + /// This method converts the result data to a string, replacing any invalid UTF-8 + /// sequences with the Unicode replacement character (U+FFFD). + /// + /// # Returns + /// + /// Returns a `Cow` containing the query result. Invalid UTF-8 sequences + /// are replaced with the replacement character. + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::execute; + /// + /// let result = execute("SELECT 'Hello, World!' AS greeting", None)?; + /// let data = result.data_utf8_lossy(); + /// println!("{}", data); + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` pub fn data_utf8_lossy(&self) -> Cow<'_, str> { String::from_utf8_lossy(self.data_ref()) } + /// Get the result data as a UTF-8 string without validation. + /// + /// # Safety + /// + /// This function is marked as safe, but it will produce invalid UTF-8 strings + /// if the underlying data contains non-UTF-8 bytes. Only use this if you're + /// certain the data is valid UTF-8, or if you're prepared to handle potentially + /// invalid strings. + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::execute; + /// + /// let result = execute("SELECT 'Hello' AS greeting", None)?; + /// let data = result.data_utf8_unchecked(); + /// println!("{}", data); + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` pub fn data_utf8_unchecked(&self) -> String { unsafe { String::from_utf8_unchecked(self.data_ref().to_vec()) } } + /// Get a reference to the raw result data as bytes. + /// + /// This method returns a byte slice containing the raw query result data. + /// The data is in the format specified when executing the query (e.g., JSON, CSV, etc.). + /// + /// # Returns + /// + /// Returns a byte slice containing the query result data. Returns an empty slice + /// if there's no data or if the buffer pointer is null. + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::execute; + /// + /// let result = execute("SELECT 1 AS value", None)?; + /// let bytes = result.data_ref(); + /// println!("Data length: {} bytes", bytes.len()); + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` pub fn data_ref(&self) -> &[u8] { let buf = unsafe { bindings::chdb_result_buffer(self.inner) }; let len = unsafe { bindings::chdb_result_length(self.inner) }; @@ -42,14 +162,68 @@ impl QueryResult { unsafe { slice::from_raw_parts(buf as *const u8, len) } } + /// Get the number of rows read by the query. + /// + /// This returns the total number of rows that were read from storage during + /// query execution. + /// + /// # Returns + /// + /// Returns the number of rows read as a `u64`. + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::execute; + /// + /// let result = execute("SELECT number FROM numbers(100)", None)?; + /// println!("Rows read: {}", result.rows_read()); + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` pub fn rows_read(&self) -> u64 { unsafe { bindings::chdb_result_rows_read(self.inner) } } + /// Get the number of bytes read by the query. + /// + /// This returns the total number of bytes that were read from storage during + /// query execution. + /// + /// # Returns + /// + /// Returns the number of bytes read as a `u64`. + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::execute; + /// + /// let result = execute("SELECT number FROM numbers(100)", None)?; + /// println!("Bytes read: {}", result.bytes_read()); + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` pub fn bytes_read(&self) -> u64 { unsafe { bindings::chdb_result_bytes_read(self.inner) } } + /// Get the elapsed time for query execution. + /// + /// This returns the time it took to execute the query, measured from when + /// the query was submitted until the result was ready. + /// + /// # Returns + /// + /// Returns a [`Duration`] representing the elapsed time. + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::execute; + /// + /// let result = execute("SELECT number FROM numbers(1000)", None)?; + /// println!("Query took: {:?}", result.elapsed()); + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` pub fn elapsed(&self) -> Duration { let elapsed = unsafe { bindings::chdb_result_elapsed(self.inner) }; Duration::from_secs_f64(elapsed) diff --git a/src/session.rs b/src/session.rs index 47e413e..673e03b 100644 --- a/src/session.rs +++ b/src/session.rs @@ -1,3 +1,8 @@ +//! Session management for persistent chDB databases. +//! +//! This module provides the [`Session`] and [`SessionBuilder`] types for managing +//! persistent database connections with automatic cleanup. + use std::fs; use std::path::PathBuf; @@ -7,6 +12,24 @@ use crate::error::Error; use crate::format::OutputFormat; use crate::query_result::QueryResult; +/// Builder for creating [`Session`] instances. +/// +/// `SessionBuilder` provides a fluent API for configuring and creating sessions. +/// Use [`new`](Self::new) to create a new builder, configure it with the desired +/// options, and call [`build`](Self::build) to create the session. +/// +/// # Examples +/// +/// ```no_run +/// use chdb_rust::session::SessionBuilder; +/// +/// // Create a session with default settings +/// let session = SessionBuilder::new() +/// .with_data_path("/tmp/mydb") +/// .with_auto_cleanup(true) +/// .build()?; +/// # Ok::<(), chdb_rust::error::Error>(()) +/// ``` pub struct SessionBuilder<'a> { data_path: PathBuf, default_format: OutputFormat, @@ -14,6 +37,47 @@ pub struct SessionBuilder<'a> { auto_cleanup: bool, } +/// A session representing a persistent connection to a chDB database. +/// +/// A `Session` manages a connection to a persistent database stored on disk. +/// Unlike stateless queries, sessions allow you to create tables, insert data, +/// and maintain state across multiple queries. +/// +/// # Thread Safety +/// +/// `Session` contains a [`Connection`] which implements +/// `Send`, so sessions can be safely transferred between threads. However, concurrent +/// access to the same session should be synchronized. +/// +/// # Examples +/// +/// ```no_run +/// use chdb_rust::session::SessionBuilder; +/// use chdb_rust::arg::Arg; +/// use chdb_rust::format::OutputFormat; +/// +/// let session = SessionBuilder::new() +/// .with_data_path("/tmp/mydb") +/// .with_auto_cleanup(true) +/// .build()?; +/// +/// // Create a table +/// session.execute( +/// "CREATE TABLE users (id UInt64, name String) ENGINE = MergeTree() ORDER BY id", +/// None +/// )?; +/// +/// // Insert data +/// session.execute("INSERT INTO users VALUES (1, 'Alice')", None)?; +/// +/// // Query data +/// let result = session.execute( +/// "SELECT * FROM users", +/// Some(&[Arg::OutputFormat(OutputFormat::JSONEachRow)]) +/// )?; +/// println!("{}", result.data_utf8_lossy()); +/// # Ok::<(), chdb_rust::error::Error>(()) +/// ``` #[derive(Debug)] pub struct Session { conn: Connection, @@ -23,6 +87,21 @@ pub struct Session { } impl<'a> SessionBuilder<'a> { + /// Create a new `SessionBuilder` with default settings. + /// + /// The default settings are: + /// - Data path: `./chdb` in the current working directory + /// - Output format: `TabSeparated` + /// - Auto cleanup: `false` + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::session::SessionBuilder; + /// + /// let builder = SessionBuilder::new(); + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` pub fn new() -> Self { let mut data_path = std::env::current_dir().unwrap(); data_path.push("chdb"); @@ -35,11 +114,49 @@ impl<'a> SessionBuilder<'a> { } } + /// Set the data path for the session. + /// + /// This specifies the filesystem path where the database will be stored. + /// The directory will be created if it doesn't exist. + /// + /// # Arguments + /// + /// * `path` - The path where the database should be stored + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::session::SessionBuilder; + /// + /// let builder = SessionBuilder::new() + /// .with_data_path("/tmp/mydb"); + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` pub fn with_data_path(mut self, path: impl Into) -> Self { self.data_path = path.into(); self } + /// Add a query argument to the session builder. + /// + /// Currently, only `OutputFormat` arguments are supported and will be used + /// as the default output format for queries executed on this session. + /// + /// # Arguments + /// + /// * `arg` - The argument to add (currently only `OutputFormat` is supported) + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::session::SessionBuilder; + /// use chdb_rust::arg::Arg; + /// use chdb_rust::format::OutputFormat; + /// + /// let builder = SessionBuilder::new() + /// .with_arg(Arg::OutputFormat(OutputFormat::JSONEachRow)); + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` pub fn with_arg(mut self, arg: Arg<'a>) -> Self { // Only OutputFormat is supported with the new API if let Some(fmt) = arg.as_output_format() { @@ -48,12 +165,59 @@ impl<'a> SessionBuilder<'a> { self } - /// If set Session will delete data directory before it is dropped. + /// Enable or disable automatic cleanup of the data directory. + /// + /// If set to `true`, the session will automatically delete the data directory + /// when it is dropped. This is useful for temporary databases. + /// + /// # Arguments + /// + /// * `value` - Whether to enable automatic cleanup + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::session::SessionBuilder; + /// + /// // Session will clean up data directory on drop + /// let session = SessionBuilder::new() + /// .with_data_path("/tmp/tempdb") + /// .with_auto_cleanup(true) + /// .build()?; + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` pub fn with_auto_cleanup(mut self, value: bool) -> Self { self.auto_cleanup = value; self } + /// Build the session with the configured settings. + /// + /// This creates the data directory if it doesn't exist and establishes + /// a connection to the database. + /// + /// # Returns + /// + /// Returns a [`Session`] if successful, or an [`Error`] if + /// the session cannot be created. + /// + /// # Errors + /// + /// Returns an error if: + /// - The data path cannot be created + /// - The data path has insufficient permissions + /// - The connection cannot be established + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::session::SessionBuilder; + /// + /// let session = SessionBuilder::new() + /// .with_data_path("/tmp/mydb") + /// .build()?; + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` pub fn build(self) -> Result { let data_path = self.data_path.to_str().ok_or(Error::PathError)?.to_string(); @@ -80,6 +244,53 @@ impl Default for SessionBuilder<'_> { } impl Session { + /// Execute a query on this session. + /// + /// This executes a SQL query against the database associated with this session. + /// The query can create tables, insert data, or query existing data. + /// + /// # Arguments + /// + /// * `query` - The SQL query string to execute + /// * `query_args` - Optional array of query arguments (e.g., output format) + /// + /// # Returns + /// + /// Returns a [`QueryResult`] containing the query output, + /// or an [`Error`] if the query fails. + /// + /// # Examples + /// + /// ```no_run + /// use chdb_rust::session::SessionBuilder; + /// use chdb_rust::arg::Arg; + /// use chdb_rust::format::OutputFormat; + /// + /// let session = SessionBuilder::new() + /// .with_data_path("/tmp/mydb") + /// .with_auto_cleanup(true) + /// .build()?; + /// + /// // Create a table + /// session.execute( + /// "CREATE TABLE test (id UInt64) ENGINE = MergeTree() ORDER BY id", + /// None + /// )?; + /// + /// // Query with JSON output + /// let result = session.execute( + /// "SELECT * FROM test", + /// Some(&[Arg::OutputFormat(OutputFormat::JSONEachRow)]) + /// )?; + /// # Ok::<(), chdb_rust::error::Error>(()) + /// ``` + /// + /// # Errors + /// + /// Returns an error if: + /// - The query syntax is invalid + /// - The query references non-existent tables or columns + /// - The query execution fails for any other reason pub fn execute(&self, query: &str, query_args: Option<&[Arg]>) -> Result { let fmt = query_args .and_then(|args| args.iter().find_map(|a| a.as_output_format())) From c67498e2e98c7ba0d1de5b34c7f65dc933cd1828 Mon Sep 17 00:00:00 2001 From: Austin Barrington Date: Wed, 31 Dec 2025 10:19:36 +0000 Subject: [PATCH 2/2] revert: revert bindings.rs changes --- src/bindings.rs | 463 +++++++++++++++++++++++++++++++----------------- 1 file changed, 299 insertions(+), 164 deletions(-) diff --git a/src/bindings.rs b/src/bindings.rs index 4f43e8b..8bc2242 100644 --- a/src/bindings.rs +++ b/src/bindings.rs @@ -1,207 +1,341 @@ /* automatically generated by rust-bindgen 0.70.1 */ +pub const __bool_true_false_are_defined: u32 = 1; pub const true_: u32 = 1; pub const false_: u32 = 0; -pub const __bool_true_false_are_defined: u32 = 1; -pub const _STDINT_H: u32 = 1; -pub const _FEATURES_H: u32 = 1; -pub const _DEFAULT_SOURCE: u32 = 1; -pub const __GLIBC_USE_ISOC2X: u32 = 0; -pub const __USE_ISOC11: u32 = 1; -pub const __USE_ISOC99: u32 = 1; -pub const __USE_ISOC95: u32 = 1; -pub const __USE_POSIX_IMPLICITLY: u32 = 1; -pub const _POSIX_SOURCE: u32 = 1; -pub const _POSIX_C_SOURCE: u32 = 200809; -pub const __USE_POSIX: u32 = 1; -pub const __USE_POSIX2: u32 = 1; -pub const __USE_POSIX199309: u32 = 1; -pub const __USE_POSIX199506: u32 = 1; -pub const __USE_XOPEN2K: u32 = 1; -pub const __USE_XOPEN2K8: u32 = 1; -pub const _ATFILE_SOURCE: u32 = 1; -pub const __USE_MISC: u32 = 1; -pub const __USE_ATFILE: u32 = 1; -pub const __USE_FORTIFY_LEVEL: u32 = 0; -pub const __GLIBC_USE_DEPRECATED_GETS: u32 = 0; -pub const __GLIBC_USE_DEPRECATED_SCANF: u32 = 0; -pub const _STDC_PREDEF_H: u32 = 1; -pub const __STDC_IEC_559__: u32 = 1; -pub const __STDC_IEC_559_COMPLEX__: u32 = 1; -pub const __STDC_ISO_10646__: u32 = 201706; -pub const __GNU_LIBRARY__: u32 = 6; -pub const __GLIBC__: u32 = 2; -pub const __GLIBC_MINOR__: u32 = 31; -pub const _SYS_CDEFS_H: u32 = 1; -pub const __glibc_c99_flexarr_available: u32 = 1; pub const __WORDSIZE: u32 = 64; -pub const __WORDSIZE_TIME64_COMPAT32: u32 = 1; -pub const __SYSCALL_WORDSIZE: u32 = 64; -pub const __LONG_DOUBLE_USES_FLOAT128: u32 = 0; -pub const __HAVE_GENERIC_SELECTION: u32 = 1; -pub const __GLIBC_USE_LIB_EXT2: u32 = 0; -pub const __GLIBC_USE_IEC_60559_BFP_EXT: u32 = 0; -pub const __GLIBC_USE_IEC_60559_BFP_EXT_C2X: u32 = 0; -pub const __GLIBC_USE_IEC_60559_FUNCS_EXT: u32 = 0; -pub const __GLIBC_USE_IEC_60559_FUNCS_EXT_C2X: u32 = 0; -pub const __GLIBC_USE_IEC_60559_TYPES_EXT: u32 = 0; -pub const _BITS_TYPES_H: u32 = 1; -pub const __TIMESIZE: u32 = 64; -pub const _BITS_TYPESIZES_H: u32 = 1; -pub const __OFF_T_MATCHES_OFF64_T: u32 = 1; -pub const __INO_T_MATCHES_INO64_T: u32 = 1; -pub const __RLIM_T_MATCHES_RLIM64_T: u32 = 1; -pub const __STATFS_MATCHES_STATFS64: u32 = 1; -pub const __FD_SETSIZE: u32 = 1024; -pub const _BITS_TIME64_H: u32 = 1; -pub const _BITS_WCHAR_H: u32 = 1; -pub const _BITS_STDINT_INTN_H: u32 = 1; -pub const _BITS_STDINT_UINTN_H: u32 = 1; -pub const INT8_MIN: i32 = -128; -pub const INT16_MIN: i32 = -32768; -pub const INT32_MIN: i32 = -2147483648; +pub const __has_safe_buffers: u32 = 1; +pub const __DARWIN_ONLY_64_BIT_INO_T: u32 = 1; +pub const __DARWIN_ONLY_UNIX_CONFORMANCE: u32 = 1; +pub const __DARWIN_ONLY_VERS_1050: u32 = 1; +pub const __DARWIN_UNIX03: u32 = 1; +pub const __DARWIN_64_BIT_INO_T: u32 = 1; +pub const __DARWIN_VERS_1050: u32 = 1; +pub const __DARWIN_NON_CANCELABLE: u32 = 0; +pub const __DARWIN_SUF_EXTSN: &[u8; 14] = b"$DARWIN_EXTSN\0"; +pub const __DARWIN_C_ANSI: u32 = 4096; +pub const __DARWIN_C_FULL: u32 = 900000; +pub const __DARWIN_C_LEVEL: u32 = 900000; +pub const __STDC_WANT_LIB_EXT1__: u32 = 1; +pub const __DARWIN_NO_LONG_LONG: u32 = 0; +pub const _DARWIN_FEATURE_64_BIT_INODE: u32 = 1; +pub const _DARWIN_FEATURE_ONLY_64_BIT_INODE: u32 = 1; +pub const _DARWIN_FEATURE_ONLY_VERS_1050: u32 = 1; +pub const _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE: u32 = 1; +pub const _DARWIN_FEATURE_UNIX_CONFORMANCE: u32 = 3; +pub const __has_ptrcheck: u32 = 0; +pub const USE_CLANG_TYPES: u32 = 0; +pub const __PTHREAD_SIZE__: u32 = 8176; +pub const __PTHREAD_ATTR_SIZE__: u32 = 56; +pub const __PTHREAD_MUTEXATTR_SIZE__: u32 = 8; +pub const __PTHREAD_MUTEX_SIZE__: u32 = 56; +pub const __PTHREAD_CONDATTR_SIZE__: u32 = 8; +pub const __PTHREAD_COND_SIZE__: u32 = 40; +pub const __PTHREAD_ONCE_SIZE__: u32 = 8; +pub const __PTHREAD_RWLOCK_SIZE__: u32 = 192; +pub const __PTHREAD_RWLOCKATTR_SIZE__: u32 = 16; pub const INT8_MAX: u32 = 127; pub const INT16_MAX: u32 = 32767; pub const INT32_MAX: u32 = 2147483647; +pub const INT64_MAX: u64 = 9223372036854775807; +pub const INT8_MIN: i32 = -128; +pub const INT16_MIN: i32 = -32768; +pub const INT32_MIN: i32 = -2147483648; +pub const INT64_MIN: i64 = -9223372036854775808; pub const UINT8_MAX: u32 = 255; pub const UINT16_MAX: u32 = 65535; pub const UINT32_MAX: u32 = 4294967295; +pub const UINT64_MAX: i32 = -1; pub const INT_LEAST8_MIN: i32 = -128; pub const INT_LEAST16_MIN: i32 = -32768; pub const INT_LEAST32_MIN: i32 = -2147483648; +pub const INT_LEAST64_MIN: i64 = -9223372036854775808; pub const INT_LEAST8_MAX: u32 = 127; pub const INT_LEAST16_MAX: u32 = 32767; pub const INT_LEAST32_MAX: u32 = 2147483647; +pub const INT_LEAST64_MAX: u64 = 9223372036854775807; pub const UINT_LEAST8_MAX: u32 = 255; pub const UINT_LEAST16_MAX: u32 = 65535; pub const UINT_LEAST32_MAX: u32 = 4294967295; +pub const UINT_LEAST64_MAX: i32 = -1; pub const INT_FAST8_MIN: i32 = -128; -pub const INT_FAST16_MIN: i64 = -9223372036854775808; -pub const INT_FAST32_MIN: i64 = -9223372036854775808; +pub const INT_FAST16_MIN: i32 = -32768; +pub const INT_FAST32_MIN: i32 = -2147483648; +pub const INT_FAST64_MIN: i64 = -9223372036854775808; pub const INT_FAST8_MAX: u32 = 127; -pub const INT_FAST16_MAX: u64 = 9223372036854775807; -pub const INT_FAST32_MAX: u64 = 9223372036854775807; +pub const INT_FAST16_MAX: u32 = 32767; +pub const INT_FAST32_MAX: u32 = 2147483647; +pub const INT_FAST64_MAX: u64 = 9223372036854775807; pub const UINT_FAST8_MAX: u32 = 255; -pub const UINT_FAST16_MAX: i32 = -1; -pub const UINT_FAST32_MAX: i32 = -1; -pub const INTPTR_MIN: i64 = -9223372036854775808; +pub const UINT_FAST16_MAX: u32 = 65535; +pub const UINT_FAST32_MAX: u32 = 4294967295; +pub const UINT_FAST64_MAX: i32 = -1; pub const INTPTR_MAX: u64 = 9223372036854775807; +pub const INTPTR_MIN: i64 = -9223372036854775808; pub const UINTPTR_MAX: i32 = -1; -pub const PTRDIFF_MIN: i64 = -9223372036854775808; -pub const PTRDIFF_MAX: u64 = 9223372036854775807; +pub const SIZE_MAX: i32 = -1; +pub const RSIZE_MAX: i32 = -1; +pub const WINT_MIN: i32 = -2147483648; +pub const WINT_MAX: u32 = 2147483647; pub const SIG_ATOMIC_MIN: i32 = -2147483648; pub const SIG_ATOMIC_MAX: u32 = 2147483647; -pub const SIZE_MAX: i32 = -1; -pub const WINT_MIN: u32 = 0; -pub const WINT_MAX: u32 = 4294967295; pub type wchar_t = ::std::os::raw::c_int; -#[repr(C)] -#[repr(align(16))] -#[derive(Debug, Copy, Clone)] -pub struct max_align_t { - pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, - pub __bindgen_padding_0: u64, - pub __clang_max_align_nonce2: u128, -} -#[allow(clippy::unnecessary_operation, clippy::identity_op)] -const _: () = { - ["Size of max_align_t"][::std::mem::size_of::() - 32usize]; - ["Alignment of max_align_t"][::std::mem::align_of::() - 16usize]; - ["Offset of field: max_align_t::__clang_max_align_nonce1"] - [::std::mem::offset_of!(max_align_t, __clang_max_align_nonce1) - 0usize]; - ["Offset of field: max_align_t::__clang_max_align_nonce2"] - [::std::mem::offset_of!(max_align_t, __clang_max_align_nonce2) - 16usize]; -}; -pub type __u_char = ::std::os::raw::c_uchar; -pub type __u_short = ::std::os::raw::c_ushort; -pub type __u_int = ::std::os::raw::c_uint; -pub type __u_long = ::std::os::raw::c_ulong; +pub type max_align_t = f64; +pub type int_least8_t = i8; +pub type int_least16_t = i16; +pub type int_least32_t = i32; +pub type int_least64_t = i64; +pub type uint_least8_t = u8; +pub type uint_least16_t = u16; +pub type uint_least32_t = u32; +pub type uint_least64_t = u64; +pub type int_fast8_t = i8; +pub type int_fast16_t = i16; +pub type int_fast32_t = i32; +pub type int_fast64_t = i64; +pub type uint_fast8_t = u8; +pub type uint_fast16_t = u16; +pub type uint_fast32_t = u32; +pub type uint_fast64_t = u64; pub type __int8_t = ::std::os::raw::c_schar; pub type __uint8_t = ::std::os::raw::c_uchar; pub type __int16_t = ::std::os::raw::c_short; pub type __uint16_t = ::std::os::raw::c_ushort; pub type __int32_t = ::std::os::raw::c_int; pub type __uint32_t = ::std::os::raw::c_uint; -pub type __int64_t = ::std::os::raw::c_long; -pub type __uint64_t = ::std::os::raw::c_ulong; -pub type __int_least8_t = __int8_t; -pub type __uint_least8_t = __uint8_t; -pub type __int_least16_t = __int16_t; -pub type __uint_least16_t = __uint16_t; -pub type __int_least32_t = __int32_t; -pub type __uint_least32_t = __uint32_t; -pub type __int_least64_t = __int64_t; -pub type __uint_least64_t = __uint64_t; -pub type __quad_t = ::std::os::raw::c_long; -pub type __u_quad_t = ::std::os::raw::c_ulong; -pub type __intmax_t = ::std::os::raw::c_long; -pub type __uintmax_t = ::std::os::raw::c_ulong; -pub type __dev_t = ::std::os::raw::c_ulong; -pub type __uid_t = ::std::os::raw::c_uint; -pub type __gid_t = ::std::os::raw::c_uint; -pub type __ino_t = ::std::os::raw::c_ulong; -pub type __ino64_t = ::std::os::raw::c_ulong; -pub type __mode_t = ::std::os::raw::c_uint; -pub type __nlink_t = ::std::os::raw::c_ulong; -pub type __off_t = ::std::os::raw::c_long; -pub type __off64_t = ::std::os::raw::c_long; -pub type __pid_t = ::std::os::raw::c_int; +pub type __int64_t = ::std::os::raw::c_longlong; +pub type __uint64_t = ::std::os::raw::c_ulonglong; +pub type __darwin_intptr_t = ::std::os::raw::c_long; +pub type __darwin_natural_t = ::std::os::raw::c_uint; +pub type __darwin_ct_rune_t = ::std::os::raw::c_int; +#[repr(C)] +#[derive(Copy, Clone)] +pub union __mbstate_t { + pub __mbstate8: [::std::os::raw::c_char; 128usize], + pub _mbstateL: ::std::os::raw::c_longlong, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of __mbstate_t"][::std::mem::size_of::<__mbstate_t>() - 128usize]; + ["Alignment of __mbstate_t"][::std::mem::align_of::<__mbstate_t>() - 8usize]; + ["Offset of field: __mbstate_t::__mbstate8"] + [::std::mem::offset_of!(__mbstate_t, __mbstate8) - 0usize]; + ["Offset of field: __mbstate_t::_mbstateL"] + [::std::mem::offset_of!(__mbstate_t, _mbstateL) - 0usize]; +}; +pub type __darwin_mbstate_t = __mbstate_t; +pub type __darwin_ptrdiff_t = ::std::os::raw::c_long; +pub type __darwin_size_t = ::std::os::raw::c_ulong; +pub type __darwin_va_list = __builtin_va_list; +pub type __darwin_wchar_t = ::std::os::raw::c_int; +pub type __darwin_rune_t = __darwin_wchar_t; +pub type __darwin_wint_t = ::std::os::raw::c_int; +pub type __darwin_clock_t = ::std::os::raw::c_ulong; +pub type __darwin_socklen_t = __uint32_t; +pub type __darwin_ssize_t = ::std::os::raw::c_long; +pub type __darwin_time_t = ::std::os::raw::c_long; +pub type __darwin_blkcnt_t = __int64_t; +pub type __darwin_blksize_t = __int32_t; +pub type __darwin_dev_t = __int32_t; +pub type __darwin_fsblkcnt_t = ::std::os::raw::c_uint; +pub type __darwin_fsfilcnt_t = ::std::os::raw::c_uint; +pub type __darwin_gid_t = __uint32_t; +pub type __darwin_id_t = __uint32_t; +pub type __darwin_ino64_t = __uint64_t; +pub type __darwin_ino_t = __darwin_ino64_t; +pub type __darwin_mach_port_name_t = __darwin_natural_t; +pub type __darwin_mach_port_t = __darwin_mach_port_name_t; +pub type __darwin_mode_t = __uint16_t; +pub type __darwin_off_t = __int64_t; +pub type __darwin_pid_t = __int32_t; +pub type __darwin_sigset_t = __uint32_t; +pub type __darwin_suseconds_t = __int32_t; +pub type __darwin_uid_t = __uint32_t; +pub type __darwin_useconds_t = __uint32_t; +pub type __darwin_uuid_t = [::std::os::raw::c_uchar; 16usize]; +pub type __darwin_uuid_string_t = [::std::os::raw::c_char; 37usize]; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __darwin_pthread_handler_rec { + pub __routine: ::std::option::Option, + pub __arg: *mut ::std::os::raw::c_void, + pub __next: *mut __darwin_pthread_handler_rec, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of __darwin_pthread_handler_rec"] + [::std::mem::size_of::<__darwin_pthread_handler_rec>() - 24usize]; + ["Alignment of __darwin_pthread_handler_rec"] + [::std::mem::align_of::<__darwin_pthread_handler_rec>() - 8usize]; + ["Offset of field: __darwin_pthread_handler_rec::__routine"] + [::std::mem::offset_of!(__darwin_pthread_handler_rec, __routine) - 0usize]; + ["Offset of field: __darwin_pthread_handler_rec::__arg"] + [::std::mem::offset_of!(__darwin_pthread_handler_rec, __arg) - 8usize]; + ["Offset of field: __darwin_pthread_handler_rec::__next"] + [::std::mem::offset_of!(__darwin_pthread_handler_rec, __next) - 16usize]; +}; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _opaque_pthread_attr_t { + pub __sig: ::std::os::raw::c_long, + pub __opaque: [::std::os::raw::c_char; 56usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _opaque_pthread_attr_t"][::std::mem::size_of::<_opaque_pthread_attr_t>() - 64usize]; + ["Alignment of _opaque_pthread_attr_t"] + [::std::mem::align_of::<_opaque_pthread_attr_t>() - 8usize]; + ["Offset of field: _opaque_pthread_attr_t::__sig"] + [::std::mem::offset_of!(_opaque_pthread_attr_t, __sig) - 0usize]; + ["Offset of field: _opaque_pthread_attr_t::__opaque"] + [::std::mem::offset_of!(_opaque_pthread_attr_t, __opaque) - 8usize]; +}; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _opaque_pthread_cond_t { + pub __sig: ::std::os::raw::c_long, + pub __opaque: [::std::os::raw::c_char; 40usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _opaque_pthread_cond_t"][::std::mem::size_of::<_opaque_pthread_cond_t>() - 48usize]; + ["Alignment of _opaque_pthread_cond_t"] + [::std::mem::align_of::<_opaque_pthread_cond_t>() - 8usize]; + ["Offset of field: _opaque_pthread_cond_t::__sig"] + [::std::mem::offset_of!(_opaque_pthread_cond_t, __sig) - 0usize]; + ["Offset of field: _opaque_pthread_cond_t::__opaque"] + [::std::mem::offset_of!(_opaque_pthread_cond_t, __opaque) - 8usize]; +}; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _opaque_pthread_condattr_t { + pub __sig: ::std::os::raw::c_long, + pub __opaque: [::std::os::raw::c_char; 8usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _opaque_pthread_condattr_t"] + [::std::mem::size_of::<_opaque_pthread_condattr_t>() - 16usize]; + ["Alignment of _opaque_pthread_condattr_t"] + [::std::mem::align_of::<_opaque_pthread_condattr_t>() - 8usize]; + ["Offset of field: _opaque_pthread_condattr_t::__sig"] + [::std::mem::offset_of!(_opaque_pthread_condattr_t, __sig) - 0usize]; + ["Offset of field: _opaque_pthread_condattr_t::__opaque"] + [::std::mem::offset_of!(_opaque_pthread_condattr_t, __opaque) - 8usize]; +}; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _opaque_pthread_mutex_t { + pub __sig: ::std::os::raw::c_long, + pub __opaque: [::std::os::raw::c_char; 56usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _opaque_pthread_mutex_t"][::std::mem::size_of::<_opaque_pthread_mutex_t>() - 64usize]; + ["Alignment of _opaque_pthread_mutex_t"] + [::std::mem::align_of::<_opaque_pthread_mutex_t>() - 8usize]; + ["Offset of field: _opaque_pthread_mutex_t::__sig"] + [::std::mem::offset_of!(_opaque_pthread_mutex_t, __sig) - 0usize]; + ["Offset of field: _opaque_pthread_mutex_t::__opaque"] + [::std::mem::offset_of!(_opaque_pthread_mutex_t, __opaque) - 8usize]; +}; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _opaque_pthread_mutexattr_t { + pub __sig: ::std::os::raw::c_long, + pub __opaque: [::std::os::raw::c_char; 8usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _opaque_pthread_mutexattr_t"] + [::std::mem::size_of::<_opaque_pthread_mutexattr_t>() - 16usize]; + ["Alignment of _opaque_pthread_mutexattr_t"] + [::std::mem::align_of::<_opaque_pthread_mutexattr_t>() - 8usize]; + ["Offset of field: _opaque_pthread_mutexattr_t::__sig"] + [::std::mem::offset_of!(_opaque_pthread_mutexattr_t, __sig) - 0usize]; + ["Offset of field: _opaque_pthread_mutexattr_t::__opaque"] + [::std::mem::offset_of!(_opaque_pthread_mutexattr_t, __opaque) - 8usize]; +}; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _opaque_pthread_once_t { + pub __sig: ::std::os::raw::c_long, + pub __opaque: [::std::os::raw::c_char; 8usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _opaque_pthread_once_t"][::std::mem::size_of::<_opaque_pthread_once_t>() - 16usize]; + ["Alignment of _opaque_pthread_once_t"] + [::std::mem::align_of::<_opaque_pthread_once_t>() - 8usize]; + ["Offset of field: _opaque_pthread_once_t::__sig"] + [::std::mem::offset_of!(_opaque_pthread_once_t, __sig) - 0usize]; + ["Offset of field: _opaque_pthread_once_t::__opaque"] + [::std::mem::offset_of!(_opaque_pthread_once_t, __opaque) - 8usize]; +}; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _opaque_pthread_rwlock_t { + pub __sig: ::std::os::raw::c_long, + pub __opaque: [::std::os::raw::c_char; 192usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _opaque_pthread_rwlock_t"] + [::std::mem::size_of::<_opaque_pthread_rwlock_t>() - 200usize]; + ["Alignment of _opaque_pthread_rwlock_t"] + [::std::mem::align_of::<_opaque_pthread_rwlock_t>() - 8usize]; + ["Offset of field: _opaque_pthread_rwlock_t::__sig"] + [::std::mem::offset_of!(_opaque_pthread_rwlock_t, __sig) - 0usize]; + ["Offset of field: _opaque_pthread_rwlock_t::__opaque"] + [::std::mem::offset_of!(_opaque_pthread_rwlock_t, __opaque) - 8usize]; +}; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _opaque_pthread_rwlockattr_t { + pub __sig: ::std::os::raw::c_long, + pub __opaque: [::std::os::raw::c_char; 16usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _opaque_pthread_rwlockattr_t"] + [::std::mem::size_of::<_opaque_pthread_rwlockattr_t>() - 24usize]; + ["Alignment of _opaque_pthread_rwlockattr_t"] + [::std::mem::align_of::<_opaque_pthread_rwlockattr_t>() - 8usize]; + ["Offset of field: _opaque_pthread_rwlockattr_t::__sig"] + [::std::mem::offset_of!(_opaque_pthread_rwlockattr_t, __sig) - 0usize]; + ["Offset of field: _opaque_pthread_rwlockattr_t::__opaque"] + [::std::mem::offset_of!(_opaque_pthread_rwlockattr_t, __opaque) - 8usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct __fsid_t { - pub __val: [::std::os::raw::c_int; 2usize], +pub struct _opaque_pthread_t { + pub __sig: ::std::os::raw::c_long, + pub __cleanup_stack: *mut __darwin_pthread_handler_rec, + pub __opaque: [::std::os::raw::c_char; 8176usize], } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { - ["Size of __fsid_t"][::std::mem::size_of::<__fsid_t>() - 8usize]; - ["Alignment of __fsid_t"][::std::mem::align_of::<__fsid_t>() - 4usize]; - ["Offset of field: __fsid_t::__val"][::std::mem::offset_of!(__fsid_t, __val) - 0usize]; + ["Size of _opaque_pthread_t"][::std::mem::size_of::<_opaque_pthread_t>() - 8192usize]; + ["Alignment of _opaque_pthread_t"][::std::mem::align_of::<_opaque_pthread_t>() - 8usize]; + ["Offset of field: _opaque_pthread_t::__sig"] + [::std::mem::offset_of!(_opaque_pthread_t, __sig) - 0usize]; + ["Offset of field: _opaque_pthread_t::__cleanup_stack"] + [::std::mem::offset_of!(_opaque_pthread_t, __cleanup_stack) - 8usize]; + ["Offset of field: _opaque_pthread_t::__opaque"] + [::std::mem::offset_of!(_opaque_pthread_t, __opaque) - 16usize]; }; -pub type __clock_t = ::std::os::raw::c_long; -pub type __rlim_t = ::std::os::raw::c_ulong; -pub type __rlim64_t = ::std::os::raw::c_ulong; -pub type __id_t = ::std::os::raw::c_uint; -pub type __time_t = ::std::os::raw::c_long; -pub type __useconds_t = ::std::os::raw::c_uint; -pub type __suseconds_t = ::std::os::raw::c_long; -pub type __daddr_t = ::std::os::raw::c_int; -pub type __key_t = ::std::os::raw::c_int; -pub type __clockid_t = ::std::os::raw::c_int; -pub type __timer_t = *mut ::std::os::raw::c_void; -pub type __blksize_t = ::std::os::raw::c_long; -pub type __blkcnt_t = ::std::os::raw::c_long; -pub type __blkcnt64_t = ::std::os::raw::c_long; -pub type __fsblkcnt_t = ::std::os::raw::c_ulong; -pub type __fsblkcnt64_t = ::std::os::raw::c_ulong; -pub type __fsfilcnt_t = ::std::os::raw::c_ulong; -pub type __fsfilcnt64_t = ::std::os::raw::c_ulong; -pub type __fsword_t = ::std::os::raw::c_long; -pub type __ssize_t = ::std::os::raw::c_long; -pub type __syscall_slong_t = ::std::os::raw::c_long; -pub type __syscall_ulong_t = ::std::os::raw::c_ulong; -pub type __loff_t = __off64_t; -pub type __caddr_t = *mut ::std::os::raw::c_char; -pub type __intptr_t = ::std::os::raw::c_long; -pub type __socklen_t = ::std::os::raw::c_uint; -pub type __sig_atomic_t = ::std::os::raw::c_int; -pub type int_least8_t = __int_least8_t; -pub type int_least16_t = __int_least16_t; -pub type int_least32_t = __int_least32_t; -pub type int_least64_t = __int_least64_t; -pub type uint_least8_t = __uint_least8_t; -pub type uint_least16_t = __uint_least16_t; -pub type uint_least32_t = __uint_least32_t; -pub type uint_least64_t = __uint_least64_t; -pub type int_fast8_t = ::std::os::raw::c_schar; -pub type int_fast16_t = ::std::os::raw::c_long; -pub type int_fast32_t = ::std::os::raw::c_long; -pub type int_fast64_t = ::std::os::raw::c_long; -pub type uint_fast8_t = ::std::os::raw::c_uchar; -pub type uint_fast16_t = ::std::os::raw::c_ulong; -pub type uint_fast32_t = ::std::os::raw::c_ulong; -pub type uint_fast64_t = ::std::os::raw::c_ulong; -pub type intmax_t = __intmax_t; -pub type uintmax_t = __uintmax_t; +pub type __darwin_pthread_attr_t = _opaque_pthread_attr_t; +pub type __darwin_pthread_cond_t = _opaque_pthread_cond_t; +pub type __darwin_pthread_condattr_t = _opaque_pthread_condattr_t; +pub type __darwin_pthread_key_t = ::std::os::raw::c_ulong; +pub type __darwin_pthread_mutex_t = _opaque_pthread_mutex_t; +pub type __darwin_pthread_mutexattr_t = _opaque_pthread_mutexattr_t; +pub type __darwin_pthread_once_t = _opaque_pthread_once_t; +pub type __darwin_pthread_rwlock_t = _opaque_pthread_rwlock_t; +pub type __darwin_pthread_rwlockattr_t = _opaque_pthread_rwlockattr_t; +pub type __darwin_pthread_t = *mut _opaque_pthread_t; +pub type intmax_t = ::std::os::raw::c_long; +pub type uintmax_t = ::std::os::raw::c_ulong; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct local_result { @@ -565,3 +699,4 @@ extern "C" { table_name: *const ::std::os::raw::c_char, ) -> chdb_state; } +pub type __builtin_va_list = *mut ::std::os::raw::c_char;