duckdb 0.2.9.0 → 0.3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af998f52f46c0ef8f51501333cbaf39d720daaa389eb618d7d7ad79627d70ad9
4
- data.tar.gz: 8e1c5323fa2f917c9ab6050a0350e5e25b646559492501f636af026b79cb20f8
3
+ metadata.gz: 6f88e0fda10b4ddc1b18ccc7d91a2ecab498146be652604836fd0dc29f100957
4
+ data.tar.gz: d8ed6ede8914c4b28295d39889c6ebfe46f2c5c034d3fd69fdb1b5abc7bd3e59
5
5
  SHA512:
6
- metadata.gz: 14809adeffb7bc79f2102e29f89a6fe6ea276ab38eaeabed9f3c18a023566c3bbad06c1ab31e55499e77d3f0f9ced186d618c24639b8c16ceff1ee61304f9f67
7
- data.tar.gz: 15d164af6af9d985765d7b9fa87dcf7f9cf89fb2d691c9d44ea2d2bb72341a77213647cb08bcacc66094eb1622d250fe203f41a9529866af9f358518800f7183
6
+ metadata.gz: 64be83996e4cd611a89ef3169aeb9f9b918d2c8854804eeef4b536f1987e8e9d1ea7c777c64c9b2e745d236857002b3768084991d16a8d8c3e8032d00b4b4e46
7
+ data.tar.gz: 293d2c3fb7a9a920996ce671657ea2f305a7aa591bbaa1bf56f5fa44fcc2cc5dce1d6f463ba9a424eaed49afdb7d6ae477762c76ca8f5bebceb83ae28f1b565f
@@ -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.2.8', '0.2.9']
18
+ ruby: ['2.6.10', '2.7.6', '3.0.4', '3.1.2', 'head']
19
+ duckdb: ['0.3.2', '0.3.3']
12
20
 
13
21
  steps:
14
22
  - uses: actions/checkout@v2
@@ -22,28 +30,27 @@ jobs:
22
30
  id: duckdb-cache
23
31
  uses: actions/cache@v2
24
32
  with:
25
- path: /usr/local/Cellar/duckdb@${{ matrix.duckdb }}
33
+ path: duckdb-v${{ matrix.duckdb }}
26
34
  key: ${{ runner.os }}-duckdb-v${{ matrix.duckdb }}
27
35
 
28
- - name: Install duckdb v${{ matrix.duckdb }} by brew
36
+ - name: Build duckdb ${{ matrix.duckdb }}
29
37
  env:
30
38
  DUCKDB_VERSION: ${{ matrix.duckdb }}
31
39
  if: steps.duckdb-cache.outputs.cache-hit != 'true'
32
40
  run: |
33
- brew tap-new duckdb/taps
34
- brew extract duckdb duckdb/taps --version $DUCKDB_VERSION
35
- brew install duckdb/taps/duckdb@$DUCKDB_VERSION
36
-
37
- - name: setup duckdb v${{ matrix.duckdb }} headers and libraries
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/
47
+
48
+ - name: prepare duckdb header and libraries
38
49
  env:
39
50
  DUCKDB_VERSION: ${{ matrix.duckdb }}
40
51
  run: |
41
- if [ ! -L /usr/local/include/duckdb.h ]; then
42
- header=`find /usr/local/Cellar/duckdb@$DUCKDB_VERSION -name "duckdb.h"`
43
- lib=`find /usr/local/Cellar/duckdb@$DUCKDB_VERSION -name "libduckdb.dylib"`
44
- ln -s $header /usr/local/include/duckdb.h
45
- ln -s $lib /usr/local/lib/libduckdb.dylib
46
- fi
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
47
54
 
48
55
  - name: Build and test with Rake with Ruby ${{ matrix.ruby }}
49
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.2.8', '0.2.9']
19
+ ruby: ['2.6.10', '2.7.6', '3.0.4', '3.1.2', 'head']
20
+ duckdb: ['0.3.2', '0.3.3']
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.2.8', '0.2.9']
18
+ ruby: ['2.6.10', '2.7.6', '3.0.4', '3.1.2', 'mingw', 'head']
19
+ duckdb: ['0.3.2', '0.3.3']
12
20
 
13
21
  steps:
14
22
  - uses: actions/checkout@v2
@@ -26,18 +34,17 @@ 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
- # FIXME: rake test fails with LoadError
40
- # C:/hostedtoolcache/windows/Ruby/2.7.3/x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require': 126: The specified module could not be found. - D:/a/ruby-duckdb/ruby-duckdb/lib/duckdb/duckdb_native.so (LoadError)`
41
48
  - name: rake test
42
49
  run: |
43
50
  rake test
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # ChangeLog
2
2
 
3
+ # 0.3.3.0
4
+ - DuckDB::Column#type supports :decimal.
5
+ - bump duckdb 0.3.3.
6
+ - bump Ruby 2.6.10, 2.7.6, 3.0.4, 3.1.2.
7
+
8
+ # 0.3.2.0
9
+
10
+ - bind_time, bind_timestamp, bind_date, bind_timeinterval to DuckDB::PreparedStatement
11
+ - bump duckdb 0.3.2
12
+ - bump Ruby 3.1.1, add Ruby mingw in CI.
13
+ - bump Ruby 2.6.9, 2.7.5, 3.0.3 in CI.
14
+
15
+ ## BREAKING CHANGE
16
+ - drop duckdb <= 0.2.8
17
+
18
+ # 0.3.1.0
19
+
20
+ - bump duckdb to 0.3.1 in CI.
21
+ - bump duckdb to 0.3.0 in CI.
22
+ - append_time, append_date, append_timestamp of DuckDB::Appender accept argument
23
+ having to_str to convert time string.
24
+
3
25
  # 0.2.9.0
4
26
 
5
27
  - add DuckDB::Appender#append
data/Gemfile.lock CHANGED
@@ -1,17 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- duckdb (0.2.9.0)
4
+ duckdb (0.3.3.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
  }
@@ -2,22 +2,25 @@
2
2
 
3
3
  VALUE cDuckDBConnection;
4
4
 
5
- static void deallocate(void *ctx)
6
- {
5
+ static void deallocate(void *ctx);
6
+ static VALUE allocate(VALUE klass);
7
+ static VALUE duckdb_connection_disconnect(VALUE self);
8
+ static VALUE duckdb_connection_connect(VALUE self, VALUE oDuckDBDatabase);
9
+ static VALUE duckdb_connection_query_sql(VALUE self, VALUE str);
10
+
11
+ static void deallocate(void *ctx) {
7
12
  rubyDuckDBConnection *p = (rubyDuckDBConnection *)ctx;
8
13
 
9
14
  duckdb_disconnect(&(p->con));
10
15
  xfree(p);
11
16
  }
12
17
 
13
- static VALUE allocate(VALUE klass)
14
- {
18
+ static VALUE allocate(VALUE klass) {
15
19
  rubyDuckDBConnection *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBConnection));
16
20
  return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
17
21
  }
18
22
 
19
- VALUE create_connection(VALUE oDuckDBDatabase)
20
- {
23
+ VALUE create_connection(VALUE oDuckDBDatabase) {
21
24
  rubyDuckDB *ctxdb;
22
25
  rubyDuckDBConnection *ctxcon;
23
26
  VALUE obj;
@@ -35,8 +38,7 @@ VALUE create_connection(VALUE oDuckDBDatabase)
35
38
  return obj;
36
39
  }
37
40
 
38
- static VALUE duckdb_connection_disconnect(VALUE self)
39
- {
41
+ static VALUE duckdb_connection_disconnect(VALUE self) {
40
42
  rubyDuckDBConnection *ctx;
41
43
 
42
44
  Data_Get_Struct(self, rubyDuckDBConnection, ctx);
@@ -45,8 +47,7 @@ static VALUE duckdb_connection_disconnect(VALUE self)
45
47
  return self;
46
48
  }
47
49
 
48
- static VALUE duckdb_connection_connect(VALUE self, VALUE oDuckDBDatabase)
49
- {
50
+ static VALUE duckdb_connection_connect(VALUE self, VALUE oDuckDBDatabase) {
50
51
  rubyDuckDBConnection *ctx;
51
52
  rubyDuckDB *ctxdb;
52
53
 
@@ -63,8 +64,7 @@ static VALUE duckdb_connection_connect(VALUE self, VALUE oDuckDBDatabase)
63
64
  return self;
64
65
  }
65
66
 
66
- static VALUE duckdb_connection_query_sql(VALUE self, VALUE str)
67
- {
67
+ static VALUE duckdb_connection_query_sql(VALUE self, VALUE str) {
68
68
  rubyDuckDBConnection *ctx;
69
69
  rubyDuckDBResult *ctxr;
70
70
 
@@ -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