duckdb 0.3.1.0 → 0.3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test_on_macos.yml +31 -9
- data/.github/workflows/test_on_ubuntu.yml +11 -3
- data/.github/workflows/test_on_windows.yml +16 -7
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +4 -3
- data/README.md +32 -3
- data/ext/duckdb/appender.c +7 -59
- data/ext/duckdb/appender.h +0 -5
- data/ext/duckdb/blob.c +1 -5
- data/ext/duckdb/blob.h +0 -4
- data/ext/duckdb/column.c +73 -0
- data/ext/duckdb/column.h +14 -0
- data/ext/duckdb/config.c +2 -4
- data/ext/duckdb/connection.c +2 -3
- data/ext/duckdb/duckdb.c +2 -11
- data/ext/duckdb/error.c +1 -2
- data/ext/duckdb/extconf.rb +17 -21
- data/ext/duckdb/prepared_statement.c +100 -46
- data/ext/duckdb/result.c +51 -20
- data/ext/duckdb/ruby-duckdb.h +7 -20
- data/ext/duckdb/util.c +45 -0
- data/ext/duckdb/util.h +13 -0
- data/lib/duckdb/appender.rb +207 -261
- data/lib/duckdb/column.rb +55 -0
- data/lib/duckdb/config.rb +1 -4
- data/lib/duckdb/converter.rb +52 -0
- data/lib/duckdb/prepared_statement.rb +111 -8
- data/lib/duckdb/version.rb +1 -1
- data/lib/duckdb.rb +2 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09a5bd2bc1a410ea68f8a3d0656c60c7048e24bbfc6406b1da5b51e3593a35e8'
|
4
|
+
data.tar.gz: 66cf129bde28b1473254d974bab4090cb738c01e7e0870b511bae82adaa9a2c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 651bc7aa40359762327e1f4f104662808a2d6c9c2bfef4aadbe3707a2f2a824bff50d8c21d302549c69e5ebd26f9a32cba457015a2903eeba85adf1487b73e43
|
7
|
+
data.tar.gz: e36ce93b343c03daff66023fc3971379ccbcfa2488c1f23b028ef18b905d62d3ca6619e389e0619e50b958015f9330a508b27e6263458b28694a78bd3c9c0b98
|
@@ -1,14 +1,22 @@
|
|
1
1
|
name: MacOS
|
2
2
|
|
3
|
-
on:
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
types:
|
9
|
+
- opened
|
10
|
+
- synchronize
|
11
|
+
- reopened
|
4
12
|
|
5
13
|
jobs:
|
6
14
|
build:
|
7
15
|
runs-on: macos-latest
|
8
16
|
strategy:
|
9
17
|
matrix:
|
10
|
-
ruby: ['2.6.
|
11
|
-
duckdb: ['0.3.
|
18
|
+
ruby: ['2.6.10', '2.7.6', '3.0.4', '3.1.2', 'head']
|
19
|
+
duckdb: ['0.3.2', '0.3.4']
|
12
20
|
|
13
21
|
steps:
|
14
22
|
- uses: actions/checkout@v2
|
@@ -18,17 +26,31 @@ jobs:
|
|
18
26
|
with:
|
19
27
|
ruby-version: ${{ matrix.ruby }}
|
20
28
|
|
21
|
-
- name:
|
29
|
+
- name: duckdb cache
|
30
|
+
id: duckdb-cache
|
31
|
+
uses: actions/cache@v2
|
32
|
+
with:
|
33
|
+
path: duckdb-v${{ matrix.duckdb }}
|
34
|
+
key: ${{ runner.os }}-duckdb-v${{ matrix.duckdb }}
|
35
|
+
|
36
|
+
- name: Build duckdb ${{ matrix.duckdb }}
|
22
37
|
env:
|
23
38
|
DUCKDB_VERSION: ${{ matrix.duckdb }}
|
39
|
+
if: steps.duckdb-cache.outputs.cache-hit != 'true'
|
24
40
|
run: |
|
25
|
-
|
41
|
+
git clone -b v$DUCKDB_VERSION https://github.com/cwida/duckdb.git duckdb-tmp-v$DUCKDB_VERSION
|
42
|
+
cd duckdb-tmp-v$DUCKDB_VERSION && make && cd ..
|
43
|
+
rm -rf duckdb-v$DUCKDB_VERSION
|
44
|
+
mkdir -p duckdb-v$DUCKDB_VERSION/build/release/src duckdb-v$DUCKDB_VERSION/src
|
45
|
+
cp -rip duckdb-tmp-v$DUCKDB_VERSION/build/release/src/*.dylib duckdb-v$DUCKDB_VERSION/build/release/src
|
46
|
+
cp -rip duckdb-tmp-v$DUCKDB_VERSION/src/include duckdb-v$DUCKDB_VERSION/src/
|
26
47
|
|
27
|
-
- name:
|
48
|
+
- name: prepare duckdb header and libraries
|
49
|
+
env:
|
50
|
+
DUCKDB_VERSION: ${{ matrix.duckdb }}
|
28
51
|
run: |
|
29
|
-
|
30
|
-
cp duckdb
|
31
|
-
cp libduckdb.dylib /usr/local/lib
|
52
|
+
cp duckdb-v$DUCKDB_VERSION/src/include/*.h /usr/local/include
|
53
|
+
cp duckdb-v$DUCKDB_VERSION/build/release/src/*.dylib /usr/local/lib
|
32
54
|
|
33
55
|
- name: Build and test with Rake with Ruby ${{ matrix.ruby }}
|
34
56
|
run: |
|
@@ -1,6 +1,14 @@
|
|
1
1
|
name: Ubuntu
|
2
2
|
|
3
|
-
on:
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
types:
|
9
|
+
- opened
|
10
|
+
- synchronize
|
11
|
+
- reopened
|
4
12
|
|
5
13
|
jobs:
|
6
14
|
build:
|
@@ -8,8 +16,8 @@ jobs:
|
|
8
16
|
runs-on: ubuntu-latest
|
9
17
|
strategy:
|
10
18
|
matrix:
|
11
|
-
ruby: ['2.6.
|
12
|
-
duckdb: ['0.3.
|
19
|
+
ruby: ['2.6.10', '2.7.6', '3.0.4', '3.1.2', 'head']
|
20
|
+
duckdb: ['0.3.2', '0.3.4']
|
13
21
|
|
14
22
|
steps:
|
15
23
|
- uses: actions/checkout@v2
|
@@ -1,14 +1,22 @@
|
|
1
1
|
name: Windows
|
2
2
|
|
3
|
-
on:
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
types:
|
9
|
+
- opened
|
10
|
+
- synchronize
|
11
|
+
- reopened
|
4
12
|
|
5
13
|
jobs:
|
6
14
|
build:
|
7
15
|
runs-on: windows-latest
|
8
16
|
strategy:
|
9
17
|
matrix:
|
10
|
-
ruby: ['2.6.
|
11
|
-
duckdb: ['0.3.
|
18
|
+
ruby: ['2.6.10', '2.7.6', '3.0.4', '3.1.2', 'mingw', 'head']
|
19
|
+
duckdb: ['0.3.2', '0.3.4']
|
12
20
|
|
13
21
|
steps:
|
14
22
|
- uses: actions/checkout@v2
|
@@ -26,15 +34,16 @@ jobs:
|
|
26
34
|
|
27
35
|
- name: extract zip file
|
28
36
|
run: |
|
29
|
-
|
37
|
+
unzip libduckdb-windows-amd64.zip
|
38
|
+
|
39
|
+
- name: setup duckdb.dll
|
40
|
+
run: |
|
41
|
+
cp duckdb.dll C:/Windows/System32/
|
30
42
|
|
31
43
|
- name: Build with Rake with Ruby ${{ matrix.ruby }}
|
32
44
|
run: |
|
33
45
|
bundle install
|
34
46
|
bundle exec rake build -- --with-duckdb-include=../../../.. --with-duckdb-lib=../../../..
|
35
|
-
- name: setup duckdb.dll
|
36
|
-
run: |
|
37
|
-
cp duckdb.dll C:/Windows/System32/
|
38
47
|
|
39
48
|
- name: rake test
|
40
49
|
run: |
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# ChangeLog
|
2
2
|
|
3
|
+
# 0.3.4.0
|
4
|
+
- bump duckdb 0.3.4
|
5
|
+
|
6
|
+
# 0.3.3.0
|
7
|
+
- DuckDB::Column#type supports :decimal.
|
8
|
+
- bump duckdb 0.3.3.
|
9
|
+
- bump Ruby 2.6.10, 2.7.6, 3.0.4, 3.1.2.
|
10
|
+
|
11
|
+
# 0.3.2.0
|
12
|
+
|
13
|
+
- bind_time, bind_timestamp, bind_date, bind_timeinterval to DuckDB::PreparedStatement
|
14
|
+
- bump duckdb 0.3.2
|
15
|
+
- bump Ruby 3.1.1, add Ruby mingw in CI.
|
16
|
+
- bump Ruby 2.6.9, 2.7.5, 3.0.3 in CI.
|
17
|
+
|
18
|
+
## BREAKING CHANGE
|
19
|
+
- drop duckdb <= 0.2.8
|
20
|
+
|
3
21
|
# 0.3.1.0
|
4
22
|
|
5
23
|
- bump duckdb to 0.3.1 in CI.
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
duckdb (0.3.
|
4
|
+
duckdb (0.3.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
minitest (5.
|
9
|
+
minitest (5.15.0)
|
10
10
|
rake (13.0.6)
|
11
|
-
rake-compiler (1.
|
11
|
+
rake-compiler (1.2.0)
|
12
12
|
rake
|
13
13
|
|
14
14
|
PLATFORMS
|
15
|
+
ruby
|
15
16
|
x86_64-linux
|
16
17
|
|
17
18
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# ruby-duckdb
|
2
2
|
|
3
|
-
[![](https://github.com/suketa/ruby-duckdb/workflows/Ubuntu/badge.svg)](https://github.com/suketa/ruby-duckdb/actions?query=workflow%3AUbuntu)
|
4
|
-
[![](https://github.com/suketa/ruby-duckdb/workflows/MacOS/badge.svg)](https://github.com/suketa/ruby-duckdb/actions?query=workflow%3AMacOS)
|
5
|
-
[![](https://github.com/suketa/ruby-duckdb/workflows/Windows/badge.svg)](https://github.com/suketa/ruby-duckdb/actions?query=workflow%3AWindows)
|
3
|
+
[![Ubuntu](https://github.com/suketa/ruby-duckdb/workflows/Ubuntu/badge.svg)](https://github.com/suketa/ruby-duckdb/actions?query=workflow%3AUbuntu)
|
4
|
+
[![MacOS](https://github.com/suketa/ruby-duckdb/workflows/MacOS/badge.svg)](https://github.com/suketa/ruby-duckdb/actions?query=workflow%3AMacOS)
|
5
|
+
[![Windows](https://github.com/suketa/ruby-duckdb/workflows/Windows/badge.svg)](https://github.com/suketa/ruby-duckdb/actions?query=workflow%3AWindows)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/duckdb.svg)](https://badge.fury.io/rb/duckdb)
|
6
7
|
|
7
8
|
## Description
|
8
9
|
|
@@ -12,11 +13,39 @@ ruby-duckdb is Ruby binding for [DuckDB](http://www.duckdb.org) database engine
|
|
12
13
|
|
13
14
|
You must have [DuckDB](http://www.duckdb.org) engine installed in order to build/use this module.
|
14
15
|
|
16
|
+
## Pre-requisite setup (Linux):
|
17
|
+
1. Head over to the [DuckDB](https://duckdb.org/) webpage
|
18
|
+
|
19
|
+
2. Download the latest C++ package release for DuckDB
|
20
|
+
|
21
|
+
3. Move the files to their respective location:
|
22
|
+
- Extract the `duckdb.h` and `duckdb.hpp` file to `/usr/local/include`
|
23
|
+
- Extract the `libduckdb.so` file to `/usr/local/lib`
|
24
|
+
|
25
|
+
```sh
|
26
|
+
unzip libduckdb-linux-amd64.zip -d libduckdb
|
27
|
+
sudo mv libduckdb/duckdb.* /usr/local/include/
|
28
|
+
sudo mv libduckdb/libduckdb.so /usr/local/lib
|
29
|
+
```
|
30
|
+
4. To create the necessary link, run `ldconfig` as root:
|
31
|
+
|
32
|
+
```sh
|
33
|
+
sudo ldconfig /usr/local/lib # adding a --verbose flag is optional - but this will let you know if the libduckdb.so library has been linked
|
34
|
+
```
|
35
|
+
## Pre-requisite setup (MacOS):
|
36
|
+
|
37
|
+
Using `brew install` is recommended.
|
38
|
+
|
39
|
+
```sh
|
40
|
+
brew install duckdb
|
41
|
+
```
|
42
|
+
|
15
43
|
## How to Install
|
16
44
|
|
17
45
|
```
|
18
46
|
gem install duckdb
|
19
47
|
```
|
48
|
+
> this will work fine with the above pre-requisite setup.
|
20
49
|
|
21
50
|
or you must specify the location of the C header and library files:
|
22
51
|
|
data/ext/duckdb/appender.c
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
#include "ruby-duckdb.h"
|
2
2
|
|
3
|
-
#ifdef HAVE_DUCKDB_APPENDER_CREATE
|
4
|
-
|
5
3
|
static VALUE cDuckDBAppender;
|
6
4
|
|
7
5
|
static void deallocate(void *);
|
@@ -29,35 +27,23 @@ static VALUE appender_append_null(VALUE self);
|
|
29
27
|
static VALUE appender__append_date(VALUE self, VALUE yearval, VALUE monthval, VALUE dayval);
|
30
28
|
#endif
|
31
29
|
|
32
|
-
#ifdef HAVE_DUCKDB_APPEND_INTERVAL
|
33
30
|
static VALUE appender__append_interval(VALUE self, VALUE months, VALUE days, VALUE micros);
|
34
|
-
#endif
|
35
31
|
|
36
|
-
#ifdef HAVE_DUCKDB_APPEND_TIME
|
37
32
|
static VALUE appender__append_time(VALUE self, VALUE hour, VALUE min, VALUE sec, VALUE micros);
|
38
|
-
#endif
|
39
|
-
|
40
|
-
#ifdef HAVE_DUCKDB_APPEND_TIMESTAMP
|
41
33
|
static VALUE appender__append_timestamp(VALUE self, VALUE year, VALUE month, VALUE day, VALUE hour, VALUE min, VALUE sec, VALUE micros);
|
42
|
-
#endif
|
43
|
-
|
44
|
-
#ifdef HAVE_DUCKDB_APPEND_HUGEINT
|
45
34
|
static VALUE appender__append_hugeint(VALUE self, VALUE lower, VALUE upper);
|
46
|
-
#endif
|
47
35
|
|
48
36
|
static VALUE appender_flush(VALUE self);
|
49
37
|
static VALUE appender_close(VALUE self);
|
50
38
|
|
51
|
-
static void deallocate(void * ctx)
|
52
|
-
{
|
39
|
+
static void deallocate(void * ctx) {
|
53
40
|
rubyDuckDBAppender *p = (rubyDuckDBAppender *)ctx;
|
54
41
|
|
55
42
|
duckdb_appender_destroy(&(p->appender));
|
56
43
|
xfree(p);
|
57
44
|
}
|
58
45
|
|
59
|
-
static VALUE allocate(VALUE klass)
|
60
|
-
{
|
46
|
+
static VALUE allocate(VALUE klass) {
|
61
47
|
rubyDuckDBAppender *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBAppender));
|
62
48
|
return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
|
63
49
|
}
|
@@ -290,16 +276,12 @@ static VALUE appender_append_null(VALUE self) {
|
|
290
276
|
}
|
291
277
|
|
292
278
|
#ifdef HAVE_DUCKDB_APPEND_DATE
|
293
|
-
static VALUE appender__append_date(VALUE self, VALUE
|
294
|
-
duckdb_date_struct dt_struct;
|
279
|
+
static VALUE appender__append_date(VALUE self, VALUE year, VALUE month, VALUE day) {
|
295
280
|
duckdb_date dt;
|
296
281
|
rubyDuckDBAppender *ctx;
|
297
282
|
|
298
283
|
Data_Get_Struct(self, rubyDuckDBAppender, ctx);
|
299
|
-
|
300
|
-
dt_struct.month = NUM2INT(monthval);
|
301
|
-
dt_struct.day = NUM2INT(dayval);
|
302
|
-
dt = duckdb_to_date(dt_struct);
|
284
|
+
dt = to_duckdb_date_from_value(year, month, day);
|
303
285
|
|
304
286
|
if (duckdb_append_date(ctx->appender, dt) == DuckDBError) {
|
305
287
|
rb_raise(eDuckDBError, "failed to append date");
|
@@ -308,71 +290,47 @@ static VALUE appender__append_date(VALUE self, VALUE yearval, VALUE monthval, VA
|
|
308
290
|
}
|
309
291
|
#endif
|
310
292
|
|
311
|
-
#ifdef HAVE_DUCKDB_APPEND_INTERVAL
|
312
293
|
static VALUE appender__append_interval(VALUE self, VALUE months, VALUE days, VALUE micros) {
|
313
294
|
duckdb_interval interval;
|
314
295
|
rubyDuckDBAppender *ctx;
|
315
296
|
|
316
297
|
Data_Get_Struct(self, rubyDuckDBAppender, ctx);
|
317
|
-
interval
|
318
|
-
interval.days = NUM2INT(days);
|
319
|
-
interval.micros = NUM2LL(micros);
|
298
|
+
to_duckdb_interval_from_value(&interval, months, days, micros);
|
320
299
|
|
321
300
|
if (duckdb_append_interval(ctx->appender, interval) == DuckDBError) {
|
322
301
|
rb_raise(eDuckDBError, "failed to append interval");
|
323
302
|
}
|
324
303
|
return self;
|
325
304
|
}
|
326
|
-
#endif
|
327
305
|
|
328
|
-
#ifdef HAVE_DUCKDB_APPEND_TIME
|
329
306
|
static VALUE appender__append_time(VALUE self, VALUE hour, VALUE min, VALUE sec, VALUE micros) {
|
330
|
-
duckdb_time_struct time_st;
|
331
307
|
duckdb_time time;
|
332
308
|
rubyDuckDBAppender *ctx;
|
333
309
|
|
334
310
|
Data_Get_Struct(self, rubyDuckDBAppender, ctx);
|
335
|
-
|
336
|
-
time_st.min = NUM2INT(min);
|
337
|
-
time_st.sec = NUM2INT(sec);
|
338
|
-
time_st.micros = NUM2INT(micros);
|
339
|
-
|
340
|
-
time = duckdb_to_time(time_st);
|
311
|
+
time = to_duckdb_time_from_value(hour, min, sec, micros);
|
341
312
|
|
342
313
|
if (duckdb_append_time(ctx->appender, time) == DuckDBError) {
|
343
314
|
rb_raise(eDuckDBError, "failed to append time");
|
344
315
|
}
|
345
316
|
return self;
|
346
317
|
}
|
347
|
-
#endif
|
348
318
|
|
349
|
-
#ifdef HAVE_DUCKDB_APPEND_TIMESTAMP
|
350
319
|
static VALUE appender__append_timestamp(VALUE self, VALUE year, VALUE month, VALUE day, VALUE hour, VALUE min, VALUE sec, VALUE micros) {
|
351
|
-
duckdb_timestamp_struct timestamp_st;
|
352
320
|
duckdb_timestamp timestamp;
|
353
321
|
|
354
322
|
rubyDuckDBAppender *ctx;
|
355
323
|
|
356
324
|
Data_Get_Struct(self, rubyDuckDBAppender, ctx);
|
357
325
|
|
358
|
-
|
359
|
-
timestamp_st.date.month = NUM2INT(month);
|
360
|
-
timestamp_st.date.day = NUM2INT(day);
|
361
|
-
timestamp_st.time.hour = NUM2INT(hour);
|
362
|
-
timestamp_st.time.min = NUM2INT(min);
|
363
|
-
timestamp_st.time.sec = NUM2INT(sec);
|
364
|
-
timestamp_st.time.micros = NUM2INT(micros);
|
365
|
-
|
366
|
-
timestamp = duckdb_to_timestamp(timestamp_st);
|
326
|
+
timestamp = to_duckdb_timestamp_from_value(year, month, day, hour, min, sec, micros);
|
367
327
|
|
368
328
|
if (duckdb_append_timestamp(ctx->appender, timestamp) == DuckDBError) {
|
369
329
|
rb_raise(eDuckDBError, "failed to append timestamp");
|
370
330
|
}
|
371
331
|
return self;
|
372
332
|
}
|
373
|
-
#endif
|
374
333
|
|
375
|
-
#ifdef HAVE_DUCKDB_APPEND_HUGEINT
|
376
334
|
static VALUE appender__append_hugeint(VALUE self, VALUE lower, VALUE upper) {
|
377
335
|
duckdb_hugeint hugeint;
|
378
336
|
|
@@ -387,7 +345,6 @@ static VALUE appender__append_hugeint(VALUE self, VALUE lower, VALUE upper) {
|
|
387
345
|
}
|
388
346
|
return self;
|
389
347
|
}
|
390
|
-
#endif
|
391
348
|
|
392
349
|
static VALUE appender_flush(VALUE self) {
|
393
350
|
rubyDuckDBAppender *ctx;
|
@@ -433,19 +390,10 @@ void init_duckdb_appender(void) {
|
|
433
390
|
#ifdef HAVE_DUCKDB_APPEND_DATE
|
434
391
|
rb_define_private_method(cDuckDBAppender, "_append_date", appender__append_date, 3);
|
435
392
|
#endif
|
436
|
-
#ifdef HAVE_DUCKDB_APPEND_INTERVAL
|
437
393
|
rb_define_private_method(cDuckDBAppender, "_append_interval", appender__append_interval, 3);
|
438
|
-
#endif
|
439
|
-
#ifdef HAVE_DUCKDB_APPEND_TIME
|
440
394
|
rb_define_private_method(cDuckDBAppender, "_append_time", appender__append_time, 4);
|
441
|
-
#endif
|
442
|
-
#ifdef HAVE_DUCKDB_APPEND_TIMESTAMP
|
443
395
|
rb_define_private_method(cDuckDBAppender, "_append_timestamp", appender__append_timestamp, 7);
|
444
|
-
#endif
|
445
|
-
#ifdef HAVE_DUCKDB_APPEND_HUGEINT
|
446
396
|
rb_define_private_method(cDuckDBAppender, "_append_hugeint", appender__append_hugeint, 2);
|
447
|
-
#endif
|
448
397
|
rb_define_method(cDuckDBAppender, "flush", appender_flush, 0);
|
449
398
|
rb_define_method(cDuckDBAppender, "close", appender_close, 0);
|
450
399
|
}
|
451
|
-
#endif /* HAVE_DUCKDB_APPENDER_CREATE */
|
data/ext/duckdb/appender.h
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
#ifndef RUBY_DUCKDB_APPENDER_H
|
2
2
|
#define RUBY_DUCKDB_APPENDER_H
|
3
3
|
|
4
|
-
#ifdef HAVE_DUCKDB_APPENDER_CREATE
|
5
|
-
|
6
4
|
struct _rubyDuckDBAppender {
|
7
5
|
duckdb_appender appender;
|
8
6
|
};
|
@@ -12,6 +10,3 @@ typedef struct _rubyDuckDBAppender rubyDuckDBAppender;
|
|
12
10
|
void init_duckdb_appender(void);
|
13
11
|
|
14
12
|
#endif
|
15
|
-
|
16
|
-
#endif
|
17
|
-
|
data/ext/duckdb/blob.c
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
#include "ruby-duckdb.h"
|
2
2
|
|
3
|
-
#ifdef HAVE_DUCKDB_VALUE_BLOB
|
4
|
-
|
5
3
|
VALUE cDuckDBBlob;
|
6
4
|
|
7
|
-
void init_duckdb_blob(void)
|
8
|
-
{
|
5
|
+
void init_duckdb_blob(void) {
|
9
6
|
cDuckDBBlob = rb_define_class_under(mDuckDB, "Blob", rb_cString);
|
10
7
|
}
|
11
|
-
#endif /* HAVE_DUCKDB_VALUE_BLOB */
|
data/ext/duckdb/blob.h
CHANGED
data/ext/duckdb/column.c
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#include "ruby-duckdb.h"
|
2
|
+
|
3
|
+
static VALUE cDuckDBColumn;
|
4
|
+
|
5
|
+
static void deallocate(void *ctx);
|
6
|
+
static VALUE allocate(VALUE klass);
|
7
|
+
static VALUE duckdb_column__type(VALUE oDuckDBColumn);
|
8
|
+
static VALUE duckdb_column_get_name(VALUE oDuckDBColumn);
|
9
|
+
|
10
|
+
static void deallocate(void *ctx) {
|
11
|
+
rubyDuckDBColumn *p = (rubyDuckDBColumn *)ctx;
|
12
|
+
|
13
|
+
xfree(p);
|
14
|
+
}
|
15
|
+
|
16
|
+
static VALUE allocate(VALUE klass) {
|
17
|
+
rubyDuckDBColumn *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBColumn));
|
18
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
|
19
|
+
}
|
20
|
+
|
21
|
+
/*
|
22
|
+
*
|
23
|
+
*/
|
24
|
+
VALUE duckdb_column__type(VALUE oDuckDBColumn) {
|
25
|
+
rubyDuckDBColumn *ctx;
|
26
|
+
Data_Get_Struct(oDuckDBColumn, rubyDuckDBColumn, ctx);
|
27
|
+
|
28
|
+
VALUE result = rb_ivar_get(oDuckDBColumn, rb_intern("result"));
|
29
|
+
rubyDuckDBResult *ctxresult;
|
30
|
+
Data_Get_Struct(result, rubyDuckDBResult, ctxresult);
|
31
|
+
duckdb_type type = duckdb_column_type(&(ctxresult->result), ctx->col);
|
32
|
+
|
33
|
+
return INT2FIX(type);
|
34
|
+
}
|
35
|
+
|
36
|
+
/*
|
37
|
+
* call-seq:
|
38
|
+
* column.name -> string.
|
39
|
+
*
|
40
|
+
* Returns the column name.
|
41
|
+
*
|
42
|
+
*/
|
43
|
+
VALUE duckdb_column_get_name(VALUE oDuckDBColumn) {
|
44
|
+
rubyDuckDBColumn *ctx;
|
45
|
+
Data_Get_Struct(oDuckDBColumn, rubyDuckDBColumn, ctx);
|
46
|
+
|
47
|
+
VALUE result = rb_ivar_get(oDuckDBColumn, rb_intern("result"));
|
48
|
+
rubyDuckDBResult *ctxresult;
|
49
|
+
Data_Get_Struct(result, rubyDuckDBResult, ctxresult);
|
50
|
+
|
51
|
+
return rb_str_new2(duckdb_column_name(&(ctxresult->result), ctx->col));
|
52
|
+
}
|
53
|
+
|
54
|
+
VALUE create_column(VALUE oDuckDBResult, idx_t col) {
|
55
|
+
VALUE obj;
|
56
|
+
|
57
|
+
obj = allocate(cDuckDBColumn);
|
58
|
+
rubyDuckDBColumn *ctx;
|
59
|
+
Data_Get_Struct(obj, rubyDuckDBColumn, ctx);
|
60
|
+
|
61
|
+
rb_ivar_set(obj, rb_intern("result"), oDuckDBResult);
|
62
|
+
ctx->col = col;
|
63
|
+
|
64
|
+
return obj;
|
65
|
+
}
|
66
|
+
|
67
|
+
void init_duckdb_column(void) {
|
68
|
+
cDuckDBColumn = rb_define_class_under(mDuckDB, "Column", rb_cObject);
|
69
|
+
rb_define_alloc_func(cDuckDBColumn, allocate);
|
70
|
+
|
71
|
+
rb_define_private_method(cDuckDBColumn, "_type", duckdb_column__type, 0);
|
72
|
+
rb_define_method(cDuckDBColumn, "name", duckdb_column_get_name, 0);
|
73
|
+
}
|
data/ext/duckdb/column.h
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#ifndef RUBY_DUCKDB_COLUMN_H
|
2
|
+
#define RUBY_DUCKDB_COLUMN_H
|
3
|
+
|
4
|
+
struct _rubyDuckDBColumn {
|
5
|
+
VALUE result;
|
6
|
+
idx_t col;
|
7
|
+
};
|
8
|
+
|
9
|
+
typedef struct _rubyDuckDBColumn rubyDuckDBColumn;
|
10
|
+
|
11
|
+
void init_duckdb_column(void);
|
12
|
+
VALUE create_column(VALUE oDuckDBResult, idx_t col);
|
13
|
+
|
14
|
+
#endif
|
data/ext/duckdb/config.c
CHANGED
@@ -11,16 +11,14 @@ static VALUE config_s_get_config_flag(VALUE self, VALUE value);
|
|
11
11
|
static VALUE config_initialize(VALUE self);
|
12
12
|
static VALUE config_set_config(VALUE self, VALUE key, VALUE value);
|
13
13
|
|
14
|
-
static void deallocate(void * ctx)
|
15
|
-
{
|
14
|
+
static void deallocate(void * ctx) {
|
16
15
|
rubyDuckDBConfig *p = (rubyDuckDBConfig *)ctx;
|
17
16
|
|
18
17
|
duckdb_destroy_config(&(p->config));
|
19
18
|
xfree(p);
|
20
19
|
}
|
21
20
|
|
22
|
-
static VALUE allocate(VALUE klass)
|
23
|
-
{
|
21
|
+
static VALUE allocate(VALUE klass) {
|
24
22
|
rubyDuckDBConfig *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBConfig));
|
25
23
|
return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
|
26
24
|
}
|
data/ext/duckdb/connection.c
CHANGED
@@ -78,13 +78,12 @@ static VALUE duckdb_connection_query_sql(VALUE self, VALUE str) {
|
|
78
78
|
}
|
79
79
|
|
80
80
|
if (duckdb_query(ctx->con, StringValueCStr(str), &(ctxr->result)) == DuckDBError) {
|
81
|
-
rb_raise(eDuckDBError, "%s", ctxr->result
|
81
|
+
rb_raise(eDuckDBError, "%s", duckdb_result_error(&(ctxr->result)));
|
82
82
|
}
|
83
83
|
return result;
|
84
84
|
}
|
85
85
|
|
86
|
-
void init_duckdb_connection(void)
|
87
|
-
{
|
86
|
+
void init_duckdb_connection(void) {
|
88
87
|
cDuckDBConnection = rb_define_class_under(mDuckDB, "Connection", rb_cObject);
|
89
88
|
rb_define_alloc_func(cDuckDBConnection, allocate);
|
90
89
|
|
data/ext/duckdb/duckdb.c
CHANGED
@@ -3,28 +3,19 @@
|
|
3
3
|
VALUE mDuckDB;
|
4
4
|
|
5
5
|
void
|
6
|
-
Init_duckdb_native(void)
|
7
|
-
{
|
6
|
+
Init_duckdb_native(void) {
|
8
7
|
mDuckDB = rb_define_module("DuckDB");
|
9
8
|
|
10
9
|
init_duckdb_error();
|
11
10
|
init_duckdb_database();
|
12
11
|
init_duckdb_connection();
|
13
12
|
init_duckdb_result();
|
13
|
+
init_duckdb_column();
|
14
14
|
init_duckdb_prepared_statement();
|
15
|
-
|
16
|
-
#ifdef HAVE_DUCKDB_VALUE_BLOB
|
17
|
-
|
18
15
|
init_duckdb_blob();
|
19
16
|
|
20
|
-
#endif /* HAVE_DUCKDB_VALUE_BLOB */
|
21
|
-
|
22
|
-
#ifdef HAVE_DUCKDB_APPENDER_CREATE
|
23
|
-
|
24
17
|
init_duckdb_appender();
|
25
18
|
|
26
|
-
#endif /* HAVE_DUCKDB_APPENDER_CREATE */
|
27
|
-
|
28
19
|
#ifdef HAVE_DUCKDB_CREATE_CONFIG
|
29
20
|
|
30
21
|
init_duckdb_config();
|
data/ext/duckdb/error.c
CHANGED
data/ext/duckdb/extconf.rb
CHANGED
@@ -1,24 +1,20 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
|
3
3
|
dir_config('duckdb')
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
have_func('duckdb_append_timestamp', 'duckdb.h')
|
22
|
-
have_func('duckdb_append_hugeint', 'duckdb.h')
|
23
|
-
create_makefile('duckdb/duckdb_native')
|
24
|
-
end
|
4
|
+
|
5
|
+
raise 'duckdb library is not found. Install duckdb library file and header file.' unless have_library('duckdb')
|
6
|
+
|
7
|
+
raise 'duckdb >= 0.2.9 is required. Install duckdb >= 0.2.9' unless have_func('duckdb_value_is_null', 'duckdb.h')
|
8
|
+
|
9
|
+
# ducdb >= 0.3.3 if duckdb_append_data_chunk() is defined.
|
10
|
+
have_func('duckdb_append_data_chunk', 'duckdb.h')
|
11
|
+
|
12
|
+
have_func('duckdb_free', 'duckdb.h')
|
13
|
+
|
14
|
+
have_func('duckdb_create_config', 'duckdb.h')
|
15
|
+
have_func('duckdb_open_ext', 'duckdb.h')
|
16
|
+
have_func('duckdb_prepare_error', 'duckdb.h')
|
17
|
+
|
18
|
+
have_func('duckdb_append_date', 'duckdb.h')
|
19
|
+
|
20
|
+
create_makefile('duckdb/duckdb_native')
|