duckdb 0.2.9.0 → 0.3.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  require 'date'
2
+ require_relative './converter'
2
3
 
3
4
  module DuckDB
4
5
  # The DuckDB::PreparedStatement encapsulates connection with DuckDB prepared
@@ -12,6 +13,7 @@ module DuckDB
12
13
  # stmt.bind(1, 'email@example.com')
13
14
  # stmt.execute
14
15
  class PreparedStatement
16
+ include DuckDB::Converter
15
17
 
16
18
  RANGE_INT16 = -32768..32767
17
19
  RANGE_INT32 = -2147483648..2147483647
@@ -27,8 +29,113 @@ module DuckDB
27
29
  end
28
30
 
29
31
  # binds i-th parameter with SQL prepared statement.
30
- # The first argument is index of parameter. The index of first parameter is
31
- # 1 not 0.
32
+ # The first argument is index of parameter.
33
+ # The index of first parameter is 1 not 0.
34
+ # The second argument value is to expected date.
35
+ #
36
+ # require 'duckdb'
37
+ # db = DuckDB::Database.open('duckdb_database')
38
+ # con = db.connect
39
+ # sql ='SELECT name FROM users WHERE birth_day = ?'
40
+ # stmt = PreparedStatement.new(con, sql)
41
+ # stmt.bind(1, Date.today)
42
+ # # or you can specify date string.
43
+ # # stmt.bind(1, '2021-02-23')
44
+ def bind_date(i, value)
45
+ case value
46
+ when Date, Time
47
+ date = value
48
+ else
49
+ begin
50
+ date = Date.parse(value)
51
+ rescue => e
52
+ raise(ArgumentError, "Cannot parse argument value to date. #{e.message}")
53
+ end
54
+ end
55
+
56
+ _bind_date(i, date.year, date.month, date.day)
57
+ end
58
+
59
+ # binds i-th parameter with SQL prepared statement.
60
+ # The first argument is index of parameter.
61
+ # The index of first parameter is 1 not 0.
62
+ # The second argument value is to expected time value.
63
+ #
64
+ # require 'duckdb'
65
+ # db = DuckDB::Database.open('duckdb_database')
66
+ # con = db.connect
67
+ # sql ='SELECT name FROM users WHERE birth_time = ?'
68
+ # stmt = PreparedStatement.new(con, sql)
69
+ # stmt.bind(1, Time.now)
70
+ # # or you can specify time string.
71
+ # # stmt.bind(1, '07:39:45')
72
+ def bind_time(i, value)
73
+ case value
74
+ when Time
75
+ time = value
76
+ else
77
+ begin
78
+ time = Time.parse(value)
79
+ rescue => e
80
+ raise(ArgumentError, "Cannot parse argument value to time. #{e.message}")
81
+ end
82
+ end
83
+
84
+ _bind_time(i, time.hour, time.min, time.sec, time.usec)
85
+ end
86
+
87
+ # binds i-th parameter with SQL prepared statement.
88
+ # The first argument is index of parameter.
89
+ # The index of first parameter is 1 not 0.
90
+ # The second argument value is to expected time value.
91
+ #
92
+ # require 'duckdb'
93
+ # db = DuckDB::Database.open('duckdb_database')
94
+ # con = db.connect
95
+ # sql ='SELECT name FROM users WHERE created_at = ?'
96
+ # stmt = PreparedStatement.new(con, sql)
97
+ # stmt.bind(1, Time.now)
98
+ # # or you can specify timestamp string.
99
+ # # stmt.bind(1, '2022-02-23 07:39:45')
100
+ def bind_timestamp(i, value)
101
+ case value
102
+ when Time
103
+ time = value
104
+ else
105
+ begin
106
+ time = Time.parse(value)
107
+ rescue => e
108
+ raise(ArgumentError, "Cannot parse argument value to time. #{e.message}")
109
+ end
110
+ end
111
+
112
+ _bind_timestamp(i, time.year, time.month, time.day, time.hour, time.min, time.sec, time.usec)
113
+ end
114
+
115
+ # binds i-th parameter with SQL prepared statement.
116
+ # The first argument is index of parameter.
117
+ # The index of first parameter is 1 not 0.
118
+ # The second argument value is to expected ISO8601 time interval string.
119
+ #
120
+ # require 'duckdb'
121
+ # db = DuckDB::Database.open('duckdb_database')
122
+ # con = db.connect
123
+ # sql ='SELECT value FROM intervals WHERE interval = ?'
124
+ # stmt = PreparedStatement.new(con, sql)
125
+ # stmt.bind(1, 'P1Y2D')
126
+ def bind_interval(i, value)
127
+ raise ArgumentError, "Argument `#{value}` must be a string." unless value.is_a?(String)
128
+
129
+ hash = iso8601_interval_to_hash(value)
130
+
131
+ months, days, micros = hash_to__append_interval_args(hash)
132
+
133
+ _bind_interval(i, months, days, micros)
134
+ end
135
+
136
+ # binds i-th parameter with SQL prepared statement.
137
+ # The first argument is index of parameter.
138
+ # The index of first parameter is 1 not 0.
32
139
  # The second argument value is the value of prepared statement parameter.
33
140
  #
34
141
  # require 'duckdb'
@@ -40,7 +147,7 @@ module DuckDB
40
147
  def bind(i, value)
41
148
  case value
42
149
  when NilClass
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')
150
+ bind_null(i)
44
151
  when Float
45
152
  bind_double(i, value)
46
153
  when Integer
@@ -51,11 +158,7 @@ module DuckDB
51
158
  bind_varchar(i, value.to_s)
52
159
  end
53
160
  when String
54
- if defined?(DuckDB::Blob)
55
- blob?(value) ? bind_blob(i, value) : bind_varchar(i, value)
56
- else
57
- bind_varchar(i, value)
58
- end
161
+ blob?(value) ? bind_blob(i, value) : bind_varchar(i, value)
59
162
  when TrueClass, FalseClass
60
163
  bind_bool(i, value)
61
164
  when Time
@@ -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.9.0'.freeze
4
+ VERSION = '0.3.3.0'.freeze
5
5
  end
data/lib/duckdb.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  require 'duckdb/duckdb_native'
2
2
  require 'duckdb/version'
3
+ require 'duckdb/converter'
3
4
  require 'duckdb/database'
4
5
  require 'duckdb/connection'
5
6
  require 'duckdb/result'
6
7
  require 'duckdb/prepared_statement'
7
8
  require 'duckdb/appender'
8
9
  require 'duckdb/config'
10
+ require 'duckdb/column'
9
11
 
10
12
  # DuckDB provides Ruby interface of DuckDB.
11
13
  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.9.0
4
+ version: 0.3.3.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-10-24 00:00:00.000000000 Z
11
+ date: 2022-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,6 +93,8 @@ files:
93
93
  - ext/duckdb/appender.h
94
94
  - ext/duckdb/blob.c
95
95
  - ext/duckdb/blob.h
96
+ - ext/duckdb/column.c
97
+ - ext/duckdb/column.h
96
98
  - ext/duckdb/config.c
97
99
  - ext/duckdb/config.h
98
100
  - ext/duckdb/connection.c
@@ -108,10 +110,14 @@ files:
108
110
  - ext/duckdb/result.c
109
111
  - ext/duckdb/result.h
110
112
  - ext/duckdb/ruby-duckdb.h
113
+ - ext/duckdb/util.c
114
+ - ext/duckdb/util.h
111
115
  - lib/duckdb.rb
112
116
  - lib/duckdb/appender.rb
117
+ - lib/duckdb/column.rb
113
118
  - lib/duckdb/config.rb
114
119
  - lib/duckdb/connection.rb
120
+ - lib/duckdb/converter.rb
115
121
  - lib/duckdb/database.rb
116
122
  - lib/duckdb/prepared_statement.rb
117
123
  - lib/duckdb/result.rb
@@ -138,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
144
  - !ruby/object:Gem::Version
139
145
  version: '0'
140
146
  requirements: []
141
- rubygems_version: 3.2.22
147
+ rubygems_version: 3.3.10
142
148
  signing_key:
143
149
  specification_version: 4
144
150
  summary: This module is Ruby binding for DuckDB database engine.