-
Notifications
You must be signed in to change notification settings - Fork 487
Expand file tree
/
Copy pathtypes.rs
More file actions
351 lines (293 loc) · 7.57 KB
/
types.rs
File metadata and controls
351 lines (293 loc) · 7.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
pub const LIBSQL_INT: i8 = 1;
pub const LIBSQL_FLOAT: i8 = 2;
pub const LIBSQL_TEXT: i8 = 3;
pub const LIBSQL_BLOB: i8 = 4;
pub const LIBSQL_NULL: i8 = 5;
#[derive(Clone, Debug)]
#[repr(C)]
pub struct libsql_config {
pub db_path: *const std::ffi::c_char,
pub primary_url: *const std::ffi::c_char,
pub auth_token: *const std::ffi::c_char,
pub read_your_writes: std::ffi::c_char,
pub encryption_key: *const std::ffi::c_char,
pub sync_interval: std::ffi::c_int,
pub with_webpki: std::ffi::c_char,
pub offline: std::ffi::c_char,
pub remote_encryption_key: *const std::ffi::c_char,
}
#[derive(Clone, Debug)]
#[repr(C)]
pub struct blob {
pub ptr: *const std::ffi::c_char,
pub len: std::ffi::c_int,
}
pub struct libsql_database {
pub(crate) db: libsql::Database,
}
#[derive(Clone, Debug)]
#[repr(transparent)]
pub struct libsql_database_t {
ptr: *const libsql_database,
}
impl libsql_database_t {
pub fn null() -> libsql_database_t {
libsql_database_t {
ptr: std::ptr::null(),
}
}
pub fn is_null(&self) -> bool {
self.ptr.is_null()
}
pub fn get_ref(&self) -> &libsql::Database {
&unsafe { &*(self.ptr) }.db
}
#[allow(clippy::mut_from_ref)]
pub fn get_ref_mut(&self) -> &mut libsql::Database {
let ptr_mut = self.ptr as *mut libsql_database;
&mut unsafe { &mut (*ptr_mut) }.db
}
}
#[allow(clippy::from_over_into)]
impl From<&libsql_database> for libsql_database_t {
fn from(value: &libsql_database) -> Self {
Self { ptr: value }
}
}
#[allow(clippy::from_over_into)]
impl From<&mut libsql_database> for libsql_database_t {
fn from(value: &mut libsql_database) -> Self {
Self { ptr: value }
}
}
pub struct libsql_connection {
pub(crate) conn: libsql::Connection,
}
#[derive(Clone, Debug)]
#[repr(transparent)]
pub struct libsql_connection_t {
ptr: *const libsql_connection,
}
impl libsql_connection_t {
pub fn null() -> libsql_connection_t {
libsql_connection_t {
ptr: std::ptr::null(),
}
}
pub fn is_null(&self) -> bool {
self.ptr.is_null()
}
pub fn get_ref(&self) -> &libsql::Connection {
&unsafe { &*(self.ptr) }.conn
}
#[allow(clippy::mut_from_ref)]
pub fn get_ref_mut(&self) -> &mut libsql::Connection {
let ptr_mut = self.ptr as *mut libsql_connection;
&mut unsafe { &mut (*ptr_mut) }.conn
}
}
#[allow(clippy::from_over_into)]
impl From<&libsql_connection> for libsql_connection_t {
fn from(value: &libsql_connection) -> Self {
Self { ptr: value }
}
}
#[allow(clippy::from_over_into)]
impl From<&mut libsql_connection> for libsql_connection_t {
fn from(value: &mut libsql_connection) -> Self {
Self { ptr: value }
}
}
#[repr(C)]
pub struct replicated {
pub frame_no: std::ffi::c_int,
pub frames_synced: std::ffi::c_int,
}
pub struct stmt {
pub stmt: libsql::Statement,
pub params: Vec<libsql::Value>,
}
pub struct libsql_stmt {
pub stmt: stmt,
}
#[derive(Clone, Debug)]
#[repr(transparent)]
pub struct libsql_stmt_t {
ptr: *const libsql_stmt,
}
impl libsql_stmt_t {
pub fn null() -> libsql_stmt_t {
libsql_stmt_t {
ptr: std::ptr::null(),
}
}
pub fn is_null(&self) -> bool {
self.ptr.is_null()
}
pub fn get_ref(&self) -> &stmt {
&unsafe { &*self.ptr }.stmt
}
#[allow(clippy::mut_from_ref)]
pub fn get_ref_mut(&self) -> &mut stmt {
let ptr_mut = self.ptr as *mut libsql_stmt;
&mut unsafe { &mut (*ptr_mut) }.stmt
}
}
#[allow(clippy::from_over_into)]
impl From<&libsql_stmt> for libsql_stmt_t {
fn from(value: &libsql_stmt) -> Self {
Self { ptr: value }
}
}
#[allow(clippy::from_over_into)]
impl From<&mut libsql_stmt> for libsql_stmt_t {
fn from(value: &mut libsql_stmt) -> Self {
Self { ptr: value }
}
}
pub struct libsql_rows {
pub(crate) result: libsql::Rows,
}
#[derive(Clone, Debug)]
#[repr(transparent)]
pub struct libsql_rows_t {
ptr: *const libsql_rows,
}
impl libsql_rows_t {
pub fn null() -> libsql_rows_t {
libsql_rows_t {
ptr: std::ptr::null(),
}
}
pub fn is_null(&self) -> bool {
self.ptr.is_null()
}
pub fn get_ref(&self) -> &libsql::Rows {
&unsafe { &*(self.ptr) }.result
}
#[allow(clippy::mut_from_ref)]
pub fn get_ref_mut(&self) -> &mut libsql::Rows {
let ptr_mut = self.ptr as *mut libsql_rows;
&mut unsafe { &mut (*ptr_mut) }.result
}
}
#[allow(clippy::from_over_into)]
impl From<&libsql_rows> for libsql_rows_t {
fn from(value: &libsql_rows) -> Self {
Self { ptr: value }
}
}
#[allow(clippy::from_over_into)]
impl From<&mut libsql_rows> for libsql_rows_t {
fn from(value: &mut libsql_rows) -> Self {
Self { ptr: value }
}
}
pub struct libsql_rows_future {
pub(crate) result: libsql::RowsFuture,
}
#[derive(Clone, Debug)]
#[repr(transparent)]
pub struct libsql_rows_future_t {
ptr: *const libsql_rows_future,
}
impl libsql_rows_future_t {
pub fn null() -> libsql_rows_future_t {
libsql_rows_future_t {
ptr: std::ptr::null(),
}
}
pub fn is_null(&self) -> bool {
self.ptr.is_null()
}
pub fn get_ref(&self) -> &libsql::RowsFuture {
&unsafe { &*(self.ptr) }.result
}
#[allow(clippy::mut_from_ref)]
pub fn get_ref_mut(&self) -> &mut libsql::RowsFuture {
let ptr_mut = self.ptr as *mut libsql_rows_future;
&mut unsafe { &mut (*ptr_mut) }.result
}
}
#[allow(clippy::from_over_into)]
impl From<&libsql_rows_future> for libsql_rows_future_t {
fn from(value: &libsql_rows_future) -> Self {
Self { ptr: value }
}
}
#[allow(clippy::from_over_into)]
impl From<&mut libsql_rows_future> for libsql_rows_future_t {
fn from(value: &mut libsql_rows_future) -> Self {
Self { ptr: value }
}
}
pub struct libsql_row {
pub(crate) result: libsql::Row,
}
#[derive(Clone, Debug)]
#[repr(transparent)]
pub struct libsql_row_t {
ptr: *const libsql_row,
}
impl libsql_row_t {
pub fn null() -> libsql_row_t {
libsql_row_t {
ptr: std::ptr::null(),
}
}
pub fn is_null(&self) -> bool {
self.ptr.is_null()
}
pub fn get_ref(&self) -> &libsql::Row {
&unsafe { &*(self.ptr) }.result
}
#[allow(clippy::mut_from_ref)]
pub fn get_ref_mut(&self) -> &mut libsql::Row {
let ptr_mut = self.ptr as *mut libsql_row;
&mut unsafe { &mut (*ptr_mut) }.result
}
}
impl From<&libsql_row> for libsql_row_t {
fn from(value: &libsql_row) -> Self {
Self { ptr: value }
}
}
impl From<&mut libsql_row> for libsql_row_t {
fn from(value: &mut libsql_row) -> Self {
Self { ptr: value }
}
}
pub struct libsql_tx {
pub(crate) tx: Option<libsql::Transaction>,
}
#[derive(Clone, Debug)]
#[repr(transparent)]
pub struct libsql_tx_t {
ptr: *const libsql_tx,
}
impl libsql_tx_t {
pub fn null() -> libsql_tx_t {
libsql_tx_t {
ptr: std::ptr::null(),
}
}
pub fn is_null(&self) -> bool {
self.ptr.is_null()
}
#[inline]
pub(crate) fn as_const_ptr(&self) -> *const libsql_tx {
self.ptr
}
}
#[allow(clippy::from_over_into)]
impl From<&libsql_tx> for libsql_tx_t {
fn from(value: &libsql_tx) -> Self {
Self { ptr: value }
}
}
#[allow(clippy::from_over_into)]
impl From<&mut libsql_tx> for libsql_tx_t {
fn from(value: &mut libsql_tx) -> Self {
Self { ptr: value }
}
}