duckdb 0.0.6 → 0.0.10

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: 74313dca99b11539431ecfe95cdd3f6392e0993776f292487991cf02e654f78f
4
- data.tar.gz: 151e355bd98be14256b1e78e02eeb7c60dff12e1f2a7ef875e3e9604b7bfb2b3
3
+ metadata.gz: c714dfd673f10a53f717920a00ce3a8d1bd60bb31eaa7c3d678427216ef8446d
4
+ data.tar.gz: 8f8df0fa662a682fc977429c25a6ee41885ca4df603edfcc25cc46f960b1256a
5
5
  SHA512:
6
- metadata.gz: 6da56e491796d920c3c330d5dd2941b6b23f119ebb0bfed4f8e5ae25e2d2f1a83445cd06cd9d0dfab55a19184b9ed6302f04d2f61c038c8352fec8c0ebc60372
7
- data.tar.gz: 8e6f30d324473da40e4e65c7ec8d6a96625eefa835647d8412cc8a8755b5cc29246100ddb2f48f42cc60f006927af4d8b1373b2c1c3e2e6c98f2f891d83fa8e4
6
+ metadata.gz: e67c083420270093e6a026037527f5e10273404d0666b155ee0afd5c7e308ceae268c46ef1f878b9b6a656dec6b97e048488b85be53f715d9253e1806f8601a0
7
+ data.tar.gz: a4501b2e7dc651147564da772f60f32dafbb21ddf846680128406ad9b64dbb6874ea3b6c15cd6e5226d35745680fb7f906eca7d0c8a72bf418594c7cd2486f53
@@ -8,54 +8,54 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
  strategy:
10
10
  matrix:
11
- ruby: ['2.5.x', '2.6.x']
12
- duckdb: ['0.1.2', '0.1.3']
11
+ ruby: ['2.5.8', '2.6.6', '2.7.2', 'head']
12
+ duckdb: ['0.2.2', '0.2.1']
13
13
 
14
14
  steps:
15
- - uses: actions/checkout@v1
15
+ - uses: actions/checkout@v2
16
16
 
17
17
  - name: Set up Ruby
18
- uses: actions/setup-ruby@v1
18
+ uses: ruby/setup-ruby@v1
19
19
  with:
20
20
  ruby-version: ${{ matrix.ruby }}
21
21
 
22
- - name: duckdb 0.1.2 cache
23
- id: duckdb-cache-v0_1_2
22
+ - name: duckdb 0.2.2 cache
23
+ id: duckdb-cache-v0_2_2
24
24
  uses: actions/cache@v1.1.0
25
25
  with:
26
- path: duckdb-v0.1.2
27
- key: ${{ runner.os }}-duckdb-v0_1_2_007
26
+ path: duckdb-v0.2.2
27
+ key: ${{ runner.os }}-duckdb-v0_2_2_001
28
28
  restore-keys: |
29
- ${{ runner.os }}-duckdb-v0_1_2
29
+ ${{ runner.os }}-duckdb-v0_2_2
30
30
 
31
- - name: Build duckdb 0.1.2
32
- if: steps.duckdb-cache-v0_1_2.outputs.cache-hit != 'true'
33
- run: |
34
- git clone -b v0.1.2 https://github.com/cwida/duckdb.git duckdb-tmp-v0.1.2
35
- cd duckdb-tmp-v0.1.2 && make && cd ..
36
- rm -rf duckdb-v0.1.2
37
- mkdir -p duckdb-v0.1.2/build/release/src duckdb-v0.1.2/src
38
- cp -rip duckdb-tmp-v0.1.2/build/release/src/*.so duckdb-v0.1.2/build/release/src
39
- cp -rip duckdb-tmp-v0.1.2/src/include duckdb-v0.1.2/src/
40
-
41
- - name: duckdb 0.1.3 cache
42
- id: duckdb-cache-v0_1_3
31
+ - name: duckdb 0.2.1 cache
32
+ id: duckdb-cache-v0_2_1
43
33
  uses: actions/cache@v1.1.0
44
34
  with:
45
- path: duckdb-v0.1.3
46
- key: ${{ runner.os }}-duckdb-v0_1_3_001
35
+ path: duckdb-v0.2.1
36
+ key: ${{ runner.os }}-duckdb-v0_2_1_001
47
37
  restore-keys: |
48
- ${{ runner.os }}-duckdb-v0_1_3
38
+ ${{ runner.os }}-duckdb-v0_2_1
39
+
40
+ - name: Build duckdb 0.2.2
41
+ if: steps.duckdb-cache-v0_2_2.outputs.cache-hit != 'true'
42
+ run: |
43
+ git clone -b v0.2.2 https://github.com/cwida/duckdb.git duckdb-tmp-v0.2.2
44
+ cd duckdb-tmp-v0.2.2 && make && cd ..
45
+ rm -rf duckdb-v0.2.2
46
+ mkdir -p duckdb-v0.2.2/build/release/src duckdb-v0.2.2/src
47
+ cp -rip duckdb-tmp-v0.2.2/build/release/src/*.so duckdb-v0.2.2/build/release/src
48
+ cp -rip duckdb-tmp-v0.2.2/src/include duckdb-v0.2.2/src/
49
49
 
50
- - name: Build duckdb 0.1.3
51
- if: steps.duckdb-cache-v0_1_3.outputs.cache-hit != 'true'
50
+ - name: Build duckdb 0.2.1
51
+ if: steps.duckdb-cache-v0_2_1.outputs.cache-hit != 'true'
52
52
  run: |
53
- git clone -b v0.1.3 https://github.com/cwida/duckdb.git duckdb-tmp-v0.1.3
54
- cd duckdb-tmp-v0.1.3 && make && cd ..
55
- rm -rf duckdb-v0.1.3
56
- mkdir -p duckdb-v0.1.3/build/release/src duckdb-v0.1.3/src
57
- cp -rip duckdb-tmp-v0.1.3/build/release/src/*.so duckdb-v0.1.3/build/release/src
58
- cp -rip duckdb-tmp-v0.1.3/src/include duckdb-v0.1.3/src/
53
+ git clone -b v0.2.1 https://github.com/cwida/duckdb.git duckdb-tmp-v0.2.1
54
+ cd duckdb-tmp-v0.2.1 && make && cd ..
55
+ rm -rf duckdb-v0.2.1
56
+ mkdir -p duckdb-v0.2.1/build/release/src duckdb-v0.2.1/src
57
+ cp -rip duckdb-tmp-v0.2.1/build/release/src/*.so duckdb-v0.2.1/build/release/src
58
+ cp -rip duckdb-tmp-v0.2.1/src/include duckdb-v0.2.1/src/
59
59
 
60
60
  - name: Build and test with Rake with Ruby ${{ matrix.ruby }}
61
61
  env:
@@ -2,19 +2,16 @@ language: ruby
2
2
  cache:
3
3
  bundler: true
4
4
  directories:
5
- - ${HOME}/duckdb-v0.1.2
6
- - ${HOME}/duckdb-v0.1.3
5
+ - ${HOME}/duckdb-v0.2.2
7
6
  before_install:
8
7
  - yes | gem update --system
9
- - if [[ ! -d ${HOME}/duckdb-v0.1.2/build ]]; then cd ${HOME} && git clone -b v0.1.2 https://github.com/cwida/duckdb.git duckdb-v0.1.2 && cd duckdb-v0.1.2 && make && cd ${TRAVIS_BUILD_DIR}; fi
10
- - if [[ ! -d ${HOME}/duckdb-v0.1.3/build ]]; then cd ${HOME} && git clone -b v0.1.3 https://github.com/cwida/duckdb.git duckdb-v0.1.3 && cd duckdb-v0.1.3 && make && cd ${TRAVIS_BUILD_DIR}; fi
8
+ - if [[ ! -d ${HOME}/duckdb-v0.2.2/build ]]; then cd ${HOME} && git clone -b v0.2.2 https://github.com/cwida/duckdb.git duckdb-v0.2.2 && cd duckdb-v0.2.2 && make && cd ${TRAVIS_BUILD_DIR}; fi
11
9
 
12
10
  env:
13
- - DUCKDB_VERSION=0.1.2
14
- - DUCKDB_VERSION=0.1.3
11
+ - DUCKDB_VERSION=0.2.2
15
12
  rvm:
16
- - 2.5.7
17
- - 2.6.5
18
- - 2.7.0
13
+ - 2.5.8
14
+ - 2.6.6
15
+ - 2.7.2
19
16
  - ruby-head
20
17
  script: bundle exec rake -- --with-duckdb-include=${HOME}/duckdb-v${DUCKDB_VERSION}/src/include --with-duckdb-lib=${HOME}/duckdb-v${DUCKDB_VERSION}/build/release/src/
@@ -1,5 +1,45 @@
1
1
  # ChangeLog
2
2
 
3
+ ## 0.0.10
4
+
5
+ - bump DuckDB to v0.2.2
6
+ - fix to build failure on MAC OS/X
7
+
8
+ ## 0.0.9
9
+
10
+ - bump DuckDB to v0.2.1
11
+ - bump Ruby to v2.7.2
12
+ - bunmp DuckDB to v0.2.0
13
+
14
+ ## 0.0.8.1
15
+
16
+ - update Gemfile.lock
17
+ - unsupport Ruby 2.4
18
+
19
+ ## 0.0.8
20
+
21
+ - remove test with Ruby 2.4.10
22
+ - bump DuckDB to v0.1.8
23
+ - bump DuckDB to v0.1.8
24
+ - bump DuckDB to v0.1.7
25
+ - current ruby-duckdb supports DuckDB version 0.1.5 and 0.1.6
26
+ - support Ruby 2.7.1
27
+ - bump DuckDB to v0.1.6
28
+ - current ruby-duckdb supports DuckDB version 0.1.5 and 0.1.6
29
+ - DuckDB::Connection#connect accepts block
30
+ - add DuckDB::Connection#connect
31
+ - DuckDB::Database#connect accepts block
32
+ - DuckDB::Database.open accepts block
33
+ - update duckdb.gemspec, required ruby version >= 2.4.0
34
+
35
+ ## 0.0.7
36
+
37
+ - bump DuckDB to v0.1.5
38
+ - DuckDB version must be 0.1.5 or later.
39
+ - add DuckDB::Connection#connect, alias method open
40
+ - add DuckDB::Connection#disconnect, alias method close
41
+ - add DuckDB::Database#close
42
+
3
43
  ## 0.0.6
4
44
 
5
45
  - add alias `execute` of `DuckDB::Connection#query`
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- duckdb (0.0.6)
4
+ duckdb (0.0.10)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- minitest (5.13.0)
9
+ minitest (5.14.2)
10
10
  rake (13.0.1)
11
- rake-compiler (1.1.0)
11
+ rake-compiler (1.1.1)
12
12
  rake
13
13
 
14
14
  PLATFORMS
data/README.md CHANGED
@@ -42,3 +42,24 @@ result.each do |row|
42
42
  p row
43
43
  end
44
44
  ```
45
+
46
+ Or, you can use block.
47
+
48
+ ```
49
+ require 'duckdb'
50
+
51
+ DuckDB::Database.open do |db|
52
+ db.connect do |con|
53
+ con.query('CREATE TABLE users (id INTEGER, name VARCHAR(30))')
54
+
55
+ con.query("INSERT into users VALUES(1, 'Alice')")
56
+ con.query("INSERT into users VALUES(2, 'Bob')")
57
+ con.query("INSERT into users VALUES(3, 'Cathy')")
58
+
59
+ result = con.query('SELECT * from users')
60
+ result.each do |row|
61
+ p row
62
+ end
63
+ end
64
+ end
65
+ ```
@@ -1,32 +1,35 @@
1
- lib = File.expand_path("lib", __dir__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "duckdb/version"
5
+ require 'duckdb/version'
4
6
 
5
7
  Gem::Specification.new do |spec|
6
- spec.name = "duckdb"
8
+ spec.name = 'duckdb'
7
9
  spec.version = DuckDB::VERSION
8
- spec.authors = ["Masaki Suketa"]
9
- spec.email = ["masaki.suketa@nifty.ne.jp"]
10
+ spec.authors = ['Masaki Suketa']
11
+ spec.email = ['masaki.suketa@nifty.ne.jp']
10
12
 
11
- spec.summary = %q{This module is Ruby binding for DuckDB database engine.}
12
- spec.description = "This module is Ruby binding for DuckDB database engine. You must have the DuckDB engine installed to build/use this module."
13
- spec.homepage = "https://github.com/suketa/ruby-duckdb"
14
- spec.license = "MIT"
13
+ spec.summary = 'This module is Ruby binding for DuckDB database engine.'
14
+ spec.description = 'This module is Ruby binding for DuckDB database engine. You must have the DuckDB engine installed to build/use this module.'
15
+ spec.homepage = 'https://github.com/suketa/ruby-duckdb'
16
+ spec.license = 'MIT'
15
17
 
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/suketa/ruby-duckdb"
18
- spec.metadata["changelog_uri"] = "https://github.com/suketa/ruby-duckdb/blob/master/CHANGELOG.md"
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/suketa/ruby-duckdb'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/suketa/ruby-duckdb/blob/master/CHANGELOG.md'
19
21
 
20
22
  # Specify which files should be added to the gem when it is released.
21
23
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
25
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
26
  end
25
- spec.require_paths = ["lib"]
26
- spec.extensions = ["ext/duckdb/extconf.rb"]
27
+ spec.require_paths = ['lib']
28
+ spec.extensions = ['ext/duckdb/extconf.rb']
29
+ spec.required_ruby_version = '>= 2.5.0'
27
30
 
28
- spec.add_development_dependency "bundler", "~> 2.0"
29
- spec.add_development_dependency "rake", "~> 13.0"
30
- spec.add_development_dependency "rake-compiler"
31
- spec.add_development_dependency "minitest", "~> 5.0"
31
+ spec.add_development_dependency 'bundler', '~> 2.0'
32
+ spec.add_development_dependency 'minitest', '~> 5.0'
33
+ spec.add_development_dependency 'rake', '~> 13.0'
34
+ spec.add_development_dependency 'rake-compiler'
32
35
  end
@@ -1,5 +1,7 @@
1
1
  #include "ruby-duckdb.h"
2
2
 
3
+ VALUE cDuckDBConnection;
4
+
3
5
  static void deallocate(void *ctx)
4
6
  {
5
7
  rubyDuckDBConnection *p = (rubyDuckDBConnection *)ctx;
@@ -33,6 +35,34 @@ VALUE create_connection(VALUE oDuckDBDatabase)
33
35
  return obj;
34
36
  }
35
37
 
38
+ static VALUE duckdb_connection_disconnect(VALUE self)
39
+ {
40
+ rubyDuckDBConnection *ctx;
41
+
42
+ Data_Get_Struct(self, rubyDuckDBConnection, ctx);
43
+ duckdb_disconnect(&(ctx->con));
44
+
45
+ return self;
46
+ }
47
+
48
+ static VALUE duckdb_connection_connect(VALUE self, VALUE oDuckDBDatabase)
49
+ {
50
+ rubyDuckDBConnection *ctx;
51
+ rubyDuckDB *ctxdb;
52
+
53
+ if (!rb_obj_is_kind_of(oDuckDBDatabase, cDuckDBDatabase)) {
54
+ rb_raise(rb_eTypeError, "The first argument must be DuckDB::Database object.");
55
+ }
56
+ Data_Get_Struct(oDuckDBDatabase, rubyDuckDB, ctxdb);
57
+ Data_Get_Struct(self, rubyDuckDBConnection, ctx);
58
+
59
+ if (duckdb_connect(ctxdb->db, &(ctx->con)) == DuckDBError) {
60
+ rb_raise(eDuckDBError, "connection error");
61
+ }
62
+
63
+ return self;
64
+ }
65
+
36
66
  static VALUE duckdb_connection_query_sql(VALUE self, VALUE str)
37
67
  {
38
68
  rubyDuckDBConnection *ctx;
@@ -43,6 +73,10 @@ static VALUE duckdb_connection_query_sql(VALUE self, VALUE str)
43
73
  Data_Get_Struct(self, rubyDuckDBConnection, ctx);
44
74
  Data_Get_Struct(result, rubyDuckDBResult, ctxr);
45
75
 
76
+ if (!(ctx->con)) {
77
+ rb_raise(eDuckDBError, "Database connection closed");
78
+ }
79
+
46
80
  if (duckdb_query(ctx->con, StringValueCStr(str), &(ctxr->result)) == DuckDBError) {
47
81
  rb_raise(eDuckDBError, "%s", ctxr->result.error_message);
48
82
  }
@@ -54,5 +88,7 @@ void init_duckdb_connection(void)
54
88
  cDuckDBConnection = rb_define_class_under(mDuckDB, "Connection", rb_cObject);
55
89
  rb_define_alloc_func(cDuckDBConnection, allocate);
56
90
 
91
+ rb_define_method(cDuckDBConnection, "disconnect", duckdb_connection_disconnect, 0);
92
+ rb_define_private_method(cDuckDBConnection, "_connect", duckdb_connection_connect, 1);
57
93
  rb_define_private_method(cDuckDBConnection, "query_sql", duckdb_connection_query_sql, 1);
58
94
  }
@@ -7,8 +7,6 @@ struct _rubyDuckDBConnection {
7
7
 
8
8
  typedef struct _rubyDuckDBConnection rubyDuckDBConnection;
9
9
 
10
- VALUE cDuckDBConnection;
11
-
12
10
  void init_duckdb_connection(void);
13
11
  VALUE create_connection(VALUE oDuckDBDatabase);
14
12
 
@@ -1,10 +1,17 @@
1
1
  #include "ruby-duckdb.h"
2
2
 
3
+ VALUE cDuckDBDatabase;
4
+
5
+ static void close_database(rubyDuckDB *p)
6
+ {
7
+ duckdb_close(&(p->db));
8
+ }
9
+
3
10
  static void deallocate(void * ctx)
4
11
  {
5
12
  rubyDuckDB *p = (rubyDuckDB *)ctx;
6
13
 
7
- duckdb_close(&(p->db));
14
+ close_database(p);
8
15
  xfree(p);
9
16
  }
10
17
 
@@ -41,10 +48,25 @@ static VALUE duckdb_database_connect(VALUE self)
41
48
  return create_connection(self);
42
49
  }
43
50
 
51
+ /*
52
+ * call-seq:
53
+ * duckdb.close -> DuckDB::Database
54
+ *
55
+ * closes DuckDB database.
56
+ */
57
+ static VALUE duckdb_database_close(VALUE self)
58
+ {
59
+ rubyDuckDB *ctx;
60
+ Data_Get_Struct(self, rubyDuckDB, ctx);
61
+ close_database(ctx);
62
+ return self;
63
+ }
64
+
44
65
  void init_duckdb_database(void)
45
66
  {
46
- VALUE cDuckDBDatabase = rb_define_class_under(mDuckDB, "Database", rb_cObject);
67
+ cDuckDBDatabase = rb_define_class_under(mDuckDB, "Database", rb_cObject);
47
68
  rb_define_alloc_func(cDuckDBDatabase, allocate);
48
- rb_define_singleton_method(cDuckDBDatabase, "open", duckdb_database_s_open, -1);
49
- rb_define_method(cDuckDBDatabase, "connect", duckdb_database_connect, 0);
69
+ rb_define_singleton_method(cDuckDBDatabase, "_open", duckdb_database_s_open, -1);
70
+ rb_define_private_method(cDuckDBDatabase, "_connect", duckdb_database_connect, 0);
71
+ rb_define_method(cDuckDBDatabase, "close", duckdb_database_close, 0);
50
72
  }
@@ -1,5 +1,7 @@
1
1
  #include "ruby-duckdb.h"
2
2
 
3
+ VALUE eDuckDBError;
4
+
3
5
  void init_duckdb_error(void)
4
6
  {
5
7
  eDuckDBError = rb_define_class_under(mDuckDB, "Error", rb_eStandardError);
@@ -1,8 +1,6 @@
1
1
  #ifndef RUBY_DUCKDB_ERROR_H
2
2
  #define RUBY_DUCKDB_ERROR_H
3
3
 
4
- VALUE eDuckDBError;
5
-
6
4
  void init_duckdb_error(void);
7
5
 
8
6
  #endif
@@ -2,6 +2,5 @@ require 'mkmf'
2
2
 
3
3
  dir_config('duckdb')
4
4
  if have_library('duckdb')
5
- have_func('duckdb_bind_null', 'duckdb.h')
6
5
  create_makefile('duckdb/duckdb_native')
7
6
  end
@@ -61,9 +61,9 @@ static VALUE duckdb_prepared_statement_execute(VALUE self)
61
61
  return result;
62
62
  }
63
63
 
64
- static index_t check_index(VALUE vidx)
64
+ static idx_t check_index(VALUE vidx)
65
65
  {
66
- index_t idx = FIX2INT(vidx);
66
+ idx_t idx = FIX2INT(vidx);
67
67
  if (idx <= 0) {
68
68
  rb_raise(rb_eArgError, "index of parameter must be greater than 0");
69
69
  }
@@ -73,7 +73,7 @@ static index_t check_index(VALUE vidx)
73
73
  static VALUE duckdb_prepared_statement_bind_boolean(VALUE self, VALUE vidx, VALUE val)
74
74
  {
75
75
  rubyDuckDBPreparedStatement *ctx;
76
- index_t idx = check_index(vidx);
76
+ idx_t idx = check_index(vidx);
77
77
 
78
78
  Data_Get_Struct(self, rubyDuckDBPreparedStatement, ctx);
79
79
  if (val != Qtrue && val != Qfalse) {
@@ -81,7 +81,7 @@ static VALUE duckdb_prepared_statement_bind_boolean(VALUE self, VALUE vidx, VALU
81
81
  }
82
82
 
83
83
  if (duckdb_bind_boolean(ctx->prepared_statement, idx, (val == Qtrue)) == DuckDBError) {
84
- rb_raise(eDuckDBError, "fail to bind %ld parameter", idx);
84
+ rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
85
85
  }
86
86
  return self;
87
87
  }
@@ -89,13 +89,13 @@ static VALUE duckdb_prepared_statement_bind_boolean(VALUE self, VALUE vidx, VALU
89
89
  static VALUE duckdb_prepared_statement_bind_int16(VALUE self, VALUE vidx, VALUE val)
90
90
  {
91
91
  rubyDuckDBPreparedStatement *ctx;
92
- index_t idx = check_index(vidx);
92
+ idx_t idx = check_index(vidx);
93
93
  int16_t i16val = NUM2INT(val);
94
94
 
95
95
  Data_Get_Struct(self, rubyDuckDBPreparedStatement, ctx);
96
96
 
97
97
  if (duckdb_bind_int16(ctx->prepared_statement, idx, i16val) == DuckDBError) {
98
- rb_raise(eDuckDBError, "fail to bind %ld parameter", idx);
98
+ rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
99
99
  }
100
100
  return self;
101
101
  }
@@ -103,13 +103,13 @@ static VALUE duckdb_prepared_statement_bind_int16(VALUE self, VALUE vidx, VALUE
103
103
  static VALUE duckdb_prepared_statement_bind_int32(VALUE self, VALUE vidx, VALUE val)
104
104
  {
105
105
  rubyDuckDBPreparedStatement *ctx;
106
- index_t idx = check_index(vidx);
107
- int32_t i32val = NUM2LONG(val);
106
+ idx_t idx = check_index(vidx);
107
+ int32_t i32val = NUM2INT(val);
108
108
 
109
109
  Data_Get_Struct(self, rubyDuckDBPreparedStatement, ctx);
110
110
 
111
111
  if (duckdb_bind_int32(ctx->prepared_statement, idx, i32val) == DuckDBError) {
112
- rb_raise(eDuckDBError, "fail to bind %ld parameter", idx);
112
+ rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
113
113
  }
114
114
  return self;
115
115
  }
@@ -117,13 +117,13 @@ static VALUE duckdb_prepared_statement_bind_int32(VALUE self, VALUE vidx, VALUE
117
117
  static VALUE duckdb_prepared_statement_bind_int64(VALUE self, VALUE vidx, VALUE val)
118
118
  {
119
119
  rubyDuckDBPreparedStatement *ctx;
120
- index_t idx = check_index(vidx);
120
+ idx_t idx = check_index(vidx);
121
121
  int64_t i64val = NUM2LL(val);
122
122
 
123
123
  Data_Get_Struct(self, rubyDuckDBPreparedStatement, ctx);
124
124
 
125
125
  if (duckdb_bind_int64(ctx->prepared_statement, idx, i64val) == DuckDBError) {
126
- rb_raise(eDuckDBError, "fail to bind %ld parameter", idx);
126
+ rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
127
127
  }
128
128
  return self;
129
129
  }
@@ -131,13 +131,13 @@ static VALUE duckdb_prepared_statement_bind_int64(VALUE self, VALUE vidx, VALUE
131
131
  static VALUE duckdb_prepared_statement_bind_float(VALUE self, VALUE vidx, VALUE val)
132
132
  {
133
133
  rubyDuckDBPreparedStatement *ctx;
134
- index_t idx = check_index(vidx);
134
+ idx_t idx = check_index(vidx);
135
135
  double dbl = NUM2DBL(val);
136
136
 
137
137
  Data_Get_Struct(self, rubyDuckDBPreparedStatement, ctx);
138
138
 
139
139
  if (duckdb_bind_float(ctx->prepared_statement, idx, (float)dbl) == DuckDBError) {
140
- rb_raise(eDuckDBError, "fail to bind %ld parameter", idx);
140
+ rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
141
141
  }
142
142
  return self;
143
143
  }
@@ -145,13 +145,13 @@ static VALUE duckdb_prepared_statement_bind_float(VALUE self, VALUE vidx, VALUE
145
145
  static VALUE duckdb_prepared_statement_bind_double(VALUE self, VALUE vidx, VALUE val)
146
146
  {
147
147
  rubyDuckDBPreparedStatement *ctx;
148
- index_t idx = check_index(vidx);
148
+ idx_t idx = check_index(vidx);
149
149
  double dbl = NUM2DBL(val);
150
150
 
151
151
  Data_Get_Struct(self, rubyDuckDBPreparedStatement, ctx);
152
152
 
153
153
  if (duckdb_bind_double(ctx->prepared_statement, idx, dbl) == DuckDBError) {
154
- rb_raise(eDuckDBError, "fail to bind %ld parameter", idx);
154
+ rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
155
155
  }
156
156
  return self;
157
157
  }
@@ -159,28 +159,26 @@ static VALUE duckdb_prepared_statement_bind_double(VALUE self, VALUE vidx, VALUE
159
159
  static VALUE duckdb_prepared_statement_bind_varchar(VALUE self, VALUE vidx, VALUE str)
160
160
  {
161
161
  rubyDuckDBPreparedStatement *ctx;
162
- index_t idx = check_index(vidx);
162
+ idx_t idx = check_index(vidx);
163
163
 
164
164
  Data_Get_Struct(self, rubyDuckDBPreparedStatement, ctx);
165
165
  if (duckdb_bind_varchar(ctx->prepared_statement, idx, StringValuePtr(str)) == DuckDBError) {
166
- rb_raise(eDuckDBError, "fail to bind %ld parameter", idx);
166
+ rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
167
167
  }
168
168
  return self;
169
169
  }
170
170
 
171
- #ifdef HAVE_DUCKDB_BIND_NULL
172
171
  static VALUE duckdb_prepared_statement_bind_null(VALUE self, VALUE vidx)
173
172
  {
174
173
  rubyDuckDBPreparedStatement *ctx;
175
- index_t idx = check_index(vidx);
174
+ idx_t idx = check_index(vidx);
176
175
 
177
176
  Data_Get_Struct(self, rubyDuckDBPreparedStatement, ctx);
178
177
  if (duckdb_bind_null(ctx->prepared_statement, idx) == DuckDBError) {
179
- rb_raise(eDuckDBError, "fail to bind %ld parameter", idx);
178
+ rb_raise(eDuckDBError, "fail to bind %llu parameter", (unsigned long long)idx);
180
179
  }
181
180
  return self;
182
181
  }
183
- #endif
184
182
 
185
183
  void init_duckdb_prepared_statement(void)
186
184
  {
@@ -198,8 +196,5 @@ void init_duckdb_prepared_statement(void)
198
196
  rb_define_method(cDuckDBPreparedStatement, "bind_float", duckdb_prepared_statement_bind_float, 2);
199
197
  rb_define_method(cDuckDBPreparedStatement, "bind_double", duckdb_prepared_statement_bind_double, 2);
200
198
  rb_define_method(cDuckDBPreparedStatement, "bind_varchar", duckdb_prepared_statement_bind_varchar, 2);
201
- #ifdef HAVE_DUCKDB_BIND_NULL
202
- /* duckdb version > 0.1.1 */
203
199
  rb_define_method(cDuckDBPreparedStatement, "bind_null", duckdb_prepared_statement_bind_null, 1);
204
- #endif
205
200
  }
@@ -3,7 +3,7 @@
3
3
 
4
4
  struct _rubyDuckDBPreparedStatement {
5
5
  duckdb_prepared_statement prepared_statement;
6
- index_t nparams;
6
+ idx_t nparams;
7
7
  };
8
8
 
9
9
  typedef struct _rubyDuckDBPreparedStatement rubyDuckDBPreparedStatement;
@@ -16,43 +16,43 @@ static VALUE allocate(VALUE klass)
16
16
  return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
17
17
  }
18
18
 
19
- static VALUE to_ruby_obj_boolean(duckdb_result *result, index_t col_idx, index_t row_idx)
19
+ static VALUE to_ruby_obj_boolean(duckdb_result *result, idx_t col_idx, idx_t row_idx)
20
20
  {
21
21
  bool bval = duckdb_value_boolean(result, col_idx, row_idx);
22
22
  return bval ? Qtrue : Qnil;
23
23
  }
24
24
 
25
- static VALUE to_ruby_obj_smallint(duckdb_result *result, index_t col_idx, index_t row_idx)
25
+ static VALUE to_ruby_obj_smallint(duckdb_result *result, idx_t col_idx, idx_t row_idx)
26
26
  {
27
27
  int16_t i16val = duckdb_value_int16(result, col_idx, row_idx);
28
28
  return INT2FIX(i16val);
29
29
  }
30
30
 
31
- static VALUE to_ruby_obj_integer(duckdb_result *result, index_t col_idx, index_t row_idx)
31
+ static VALUE to_ruby_obj_integer(duckdb_result *result, idx_t col_idx, idx_t row_idx)
32
32
  {
33
33
  int32_t i32val = duckdb_value_int32(result, col_idx, row_idx);
34
34
  return INT2NUM(i32val);
35
35
  }
36
36
 
37
- static VALUE to_ruby_obj_bigint(duckdb_result *result, index_t col_idx, index_t row_idx)
37
+ static VALUE to_ruby_obj_bigint(duckdb_result *result, idx_t col_idx, idx_t row_idx)
38
38
  {
39
39
  int64_t i64val = duckdb_value_int64(result, col_idx, row_idx);
40
40
  return rb_int2big(i64val);
41
41
  }
42
42
 
43
- static VALUE to_ruby_obj_float(duckdb_result *result, index_t col_idx, index_t row_idx)
43
+ static VALUE to_ruby_obj_float(duckdb_result *result, idx_t col_idx, idx_t row_idx)
44
44
  {
45
45
  float fval = duckdb_value_float(result, col_idx, row_idx);
46
46
  return DBL2NUM(fval);
47
47
  }
48
48
 
49
- static VALUE to_ruby_obj_double(duckdb_result *result, index_t col_idx, index_t row_idx)
49
+ static VALUE to_ruby_obj_double(duckdb_result *result, idx_t col_idx, idx_t row_idx)
50
50
  {
51
51
  double dval = duckdb_value_double(result, col_idx, row_idx);
52
52
  return DBL2NUM(dval);
53
53
  }
54
54
 
55
- static VALUE to_ruby_obj(duckdb_result *result, index_t col_idx, index_t row_idx)
55
+ static VALUE to_ruby_obj(duckdb_result *result, idx_t col_idx, idx_t row_idx)
56
56
  {
57
57
  char *p;
58
58
  VALUE obj = Qnil;
@@ -80,9 +80,9 @@ static VALUE to_ruby_obj(duckdb_result *result, index_t col_idx, index_t row_idx
80
80
  return obj;
81
81
  }
82
82
 
83
- static VALUE row_array(rubyDuckDBResult *ctx, index_t row_idx)
83
+ static VALUE row_array(rubyDuckDBResult *ctx, idx_t row_idx)
84
84
  {
85
- index_t col_idx;
85
+ idx_t col_idx;
86
86
  VALUE ary = rb_ary_new2(ctx->result.column_count);
87
87
  for(col_idx = 0; col_idx < ctx->result.column_count; col_idx++) {
88
88
  rb_ary_store(ary, col_idx, to_ruby_obj(&(ctx->result), col_idx, row_idx));
@@ -101,7 +101,7 @@ static VALUE duckdb_result_row_size(VALUE oDuckDBResult, VALUE args, VALUE obj)
101
101
  static VALUE duckdb_result_each(VALUE oDuckDBResult)
102
102
  {
103
103
  rubyDuckDBResult *ctx;
104
- index_t row_idx = 0;
104
+ idx_t row_idx = 0;
105
105
 
106
106
  RETURN_SIZED_ENUMERATOR(oDuckDBResult, 0, 0, duckdb_result_row_size);
107
107
 
@@ -10,5 +10,8 @@
10
10
  #include "./prepared_statement.h"
11
11
 
12
12
  extern VALUE mDuckDB;
13
+ extern VALUE cDuckDBDatabase;
14
+ extern VALUE cDuckDBConnection;
15
+ extern VALUE eDuckDBError;
13
16
 
14
17
  #endif
@@ -1,7 +1,7 @@
1
+ require 'duckdb/duckdb_native'
1
2
  require 'duckdb/version'
2
3
  require 'duckdb/database'
3
4
  require 'duckdb/connection'
4
- require 'duckdb/duckdb_native'
5
5
  require 'duckdb/result'
6
6
  require 'duckdb/prepared_statement'
7
7
 
@@ -29,6 +29,23 @@ module DuckDB
29
29
  stmt.execute
30
30
  end
31
31
 
32
+ #
33
+ # connects DuckDB database
34
+ # The first argument is DuckDB::Database object
35
+ #
36
+ def connect(db)
37
+ conn = _connect(db)
38
+ return conn unless block_given?
39
+
40
+ begin
41
+ yield conn
42
+ ensure
43
+ conn.disconnect
44
+ end
45
+ end
46
+
32
47
  alias execute query
48
+ alias open connect
49
+ alias close disconnect
33
50
  end
34
51
  end
@@ -20,5 +20,58 @@ module DuckDB
20
20
  # end
21
21
  #
22
22
  class Database
23
+ private_class_method :_open
24
+
25
+ class << self
26
+ ##
27
+ # Opens database.
28
+ # The first argument is DuckDB database file path to open.
29
+ # If there is no argument, the method opens DuckDB database in memory.
30
+ # The method yields block if block is given.
31
+ #
32
+ # DuckDB::Database.open('duckdb_database.db') #=> DuckDB::Database
33
+ #
34
+ # DuckDB::Database.open #=> opens DuckDB::Database in memory.
35
+ #
36
+ # DuckDB::Database.open do |db|
37
+ # con = db.connect
38
+ # con.query('CREATE TABLE users (id INTEGER, name VARCHAR(30))')
39
+ # end
40
+ #
41
+ def open(*args)
42
+ db = _open(*args)
43
+ return db unless block_given?
44
+
45
+ begin
46
+ yield db
47
+ ensure
48
+ db.close
49
+ end
50
+ end
51
+ end
52
+
53
+ ##
54
+ # connects database.
55
+ #
56
+ # The method yields block and disconnects the database if block given
57
+ #
58
+ # db = DuckDB::Database.open
59
+ #
60
+ # con = db.connect # => DuckDB::Connection
61
+ #
62
+ # db.connect do |con|
63
+ # con.query('CREATE TABLE users (id INTEGER, name VARCHAR(30))')
64
+ # end
65
+ #
66
+ def connect
67
+ conn = _connect
68
+ return conn unless block_given?
69
+
70
+ begin
71
+ yield conn
72
+ ensure
73
+ conn.disconnect
74
+ end
75
+ end
23
76
  end
24
77
  end
@@ -1,5 +1,5 @@
1
1
  module DuckDB
2
2
  # The version string of ruby-duckdb.
3
3
  # Currently, ruby-duckdb is NOT semantic versioning.
4
- VERSION = '0.0.6'.freeze
4
+ VERSION = '0.0.10'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duckdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Suketa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-15 00:00:00.000000000 Z
11
+ date: 2020-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,47 +25,47 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '13.0'
33
+ version: '5.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '13.0'
40
+ version: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake-compiler
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest
56
+ name: rake-compiler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '5.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '5.0'
68
+ version: '0'
69
69
  description: This module is Ruby binding for DuckDB database engine. You must have
70
70
  the DuckDB engine installed to build/use this module.
71
71
  email:
@@ -121,14 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: 2.5.0
125
125
  required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - ">="
128
128
  - !ruby/object:Gem::Version
129
129
  version: '0'
130
130
  requirements: []
131
- rubygems_version: 3.1.2
131
+ rubygems_version: 3.2.0.rc.2
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: This module is Ruby binding for DuckDB database engine.