duckdb 0.2.6.0 → 0.2.9.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
@@ -52,6 +52,27 @@ module DuckDB
52
52
  PreparedStatement.new(self, str)
53
53
  end
54
54
 
55
+ #
56
+ # returns Appender object.
57
+ # The first argument is table name
58
+ #
59
+ def appender(table)
60
+ appender = create_appender(table)
61
+
62
+ return appender unless block_given?
63
+
64
+ yield appender
65
+ appender.flush
66
+ appender.close
67
+ end
68
+
69
+ private
70
+
71
+ def create_appender(table)
72
+ t1, t2 = table.split('.')
73
+ t2 ? Appender.new(self, t1, t2) : Appender.new(self, t2, t1)
74
+ end
75
+
55
76
  alias execute query
56
77
  alias open connect
57
78
  alias close disconnect
@@ -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
  ##
@@ -13,6 +13,19 @@ module DuckDB
13
13
  # stmt.execute
14
14
  class PreparedStatement
15
15
 
16
+ RANGE_INT16 = -32768..32767
17
+ RANGE_INT32 = -2147483648..2147483647
18
+ RANGE_INT64 = -9223372036854775808..9223372036854775807
19
+
20
+ def bind_hugeint(i, value)
21
+ case value
22
+ when Integer
23
+ bind_varchar(i, value.to_s)
24
+ else
25
+ raise(ArgumentError, "2nd argument `#{value}` must be Integer.")
26
+ end
27
+ end
28
+
16
29
  # binds i-th parameter with SQL prepared statement.
17
30
  # The first argument is index of parameter. The index of first parameter is
18
31
  # 1 not 0.
@@ -27,11 +40,16 @@ module DuckDB
27
40
  def bind(i, value)
28
41
  case value
29
42
  when NilClass
30
- 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')
31
44
  when Float
32
45
  bind_double(i, value)
33
46
  when Integer
34
- bind_int64(i, value)
47
+ case value
48
+ when RANGE_INT64
49
+ bind_int64(i, value)
50
+ else
51
+ bind_varchar(i, value.to_s)
52
+ end
35
53
  when String
36
54
  if defined?(DuckDB::Blob)
37
55
  blob?(value) ? bind_blob(i, value) : bind_varchar(i, value)
@@ -39,13 +57,13 @@ module DuckDB
39
57
  bind_varchar(i, value)
40
58
  end
41
59
  when TrueClass, FalseClass
42
- bind_boolean(i, value)
60
+ bind_bool(i, value)
43
61
  when Time
44
62
  bind_varchar(i, value.strftime('%Y-%m-%d %H:%M:%S.%N'))
45
63
  when Date
46
64
  bind_varchar(i, value.strftime('%Y-%m-%d'))
47
65
  else
48
- rb_raise(DuckDB::Error, "not supported type #{value} (value.class)")
66
+ raise(DuckDB::Error, "not supported type `#{value}` (#{value.class})")
49
67
  end
50
68
  end
51
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.0'.freeze
4
+ VERSION = '0.2.9.0'.freeze
5
5
  end
data/lib/duckdb.rb CHANGED
@@ -4,6 +4,8 @@ require 'duckdb/database'
4
4
  require 'duckdb/connection'
5
5
  require 'duckdb/result'
6
6
  require 'duckdb/prepared_statement'
7
+ require 'duckdb/appender'
8
+ require 'duckdb/config'
7
9
 
8
10
  # DuckDB provides Ruby interface of DuckDB.
9
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.0
4
+ version: 0.2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Suketa
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-22 00:00:00.000000000 Z
11
+ date: 2021-10-24 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
@@ -106,6 +109,8 @@ files:
106
109
  - ext/duckdb/result.h
107
110
  - ext/duckdb/ruby-duckdb.h
108
111
  - lib/duckdb.rb
112
+ - lib/duckdb/appender.rb
113
+ - lib/duckdb/config.rb
109
114
  - lib/duckdb/connection.rb
110
115
  - lib/duckdb/database.rb
111
116
  - lib/duckdb/prepared_statement.rb
@@ -118,7 +123,7 @@ metadata:
118
123
  homepage_uri: https://github.com/suketa/ruby-duckdb
119
124
  source_code_uri: https://github.com/suketa/ruby-duckdb
120
125
  changelog_uri: https://github.com/suketa/ruby-duckdb/blob/master/CHANGELOG.md
121
- post_install_message:
126
+ post_install_message:
122
127
  rdoc_options: []
123
128
  require_paths:
124
129
  - lib
@@ -126,15 +131,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
131
  requirements:
127
132
  - - ">="
128
133
  - !ruby/object:Gem::Version
129
- version: 2.5.0
134
+ version: 2.6.0
130
135
  required_rubygems_version: !ruby/object:Gem::Requirement
131
136
  requirements:
132
137
  - - ">="
133
138
  - !ruby/object:Gem::Version
134
139
  version: '0'
135
140
  requirements: []
136
- rubygems_version: 3.3.0.dev
137
- signing_key:
141
+ rubygems_version: 3.2.22
142
+ signing_key:
138
143
  specification_version: 4
139
144
  summary: This module is Ruby binding for DuckDB database engine.
140
145
  test_files: []
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/