duckdb 0.0.12 → 0.2.8.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.
@@ -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
@@ -44,6 +44,35 @@ module DuckDB
44
44
  end
45
45
  end
46
46
 
47
+ #
48
+ # returns PreparedStatement object.
49
+ # The first argument is SQL string.
50
+ #
51
+ def prepared_statement(str)
52
+ PreparedStatement.new(self, str)
53
+ end
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
+
47
76
  alias execute query
48
77
  alias open connect
49
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
+ rb_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.
@@ -31,7 +44,12 @@ module DuckDB
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,7 +57,7 @@ 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
@@ -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.12'.freeze
4
+ VERSION = '0.2.8.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.0.12
4
+ version: 0.2.8.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-03-13 00:00:00.000000000 Z
11
+ date: 2021-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,6 +77,7 @@ 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
82
  - ".travis.yml"
82
83
  - CHANGELOG.md
@@ -88,8 +89,12 @@ files:
88
89
  - bin/console
89
90
  - bin/setup
90
91
  - duckdb.gemspec
92
+ - ext/duckdb/appender.c
93
+ - ext/duckdb/appender.h
91
94
  - ext/duckdb/blob.c
92
95
  - ext/duckdb/blob.h
96
+ - ext/duckdb/config.c
97
+ - ext/duckdb/config.h
93
98
  - ext/duckdb/connection.c
94
99
  - ext/duckdb/connection.h
95
100
  - ext/duckdb/database.c
@@ -104,6 +109,8 @@ files:
104
109
  - ext/duckdb/result.h
105
110
  - ext/duckdb/ruby-duckdb.h
106
111
  - lib/duckdb.rb
112
+ - lib/duckdb/appender.rb
113
+ - lib/duckdb/config.rb
107
114
  - lib/duckdb/connection.rb
108
115
  - lib/duckdb/database.rb
109
116
  - lib/duckdb/prepared_statement.rb
@@ -116,7 +123,7 @@ metadata:
116
123
  homepage_uri: https://github.com/suketa/ruby-duckdb
117
124
  source_code_uri: https://github.com/suketa/ruby-duckdb
118
125
  changelog_uri: https://github.com/suketa/ruby-duckdb/blob/master/CHANGELOG.md
119
- post_install_message:
126
+ post_install_message:
120
127
  rdoc_options: []
121
128
  require_paths:
122
129
  - lib
@@ -131,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
138
  - !ruby/object:Gem::Version
132
139
  version: '0'
133
140
  requirements: []
134
- rubygems_version: 3.2.3
135
- signing_key:
141
+ rubygems_version: 3.2.22
142
+ signing_key:
136
143
  specification_version: 4
137
144
  summary: This module is Ruby binding for DuckDB database engine.
138
145
  test_files: []