duckdb 0.3.4.0 → 0.5.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: '09a5bd2bc1a410ea68f8a3d0656c60c7048e24bbfc6406b1da5b51e3593a35e8'
4
- data.tar.gz: 66cf129bde28b1473254d974bab4090cb738c01e7e0870b511bae82adaa9a2c3
3
+ metadata.gz: 7dfab228c1219f54a4ae96cc9b997e0a4a1ea27c4da8822b8ebc2abb59472914
4
+ data.tar.gz: a899d87be82ba06faadb895a871b6b46fe564f23faec6ff312f28fc30ee1fb32
5
5
  SHA512:
6
- metadata.gz: 651bc7aa40359762327e1f4f104662808a2d6c9c2bfef4aadbe3707a2f2a824bff50d8c21d302549c69e5ebd26f9a32cba457015a2903eeba85adf1487b73e43
7
- data.tar.gz: e36ce93b343c03daff66023fc3971379ccbcfa2488c1f23b028ef18b905d62d3ca6619e389e0619e50b958015f9330a508b27e6263458b28694a78bd3c9c0b98
6
+ metadata.gz: c69e2332a79ebd3f92322fe2e1318d89f71abfe4964776548772d518a76c52170c2f989d22575f3f1c7cc22412431c41ae374513a7bc21087e8b5c7ab5c25d3b
7
+ data.tar.gz: 684de0961c64fdf34df7c12bd6792aac86ca491de263440f61c93c7b76a04cd0c4c03617d424bd46da5a8ddd9ed1e7a5f4174a3b71026a74e794c0712a30869d
@@ -11,12 +11,12 @@ on:
11
11
  - reopened
12
12
 
13
13
  jobs:
14
- build:
14
+ test:
15
15
  runs-on: macos-latest
16
16
  strategy:
17
17
  matrix:
18
- ruby: ['2.6.10', '2.7.6', '3.0.4', '3.1.2', 'head']
19
- duckdb: ['0.3.2', '0.3.4']
18
+ ruby: ['2.6.10', '2.7.6', '3.0.4', '3.1.2', '3.2.0-preview2', 'head']
19
+ duckdb: ['0.4.0', '0.5.0']
20
20
 
21
21
  steps:
22
22
  - uses: actions/checkout@v2
@@ -57,3 +57,10 @@ jobs:
57
57
  ruby -v
58
58
  bundle install --jobs 4 --retry 3
59
59
  bundle exec rake
60
+
61
+ post-test:
62
+ name: All tests passed on macos
63
+ runs-on: macos-latest
64
+ needs: test
65
+ steps:
66
+ - run: echo ok
@@ -11,13 +11,12 @@ on:
11
11
  - reopened
12
12
 
13
13
  jobs:
14
- build:
15
-
14
+ test:
16
15
  runs-on: ubuntu-latest
17
16
  strategy:
18
17
  matrix:
19
- ruby: ['2.6.10', '2.7.6', '3.0.4', '3.1.2', 'head']
20
- duckdb: ['0.3.2', '0.3.4']
18
+ ruby: ['2.6.10', '2.7.6', '3.0.4', '3.1.2', '3.2.0-preview2', 'head']
19
+ duckdb: ['0.4.0', '0.5.0']
21
20
 
22
21
  steps:
23
22
  - uses: actions/checkout@v2
@@ -53,3 +52,10 @@ jobs:
53
52
  gem install bundler
54
53
  bundle install --jobs 4 --retry 3
55
54
  bundle exec rake -- --with-duckdb-include=${GITHUB_WORKSPACE}/duckdb-v${DUCKDB_VERSION}/src/include --with-duckdb-lib=${GITHUB_WORKSPACE}/duckdb-v${DUCKDB_VERSION}/build/release/src/
55
+
56
+ post-test:
57
+ name: All tests passed on Ubuntu
58
+ runs-on: ubuntu-latest
59
+ needs: test
60
+ steps:
61
+ - run: echo ok
@@ -11,12 +11,12 @@ on:
11
11
  - reopened
12
12
 
13
13
  jobs:
14
- build:
14
+ test:
15
15
  runs-on: windows-latest
16
16
  strategy:
17
17
  matrix:
18
- ruby: ['2.6.10', '2.7.6', '3.0.4', '3.1.2', 'mingw', 'head']
19
- duckdb: ['0.3.2', '0.3.4']
18
+ ruby: ['2.6.10', '2.7.6', '3.0.4', '3.1.2', 'ucrt', 'mingw', 'head']
19
+ duckdb: ['0.4.0', '0.5.0']
20
20
 
21
21
  steps:
22
22
  - uses: actions/checkout@v2
@@ -48,3 +48,10 @@ jobs:
48
48
  - name: rake test
49
49
  run: |
50
50
  rake test
51
+
52
+ post-test:
53
+ name: All tests passed on Windows
54
+ runs-on: windows-latest
55
+ needs: test
56
+ steps:
57
+ - run: echo ok
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # ChangeLog
2
2
 
3
+ # 0.5.0
4
+ - update bundle version of Gemfile.lock
5
+ - add ruby ucrt test on Windows
6
+ - use TypedData_Wrap_Struct, TypedData_Get_Struct
7
+ - bump duckdb 0.5.0
8
+ - fix utf-8 encoding.
9
+ - add DuckDB::Result#enum_dictionary_values
10
+ - add DuckDB::Result#row_count, DuckDB::Result#row_size(alias of row_count).
11
+ - add DuckDB::Result#column_count, DuckDB::Result#column_size(alias of column_count).
12
+
13
+ ## Breaking Change
14
+ - bind_varchar does not raised DuckDB::Error when the binding column is date or datetime.
15
+
3
16
  # 0.3.4.0
4
17
  - bump duckdb 0.3.4
5
18
 
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- duckdb (0.3.4.0)
4
+ duckdb (0.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- minitest (5.15.0)
9
+ minitest (5.16.3)
10
10
  rake (13.0.6)
11
11
  rake-compiler (1.2.0)
12
12
  rake
@@ -16,11 +16,11 @@ PLATFORMS
16
16
  x86_64-linux
17
17
 
18
18
  DEPENDENCIES
19
- bundler (~> 2.0)
19
+ bundler (~> 2.3)
20
20
  duckdb!
21
21
  minitest (~> 5.0)
22
22
  rake (~> 13.0)
23
23
  rake-compiler
24
24
 
25
25
  BUNDLED WITH
26
- 2.2.25
26
+ 2.3.22
data/README.md CHANGED
@@ -21,14 +21,14 @@ You must have [DuckDB](http://www.duckdb.org) engine installed in order to build
21
21
  3. Move the files to their respective location:
22
22
  - Extract the `duckdb.h` and `duckdb.hpp` file to `/usr/local/include`
23
23
  - Extract the `libduckdb.so` file to `/usr/local/lib`
24
-
24
+
25
25
  ```sh
26
26
  unzip libduckdb-linux-amd64.zip -d libduckdb
27
27
  sudo mv libduckdb/duckdb.* /usr/local/include/
28
28
  sudo mv libduckdb/libduckdb.so /usr/local/lib
29
29
  ```
30
30
  4. To create the necessary link, run `ldconfig` as root:
31
-
31
+
32
32
  ```sh
33
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
34
  ```
@@ -42,20 +42,20 @@ brew install duckdb
42
42
 
43
43
  ## How to Install
44
44
 
45
- ```
45
+ ```sh
46
46
  gem install duckdb
47
47
  ```
48
48
  > this will work fine with the above pre-requisite setup.
49
49
 
50
50
  or you must specify the location of the C header and library files:
51
51
 
52
- ```
52
+ ```sh
53
53
  gem install duckdb -- --with-duckdb-include=/duckdb_header_directory --with-duckdb-lib=/duckdb_library_directory
54
54
  ```
55
55
 
56
56
  ## Usage
57
57
 
58
- ```
58
+ ```ruby
59
59
  require 'duckdb'
60
60
 
61
61
  db = DuckDB::Database.open # database in memory
@@ -75,7 +75,7 @@ end
75
75
 
76
76
  Or, you can use block.
77
77
 
78
- ```
78
+ ```ruby
79
79
  require 'duckdb'
80
80
 
81
81
  DuckDB::Database.open do |db|
@@ -99,7 +99,7 @@ end
99
99
  BLOB is available with DuckDB v0.2.5 or later.
100
100
  Use `DuckDB::Blob.new` or use sting#force_encoding(Encoding::BINARY)
101
101
 
102
- ```
102
+ ```ruby
103
103
  require 'duckdb'
104
104
 
105
105
  DuckDB::Database.open do |db|
@@ -121,7 +121,7 @@ end
121
121
 
122
122
  Appender class provides Ruby interface of [DuckDB Appender](https://duckdb.org/docs/data/appender)
123
123
 
124
- ```
124
+ ```ruby
125
125
  require 'duckdb'
126
126
  require 'benchmark'
127
127
 
@@ -183,7 +183,7 @@ end
183
183
 
184
184
  Config class provides Ruby interface of [DuckDB configuration](https://duckdb.org/docs/api/c/config).
185
185
 
186
- ```
186
+ ```ruby
187
187
  require 'duckdb'
188
188
  config = DuckDB::Config.new
189
189
  config['default_order'] = 'DESC'
data/duckdb.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.extensions = ['ext/duckdb/extconf.rb']
29
29
  spec.required_ruby_version = '>= 2.6.0'
30
30
 
31
- spec.add_development_dependency 'bundler', '~> 2.0'
31
+ spec.add_development_dependency 'bundler', '~> 2.3'
32
32
  spec.add_development_dependency 'minitest', '~> 5.0'
33
33
  spec.add_development_dependency 'rake', '~> 13.0'
34
34
  spec.add_development_dependency 'rake-compiler'
@@ -4,6 +4,7 @@ static VALUE cDuckDBAppender;
4
4
 
5
5
  static void deallocate(void *);
6
6
  static VALUE allocate(VALUE klass);
7
+ static size_t memsize(const void *p);
7
8
  static VALUE appender_initialize(VALUE klass, VALUE con, VALUE schema, VALUE table);
8
9
  static VALUE appender_begin_row(VALUE self);
9
10
  static VALUE appender_end_row(VALUE self);
@@ -22,20 +23,20 @@ static VALUE appender_append_varchar(VALUE self, VALUE val);
22
23
  static VALUE appender_append_varchar_length(VALUE self, VALUE val, VALUE len);
23
24
  static VALUE appender_append_blob(VALUE self, VALUE val);
24
25
  static VALUE appender_append_null(VALUE self);
25
-
26
- #ifdef HAVE_DUCKDB_APPEND_DATE
27
26
  static VALUE appender__append_date(VALUE self, VALUE yearval, VALUE monthval, VALUE dayval);
28
- #endif
29
-
30
27
  static VALUE appender__append_interval(VALUE self, VALUE months, VALUE days, VALUE micros);
31
-
32
28
  static VALUE appender__append_time(VALUE self, VALUE hour, VALUE min, VALUE sec, VALUE micros);
33
29
  static VALUE appender__append_timestamp(VALUE self, VALUE year, VALUE month, VALUE day, VALUE hour, VALUE min, VALUE sec, VALUE micros);
34
30
  static VALUE appender__append_hugeint(VALUE self, VALUE lower, VALUE upper);
35
-
36
31
  static VALUE appender_flush(VALUE self);
37
32
  static VALUE appender_close(VALUE self);
38
33
 
34
+ static const rb_data_type_t appender_data_type = {
35
+ "DuckDB/Appender",
36
+ {NULL, deallocate, memsize,},
37
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
38
+ };
39
+
39
40
  static void deallocate(void * ctx) {
40
41
  rubyDuckDBAppender *p = (rubyDuckDBAppender *)ctx;
41
42
 
@@ -45,7 +46,11 @@ static void deallocate(void * ctx) {
45
46
 
46
47
  static VALUE allocate(VALUE klass) {
47
48
  rubyDuckDBAppender *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBAppender));
48
- return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
49
+ return TypedData_Wrap_Struct(klass, &appender_data_type, ctx);
50
+ }
51
+
52
+ static size_t memsize(const void *p) {
53
+ return sizeof(rubyDuckDBAppender);
49
54
  }
50
55
 
51
56
  static VALUE appender_initialize(VALUE self, VALUE con, VALUE schema, VALUE table) {
@@ -58,8 +63,8 @@ static VALUE appender_initialize(VALUE self, VALUE con, VALUE schema, VALUE tabl
58
63
  rb_raise(rb_eTypeError, "1st argument should be instance of DackDB::Connection");
59
64
  }
60
65
 
61
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
62
- Data_Get_Struct(con, rubyDuckDBConnection, ctxcon);
66
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
67
+ ctxcon = get_struct_connection(con);
63
68
 
64
69
  if (schema != Qnil) {
65
70
  pschema = StringValuePtr(schema);
@@ -73,7 +78,7 @@ static VALUE appender_initialize(VALUE self, VALUE con, VALUE schema, VALUE tabl
73
78
 
74
79
  static VALUE appender_begin_row(VALUE self) {
75
80
  rubyDuckDBAppender *ctx;
76
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
81
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
77
82
 
78
83
  if (duckdb_appender_begin_row(ctx->appender) == DuckDBError) {
79
84
  rb_raise(eDuckDBError, "failed to flush");
@@ -83,7 +88,7 @@ static VALUE appender_begin_row(VALUE self) {
83
88
 
84
89
  static VALUE appender_end_row(VALUE self) {
85
90
  rubyDuckDBAppender *ctx;
86
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
91
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
87
92
 
88
93
  if (duckdb_appender_end_row(ctx->appender) == DuckDBError) {
89
94
  rb_raise(eDuckDBError, "failed to flush");
@@ -93,7 +98,7 @@ static VALUE appender_end_row(VALUE self) {
93
98
 
94
99
  static VALUE appender_append_bool(VALUE self, VALUE val) {
95
100
  rubyDuckDBAppender *ctx;
96
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
101
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
97
102
 
98
103
  if (val != Qtrue && val != Qfalse) {
99
104
  rb_raise(rb_eArgError, "argument must be boolean");
@@ -109,7 +114,7 @@ static VALUE appender_append_int8(VALUE self, VALUE val) {
109
114
  rubyDuckDBAppender *ctx;
110
115
  int8_t i8val = (int8_t)NUM2INT(val);
111
116
 
112
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
117
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
113
118
 
114
119
  if (duckdb_append_int8(ctx->appender, i8val) == DuckDBError) {
115
120
  rb_raise(eDuckDBError, "failed to append");
@@ -121,7 +126,7 @@ static VALUE appender_append_int16(VALUE self, VALUE val) {
121
126
  rubyDuckDBAppender *ctx;
122
127
  int16_t i16val = (int16_t)NUM2INT(val);
123
128
 
124
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
129
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
125
130
 
126
131
  if (duckdb_append_int16(ctx->appender, i16val) == DuckDBError) {
127
132
  rb_raise(eDuckDBError, "failed to append");
@@ -133,7 +138,7 @@ static VALUE appender_append_int32(VALUE self, VALUE val) {
133
138
  rubyDuckDBAppender *ctx;
134
139
  int32_t i32val = (int32_t)NUM2INT(val);
135
140
 
136
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
141
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
137
142
 
138
143
  if (duckdb_append_int32(ctx->appender, i32val) == DuckDBError) {
139
144
  rb_raise(eDuckDBError, "failed to append");
@@ -145,7 +150,7 @@ static VALUE appender_append_int64(VALUE self, VALUE val) {
145
150
  rubyDuckDBAppender *ctx;
146
151
  int64_t i64val = (int64_t)NUM2LL(val);
147
152
 
148
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
153
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
149
154
 
150
155
  if (duckdb_append_int64(ctx->appender, i64val) == DuckDBError) {
151
156
  rb_raise(eDuckDBError, "failed to append");
@@ -157,7 +162,7 @@ static VALUE appender_append_uint8(VALUE self, VALUE val) {
157
162
  rubyDuckDBAppender *ctx;
158
163
  int8_t ui8val = (uint8_t)NUM2UINT(val);
159
164
 
160
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
165
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
161
166
 
162
167
  if (duckdb_append_uint8(ctx->appender, ui8val) == DuckDBError) {
163
168
  rb_raise(eDuckDBError, "failed to append");
@@ -169,7 +174,7 @@ static VALUE appender_append_uint16(VALUE self, VALUE val) {
169
174
  rubyDuckDBAppender *ctx;
170
175
  uint16_t ui16val = (uint16_t)NUM2UINT(val);
171
176
 
172
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
177
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
173
178
 
174
179
  if (duckdb_append_uint16(ctx->appender, ui16val) == DuckDBError) {
175
180
  rb_raise(eDuckDBError, "failed to append");
@@ -181,7 +186,7 @@ static VALUE appender_append_uint32(VALUE self, VALUE val) {
181
186
  rubyDuckDBAppender *ctx;
182
187
  uint32_t ui32val = (uint32_t)NUM2UINT(val);
183
188
 
184
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
189
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
185
190
 
186
191
  if (duckdb_append_uint32(ctx->appender, ui32val) == DuckDBError) {
187
192
  rb_raise(eDuckDBError, "failed to append");
@@ -193,7 +198,7 @@ static VALUE appender_append_uint64(VALUE self, VALUE val) {
193
198
  rubyDuckDBAppender *ctx;
194
199
  uint64_t ui64val = (uint64_t)NUM2ULL(val);
195
200
 
196
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
201
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
197
202
 
198
203
  if (duckdb_append_uint64(ctx->appender, ui64val) == DuckDBError) {
199
204
  rb_raise(eDuckDBError, "failed to append");
@@ -205,7 +210,7 @@ static VALUE appender_append_float(VALUE self, VALUE val) {
205
210
  rubyDuckDBAppender *ctx;
206
211
  float fval = (float)NUM2DBL(val);
207
212
 
208
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
213
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
209
214
 
210
215
  if (duckdb_append_float(ctx->appender, fval) == DuckDBError) {
211
216
  rb_raise(eDuckDBError, "failed to append");
@@ -217,7 +222,7 @@ static VALUE appender_append_double(VALUE self, VALUE val) {
217
222
  rubyDuckDBAppender *ctx;
218
223
  double dval = NUM2DBL(val);
219
224
 
220
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
225
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
221
226
 
222
227
  if (duckdb_append_double(ctx->appender, dval) == DuckDBError) {
223
228
  rb_raise(eDuckDBError, "failed to append");
@@ -229,7 +234,7 @@ static VALUE appender_append_varchar(VALUE self, VALUE val) {
229
234
  rubyDuckDBAppender *ctx;
230
235
  char *pval = StringValuePtr(val);
231
236
 
232
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
237
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
233
238
 
234
239
  if (duckdb_append_varchar(ctx->appender, pval) == DuckDBError) {
235
240
  rb_raise(eDuckDBError, "failed to append");
@@ -243,7 +248,7 @@ static VALUE appender_append_varchar_length(VALUE self, VALUE val, VALUE len) {
243
248
  char *pval = StringValuePtr(val);
244
249
  idx_t length = (idx_t)NUM2ULL(len);
245
250
 
246
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
251
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
247
252
 
248
253
  if (duckdb_append_varchar_length(ctx->appender, pval, length) == DuckDBError) {
249
254
  rb_raise(eDuckDBError, "failed to append");
@@ -257,7 +262,7 @@ static VALUE appender_append_blob(VALUE self, VALUE val) {
257
262
  char *pval = StringValuePtr(val);
258
263
  idx_t length = (idx_t)RSTRING_LEN(val);
259
264
 
260
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
265
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
261
266
 
262
267
  if (duckdb_append_blob(ctx->appender, (void *)pval, length) == DuckDBError) {
263
268
  rb_raise(eDuckDBError, "failed to append");
@@ -267,7 +272,7 @@ static VALUE appender_append_blob(VALUE self, VALUE val) {
267
272
 
268
273
  static VALUE appender_append_null(VALUE self) {
269
274
  rubyDuckDBAppender *ctx;
270
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
275
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
271
276
 
272
277
  if (duckdb_append_null(ctx->appender) == DuckDBError) {
273
278
  rb_raise(eDuckDBError, "failed to append");
@@ -275,12 +280,11 @@ static VALUE appender_append_null(VALUE self) {
275
280
  return self;
276
281
  }
277
282
 
278
- #ifdef HAVE_DUCKDB_APPEND_DATE
279
283
  static VALUE appender__append_date(VALUE self, VALUE year, VALUE month, VALUE day) {
280
284
  duckdb_date dt;
281
285
  rubyDuckDBAppender *ctx;
282
286
 
283
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
287
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
284
288
  dt = to_duckdb_date_from_value(year, month, day);
285
289
 
286
290
  if (duckdb_append_date(ctx->appender, dt) == DuckDBError) {
@@ -288,13 +292,12 @@ static VALUE appender__append_date(VALUE self, VALUE year, VALUE month, VALUE da
288
292
  }
289
293
  return self;
290
294
  }
291
- #endif
292
295
 
293
296
  static VALUE appender__append_interval(VALUE self, VALUE months, VALUE days, VALUE micros) {
294
297
  duckdb_interval interval;
295
298
  rubyDuckDBAppender *ctx;
296
299
 
297
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
300
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
298
301
  to_duckdb_interval_from_value(&interval, months, days, micros);
299
302
 
300
303
  if (duckdb_append_interval(ctx->appender, interval) == DuckDBError) {
@@ -307,7 +310,7 @@ static VALUE appender__append_time(VALUE self, VALUE hour, VALUE min, VALUE sec,
307
310
  duckdb_time time;
308
311
  rubyDuckDBAppender *ctx;
309
312
 
310
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
313
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
311
314
  time = to_duckdb_time_from_value(hour, min, sec, micros);
312
315
 
313
316
  if (duckdb_append_time(ctx->appender, time) == DuckDBError) {
@@ -321,7 +324,7 @@ static VALUE appender__append_timestamp(VALUE self, VALUE year, VALUE month, VAL
321
324
 
322
325
  rubyDuckDBAppender *ctx;
323
326
 
324
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
327
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
325
328
 
326
329
  timestamp = to_duckdb_timestamp_from_value(year, month, day, hour, min, sec, micros);
327
330
 
@@ -339,7 +342,7 @@ static VALUE appender__append_hugeint(VALUE self, VALUE lower, VALUE upper) {
339
342
 
340
343
  rubyDuckDBAppender *ctx;
341
344
 
342
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
345
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
343
346
  if (duckdb_append_hugeint(ctx->appender, hugeint) == DuckDBError) {
344
347
  rb_raise(eDuckDBError, "failed to append hugeint");
345
348
  }
@@ -348,7 +351,7 @@ static VALUE appender__append_hugeint(VALUE self, VALUE lower, VALUE upper) {
348
351
 
349
352
  static VALUE appender_flush(VALUE self) {
350
353
  rubyDuckDBAppender *ctx;
351
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
354
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
352
355
 
353
356
  if (duckdb_appender_flush(ctx->appender) == DuckDBError) {
354
357
  rb_raise(eDuckDBError, "failed to flush");
@@ -358,7 +361,7 @@ static VALUE appender_flush(VALUE self) {
358
361
 
359
362
  static VALUE appender_close(VALUE self) {
360
363
  rubyDuckDBAppender *ctx;
361
- Data_Get_Struct(self, rubyDuckDBAppender, ctx);
364
+ TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
362
365
 
363
366
  if (duckdb_appender_close(ctx->appender) == DuckDBError) {
364
367
  rb_raise(eDuckDBError, "failed to flush");
@@ -387,9 +390,7 @@ void init_duckdb_appender(void) {
387
390
  rb_define_method(cDuckDBAppender, "append_varchar_length", appender_append_varchar_length, 2);
388
391
  rb_define_method(cDuckDBAppender, "append_blob", appender_append_blob, 1);
389
392
  rb_define_method(cDuckDBAppender, "append_null", appender_append_null, 0);
390
- #ifdef HAVE_DUCKDB_APPEND_DATE
391
393
  rb_define_private_method(cDuckDBAppender, "_append_date", appender__append_date, 3);
392
- #endif
393
394
  rb_define_private_method(cDuckDBAppender, "_append_interval", appender__append_interval, 3);
394
395
  rb_define_private_method(cDuckDBAppender, "_append_time", appender__append_time, 4);
395
396
  rb_define_private_method(cDuckDBAppender, "_append_timestamp", appender__append_timestamp, 7);
data/ext/duckdb/column.c CHANGED
@@ -4,9 +4,16 @@ static VALUE cDuckDBColumn;
4
4
 
5
5
  static void deallocate(void *ctx);
6
6
  static VALUE allocate(VALUE klass);
7
+ static size_t memsize(const void *p);
7
8
  static VALUE duckdb_column__type(VALUE oDuckDBColumn);
8
9
  static VALUE duckdb_column_get_name(VALUE oDuckDBColumn);
9
10
 
11
+ static const rb_data_type_t column_data_type = {
12
+ "DuckDB/Column",
13
+ {NULL, deallocate, memsize,},
14
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
15
+ };
16
+
10
17
  static void deallocate(void *ctx) {
11
18
  rubyDuckDBColumn *p = (rubyDuckDBColumn *)ctx;
12
19
 
@@ -15,7 +22,11 @@ static void deallocate(void *ctx) {
15
22
 
16
23
  static VALUE allocate(VALUE klass) {
17
24
  rubyDuckDBColumn *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBColumn));
18
- return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
25
+ return TypedData_Wrap_Struct(klass, &column_data_type, ctx);
26
+ }
27
+
28
+ static size_t memsize(const void *p) {
29
+ return sizeof(rubyDuckDBColumn);
19
30
  }
20
31
 
21
32
  /*
@@ -23,12 +34,15 @@ static VALUE allocate(VALUE klass) {
23
34
  */
24
35
  VALUE duckdb_column__type(VALUE oDuckDBColumn) {
25
36
  rubyDuckDBColumn *ctx;
26
- Data_Get_Struct(oDuckDBColumn, rubyDuckDBColumn, ctx);
27
-
28
- VALUE result = rb_ivar_get(oDuckDBColumn, rb_intern("result"));
29
37
  rubyDuckDBResult *ctxresult;
30
- Data_Get_Struct(result, rubyDuckDBResult, ctxresult);
31
- duckdb_type type = duckdb_column_type(&(ctxresult->result), ctx->col);
38
+ VALUE result;
39
+ duckdb_type type;
40
+
41
+ TypedData_Get_Struct(oDuckDBColumn, rubyDuckDBColumn, &column_data_type, ctx);
42
+
43
+ result = rb_ivar_get(oDuckDBColumn, rb_intern("result"));
44
+ ctxresult = get_struct_result(result);
45
+ type = duckdb_column_type(&(ctxresult->result), ctx->col);
32
46
 
33
47
  return INT2FIX(type);
34
48
  }
@@ -42,21 +56,24 @@ VALUE duckdb_column__type(VALUE oDuckDBColumn) {
42
56
  */
43
57
  VALUE duckdb_column_get_name(VALUE oDuckDBColumn) {
44
58
  rubyDuckDBColumn *ctx;
45
- Data_Get_Struct(oDuckDBColumn, rubyDuckDBColumn, ctx);
46
-
47
- VALUE result = rb_ivar_get(oDuckDBColumn, rb_intern("result"));
59
+ VALUE result;
48
60
  rubyDuckDBResult *ctxresult;
49
- Data_Get_Struct(result, rubyDuckDBResult, ctxresult);
50
61
 
51
- return rb_str_new2(duckdb_column_name(&(ctxresult->result), ctx->col));
62
+ TypedData_Get_Struct(oDuckDBColumn, rubyDuckDBColumn, &column_data_type, ctx);
63
+
64
+ result = rb_ivar_get(oDuckDBColumn, rb_intern("result"));
65
+
66
+ ctxresult = get_struct_result(result);
67
+
68
+ return rb_utf8_str_new_cstr(duckdb_column_name(&(ctxresult->result), ctx->col));
52
69
  }
53
70
 
54
71
  VALUE create_column(VALUE oDuckDBResult, idx_t col) {
55
72
  VALUE obj;
73
+ rubyDuckDBColumn *ctx;
56
74
 
57
75
  obj = allocate(cDuckDBColumn);
58
- rubyDuckDBColumn *ctx;
59
- Data_Get_Struct(obj, rubyDuckDBColumn, ctx);
76
+ TypedData_Get_Struct(obj, rubyDuckDBColumn, &column_data_type, ctx);
60
77
 
61
78
  rb_ivar_set(obj, rb_intern("result"), oDuckDBResult);
62
79
  ctx->col = col;
data/ext/duckdb/config.c CHANGED
@@ -1,16 +1,21 @@
1
1
  #include "ruby-duckdb.h"
2
2
 
3
- #ifdef HAVE_DUCKDB_CREATE_CONFIG
4
-
5
3
  VALUE cDuckDBConfig;
6
4
 
7
5
  static void deallocate(void *);
8
6
  static VALUE allocate(VALUE klass);
7
+ static size_t memsize(const void *p);
9
8
  static VALUE config_s_size(VALUE klass);
10
9
  static VALUE config_s_get_config_flag(VALUE self, VALUE value);
11
10
  static VALUE config_initialize(VALUE self);
12
11
  static VALUE config_set_config(VALUE self, VALUE key, VALUE value);
13
12
 
13
+ static const rb_data_type_t config_data_type = {
14
+ "DuckDB/Config",
15
+ {NULL, deallocate, memsize,},
16
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
17
+ };
18
+
14
19
  static void deallocate(void * ctx) {
15
20
  rubyDuckDBConfig *p = (rubyDuckDBConfig *)ctx;
16
21
 
@@ -20,13 +25,23 @@ static void deallocate(void * ctx) {
20
25
 
21
26
  static VALUE allocate(VALUE klass) {
22
27
  rubyDuckDBConfig *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBConfig));
23
- return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
28
+ return TypedData_Wrap_Struct(klass, &config_data_type, ctx);
29
+ }
30
+
31
+ static size_t memsize(const void *p) {
32
+ return sizeof(rubyDuckDBConfig);
33
+ }
34
+
35
+ rubyDuckDBConfig *get_struct_config(VALUE obj) {
36
+ rubyDuckDBConfig *ctx;
37
+ TypedData_Get_Struct(obj, rubyDuckDBConfig, &config_data_type, ctx);
38
+ return ctx;
24
39
  }
25
40
 
26
41
  static VALUE config_initialize(VALUE self) {
27
42
  rubyDuckDBConfig *ctx;
28
43
 
29
- Data_Get_Struct(self, rubyDuckDBConfig, ctx);
44
+ TypedData_Get_Struct(self, rubyDuckDBConfig, &config_data_type, ctx);
30
45
 
31
46
  if (duckdb_create_config(&(ctx->config)) == DuckDBError) {
32
47
  rb_raise(eDuckDBError, "failed to create config");
@@ -48,7 +63,7 @@ static VALUE config_s_get_config_flag(VALUE klass, VALUE value) {
48
63
  rb_raise(eDuckDBError, "failed to get config information of index %ld", i);
49
64
  }
50
65
 
51
- return rb_ary_new3(2, rb_str_new2(pkey), rb_str_new2(pdesc));
66
+ return rb_ary_new3(2, rb_utf8_str_new_cstr(pkey), rb_utf8_str_new_cstr(pdesc));
52
67
  }
53
68
 
54
69
  static VALUE config_set_config(VALUE self, VALUE key, VALUE value) {
@@ -56,7 +71,7 @@ static VALUE config_set_config(VALUE self, VALUE key, VALUE value) {
56
71
  const char *pval = StringValuePtr(value);
57
72
 
58
73
  rubyDuckDBConfig *ctx;
59
- Data_Get_Struct(self, rubyDuckDBConfig, ctx);
74
+ TypedData_Get_Struct(self, rubyDuckDBConfig, &config_data_type, ctx);
60
75
 
61
76
  if (duckdb_set_config(ctx->config, pkey, pval) == DuckDBError) {
62
77
  rb_raise(eDuckDBError, "failed to set config %s => %s", pkey, pval);
@@ -73,6 +88,3 @@ void init_duckdb_config(void) {
73
88
  rb_define_method(cDuckDBConfig, "initialize", config_initialize, 0);
74
89
  rb_define_method(cDuckDBConfig, "set_config", config_set_config, 2);
75
90
  }
76
-
77
- #endif
78
-