duckdb 0.2.6.1 → 0.3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,65 @@
1
+ module DuckDB
2
+ if defined?(DuckDB::Config)
3
+ # The DuckDB::Config encapsulates DuckDB Configuration.
4
+ #
5
+ # require 'duckdb'
6
+ # config = DuckDB::Config.new
7
+ # config['default_order'] = 'DESC'
8
+ # db = DuckDB::Database.open(nil, config)
9
+ # con = db.connect
10
+ # con.query('CREATE TABLE numbers (number INTEGER)')
11
+ # con.query('INSERT INTO numbers VALUES (2), (1), (4), (3)')
12
+ #
13
+ # # number is ordered by descending.
14
+ # r = con.query('SELECT number FROM numbers ORDER BY number)
15
+ # r.first.first # => 4
16
+ class Config
17
+ class << self
18
+ #
19
+ # returns available configuration name and the description.
20
+ # The return value is array object. The first element is the configuration
21
+ # name. The second is the description.
22
+ #
23
+ # key, desc = DuckDB::Config.key_description(0)
24
+ # key # => "access_mode"
25
+ # desc # => "Access mode of the database ([AUTOMATIC], READ_ONLY or READ_WRITE)"
26
+ #
27
+ alias key_description get_config_flag
28
+
29
+ #
30
+ # returns the Hash object of all available configuration names and
31
+ # the descriptions.
32
+ #
33
+ # configs = DuckDB::Config.key_descriptions
34
+ # configs['default_order'] # => "The order type used when none is specified ([ASC] or DESC)"
35
+ #
36
+ def key_descriptions
37
+ return @key_descriptions if @key_descriptions
38
+
39
+ n = size
40
+ @key_descriptions = (0...n).each_with_object({}) do |i, hash|
41
+ key, description = key_description(i)
42
+ hash[key] = description
43
+ end
44
+ end
45
+ end
46
+
47
+ #
48
+ # set configuration value
49
+ #
50
+ # config = DuckDB::Config.new
51
+ # # config.set_config('default_order', 'DESC')
52
+ # config['default_order'] = 'DESC'
53
+ #
54
+ # db = DuckDB::Database.open(nil, config)
55
+ # con = db.connect
56
+ # con.query('CREATE TABLE numbers (number INTEGER)')
57
+ # con.query('INSERT INTO numbers VALUES (2), (1), (4), (3)')
58
+ #
59
+ # # numbers are ordered by descending.
60
+ # r = con.query('SELECT number FROM numbers ORDER BY number)
61
+ # r.first.first # => 4
62
+ alias []= set_config
63
+ end
64
+ end
65
+ end
@@ -21,6 +21,7 @@ module DuckDB
21
21
  #
22
22
  class Database
23
23
  private_class_method :_open
24
+ private_class_method :_open_ext if defined?(DuckDB::Config)
24
25
 
25
26
  class << self
26
27
  ##
@@ -38,8 +39,8 @@ module DuckDB
38
39
  # con.query('CREATE TABLE users (id INTEGER, name VARCHAR(30))')
39
40
  # end
40
41
  #
41
- def open(*args)
42
- db = _open(*args)
42
+ def open(dbpath = nil, config = nil)
43
+ db = _db_open(dbpath, config)
43
44
  return db unless block_given?
44
45
 
45
46
  begin
@@ -48,6 +49,18 @@ module DuckDB
48
49
  db.close
49
50
  end
50
51
  end
52
+
53
+ private
54
+
55
+ def _db_open(dbpath, config)
56
+ if defined?(DuckDB::Config) && config
57
+ _open_ext(dbpath, config)
58
+ elsif config
59
+ _open(dbpath, config)
60
+ else
61
+ _open(dbpath)
62
+ end
63
+ end
51
64
  end
52
65
 
53
66
  ##
@@ -22,7 +22,7 @@ module DuckDB
22
22
  when Integer
23
23
  bind_varchar(i, value.to_s)
24
24
  else
25
- rb_raise(ArgumentError, "2nd argument `#{value}` must be Integer.")
25
+ raise(ArgumentError, "2nd argument `#{value}` must be Integer.")
26
26
  end
27
27
  end
28
28
 
@@ -40,7 +40,7 @@ module DuckDB
40
40
  def bind(i, value)
41
41
  case value
42
42
  when NilClass
43
- respond_to?(:bind_null) ? bind_null(i) : rb_raise(DuckDB::Error, 'This bind method does not support nil value. Re-compile ruby-duckdb with DuckDB version >= 0.1.1')
43
+ respond_to?(:bind_null) ? bind_null(i) : raise(DuckDB::Error, 'This bind method does not support nil value. Re-compile ruby-duckdb with DuckDB version >= 0.1.1')
44
44
  when Float
45
45
  bind_double(i, value)
46
46
  when Integer
@@ -63,7 +63,7 @@ module DuckDB
63
63
  when Date
64
64
  bind_varchar(i, value.strftime('%Y-%m-%d'))
65
65
  else
66
- rb_raise(DuckDB::Error, "not supported type #{value} (value.class)")
66
+ raise(DuckDB::Error, "not supported type `#{value}` (#{value.class})")
67
67
  end
68
68
  end
69
69
 
@@ -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.2.6.1'.freeze
4
+ VERSION = '0.3.1.0'.freeze
5
5
  end
data/lib/duckdb.rb CHANGED
@@ -5,6 +5,7 @@ require 'duckdb/connection'
5
5
  require 'duckdb/result'
6
6
  require 'duckdb/prepared_statement'
7
7
  require 'duckdb/appender'
8
+ require 'duckdb/config'
8
9
 
9
10
  # DuckDB provides Ruby interface of DuckDB.
10
11
  module DuckDB
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.2.6.1
4
+ version: 0.3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Suketa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-14 00:00:00.000000000 Z
11
+ date: 2021-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,9 +77,10 @@ extra_rdoc_files: []
77
77
  files:
78
78
  - ".github/workflows/test_on_macos.yml"
79
79
  - ".github/workflows/test_on_ubuntu.yml"
80
+ - ".github/workflows/test_on_windows.yml"
80
81
  - ".gitignore"
81
- - ".travis.yml"
82
82
  - CHANGELOG.md
83
+ - CONTRIBUTION.md
83
84
  - Gemfile
84
85
  - Gemfile.lock
85
86
  - LICENSE
@@ -92,6 +93,8 @@ files:
92
93
  - ext/duckdb/appender.h
93
94
  - ext/duckdb/blob.c
94
95
  - ext/duckdb/blob.h
96
+ - ext/duckdb/config.c
97
+ - ext/duckdb/config.h
95
98
  - ext/duckdb/connection.c
96
99
  - ext/duckdb/connection.h
97
100
  - ext/duckdb/database.c
@@ -107,6 +110,7 @@ files:
107
110
  - ext/duckdb/ruby-duckdb.h
108
111
  - lib/duckdb.rb
109
112
  - lib/duckdb/appender.rb
113
+ - lib/duckdb/config.rb
110
114
  - lib/duckdb/connection.rb
111
115
  - lib/duckdb/database.rb
112
116
  - lib/duckdb/prepared_statement.rb
@@ -127,14 +131,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
131
  requirements:
128
132
  - - ">="
129
133
  - !ruby/object:Gem::Version
130
- version: 2.5.0
134
+ version: 2.6.0
131
135
  required_rubygems_version: !ruby/object:Gem::Requirement
132
136
  requirements:
133
137
  - - ">="
134
138
  - !ruby/object:Gem::Version
135
139
  version: '0'
136
140
  requirements: []
137
- rubygems_version: 3.2.15
141
+ rubygems_version: 3.2.22
138
142
  signing_key:
139
143
  specification_version: 4
140
144
  summary: This module is Ruby binding for DuckDB database engine.
data/.travis.yml DELETED
@@ -1,18 +0,0 @@
1
- language: ruby
2
- cache:
3
- bundler: true
4
- directories:
5
- - ${HOME}/duckdb-v0.2.6
6
- before_install:
7
- - yes | gem update --system
8
- - if [[ ! -d ${HOME}/duckdb-v0.2.6/build ]]; then cd ${HOME} && git clone -b v0.2.6 https://github.com/cwida/duckdb.git duckdb-v0.2.6 && cd duckdb-v0.2.6 && make && cd ${TRAVIS_BUILD_DIR}; fi
9
-
10
- env:
11
- - DUCKDB_VERSION=0.2.6
12
- rvm:
13
- - 2.5.8
14
- - 2.6.7
15
- - 2.7.3
16
- - 3.0.1
17
- - ruby-head
18
- 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/