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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba5fa57fc1eaf1a2b0bb6ffa7379b8982d3858d17075c83b949af79331322a1e
4
- data.tar.gz: cbe87ed1de6de024e9941e063102e7bf31a5407945d99180121a38fde703a8d4
3
+ metadata.gz: '09a5bd2bc1a410ea68f8a3d0656c60c7048e24bbfc6406b1da5b51e3593a35e8'
4
+ data.tar.gz: 66cf129bde28b1473254d974bab4090cb738c01e7e0870b511bae82adaa9a2c3
5
5
  SHA512:
6
- metadata.gz: 52d8cff8db75e7e2d7f86632573fda6d1fe021e7ff38524edf9307e2d3c4720541daab609caee24307c3a8b6a0fa40d6b1cca4151d1edbb8b17f3c7f770bb7d3
7
- data.tar.gz: 371925fa099235c382cdd370f0d43d346f40b9dc45332931956f953ab742b0a55ec7afa52f73aa942695fe30b1df78722e7afadb1de66a6250381fdf0ed990f8
6
+ metadata.gz: 651bc7aa40359762327e1f4f104662808a2d6c9c2bfef4aadbe3707a2f2a824bff50d8c21d302549c69e5ebd26f9a32cba457015a2903eeba85adf1487b73e43
7
+ data.tar.gz: e36ce93b343c03daff66023fc3971379ccbcfa2488c1f23b028ef18b905d62d3ca6619e389e0619e50b958015f9330a508b27e6263458b28694a78bd3c9c0b98
@@ -1,14 +1,22 @@
1
1
  name: MacOS
2
2
 
3
- on: [push]
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.8', '2.7.4', '3.0.2', 'head']
11
- duckdb: ['0.3.0', '0.3.1']
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: download duckdb binary for MacOS 64bit
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
- curl -OL https://github.com/duckdb/duckdb/releases/download/v${DUCKDB_VERSION}/libduckdb-osx-amd64.zip
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: extract zip file
48
+ - name: prepare duckdb header and libraries
49
+ env:
50
+ DUCKDB_VERSION: ${{ matrix.duckdb }}
28
51
  run: |
29
- unzip libduckdb-osx-amd64.zip
30
- cp duckdb.h /usr/local/include
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: [push]
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.8', '2.7.4', '3.0.2', 'head']
12
- duckdb: ['0.3.0', '0.3.1']
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: [push]
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.8', '2.7.4', '3.0.2', 'head']
11
- duckdb: ['0.3.0', '0.3.1']
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
- 7z x libduckdb-windows-amd64.zip
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.1.0)
4
+ duckdb (0.3.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- minitest (5.14.4)
9
+ minitest (5.15.0)
10
10
  rake (13.0.6)
11
- rake-compiler (1.1.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
 
@@ -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 yearval, VALUE monthval, VALUE dayval) {
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
- dt_struct.year = NUM2INT(yearval);
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.months = NUM2INT(months);
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
- time_st.hour = NUM2INT(hour);
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
- timestamp_st.date.year = NUM2INT(year);
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 */
@@ -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
@@ -4,11 +4,7 @@
4
4
  /*
5
5
  * blob is supported by duckdb v0.2.5 or later
6
6
  */
7
- #ifdef HAVE_DUCKDB_VALUE_BLOB
8
-
9
7
  void init_duckdb_blob(void);
10
8
 
11
- #endif /* HAVE_DUCKDB_VALUE_BLOB */
12
-
13
9
  #endif
14
10
 
@@ -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
+ }
@@ -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
  }
@@ -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.error_message);
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
@@ -2,7 +2,6 @@
2
2
 
3
3
  VALUE eDuckDBError;
4
4
 
5
- void init_duckdb_error(void)
6
- {
5
+ void init_duckdb_error(void) {
7
6
  eDuckDBError = rb_define_class_under(mDuckDB, "Error", rb_eStandardError);
8
7
  }
@@ -1,24 +1,20 @@
1
1
  require 'mkmf'
2
2
 
3
3
  dir_config('duckdb')
4
- if have_library('duckdb')
5
- if have_func('duckdb_nparams(NULL)', 'duckdb.h')
6
- $defs << '-DHAVE_DUCKDB_NPARAMS_029'
7
- elsif have_func('duckdb_nparams(NULL, NULL)', 'duckdb.h')
8
- $defs << '-DHAVE_DUCKDB_NPARAMS_028'
9
- end
10
-
11
- have_func('duckdb_value_blob', 'duckdb.h')
12
- have_func('duckdb_bind_blob', 'duckdb.h')
13
- have_func('duckdb_appender_create', 'duckdb.h')
14
- have_func('duckdb_free', 'duckdb.h')
15
- have_func('duckdb_create_config', 'duckdb.h')
16
- have_func('duckdb_open_ext', 'duckdb.h')
17
- have_func('duckdb_prepare_error', 'duckdb.h')
18
- have_func('duckdb_append_date', 'duckdb.h')
19
- have_func('duckdb_append_interval', 'duckdb.h')
20
- have_func('duckdb_append_time', 'duckdb.h')
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')