extralite-bundle 1.26 → 1.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +2 -2
- data/README.md +1 -1
- data/ext/sqlite3/sqlite3.c +7506 -3493
- data/ext/sqlite3/sqlite3.h +304 -130
- data/lib/extralite/version.rb +1 -1
- data/lib/sequel/adapters/extralite.rb +26 -26
- data/test/test_sequel.rb +27 -5
- metadata +2 -2
data/lib/extralite/version.rb
CHANGED
@@ -94,19 +94,19 @@ module Sequel
|
|
94
94
|
|
95
95
|
# @!visibility private
|
96
96
|
USE_EXTENDED_RESULT_CODES = false
|
97
|
-
|
97
|
+
|
98
98
|
# Database adapter for Sequel
|
99
99
|
class Database < Sequel::Database
|
100
100
|
include ::Sequel::SQLite::DatabaseMethods
|
101
|
-
|
101
|
+
|
102
102
|
set_adapter_scheme :extralite
|
103
|
-
|
103
|
+
|
104
104
|
# Mimic the file:// uri, by having 2 preceding slashes specify a relative
|
105
105
|
# path, and 3 preceding slashes specify an absolute path.
|
106
106
|
def self.uri_to_options(uri) # :nodoc:
|
107
107
|
{ :database => (uri.host.nil? && uri.path == '/') ? nil : "#{uri.host}#{uri.path}" }
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
private_class_method :uri_to_options
|
111
111
|
|
112
112
|
# The conversion procs to use for this database
|
@@ -131,14 +131,14 @@ module Sequel
|
|
131
131
|
# if USE_EXTENDED_RESULT_CODES
|
132
132
|
# db.extended_result_codes = true
|
133
133
|
# end
|
134
|
-
|
134
|
+
|
135
135
|
connection_pragmas.each{|s| log_connection_yield(s, db){db.query(s)}}
|
136
|
-
|
136
|
+
|
137
137
|
class << db
|
138
138
|
attr_reader :prepared_statements
|
139
139
|
end
|
140
140
|
db.instance_variable_set(:@prepared_statements, {})
|
141
|
-
|
141
|
+
|
142
142
|
db
|
143
143
|
end
|
144
144
|
|
@@ -147,7 +147,7 @@ module Sequel
|
|
147
147
|
c.prepared_statements.each_value{|v| v.first.close }
|
148
148
|
c.close
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
151
|
# Run the given SQL with the given arguments and yield each row.
|
152
152
|
def execute(sql, opts=OPTS, &block)
|
153
153
|
_execute(:select, sql, opts, &block)
|
@@ -157,7 +157,7 @@ module Sequel
|
|
157
157
|
def execute_dui(sql, opts=OPTS)
|
158
158
|
_execute(:update, sql, opts)
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
# Drop any prepared statements on the connection when executing DDL. This is because
|
162
162
|
# prepared statements lock the table in such a way that you can't drop or alter the
|
163
163
|
# table while a prepared statement that references it still exists.
|
@@ -168,12 +168,12 @@ module Sequel
|
|
168
168
|
super
|
169
169
|
end
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
# @!visibility private
|
173
173
|
def execute_insert(sql, opts=OPTS)
|
174
174
|
_execute(:insert, sql, opts)
|
175
175
|
end
|
176
|
-
|
176
|
+
|
177
177
|
# @!visibility private
|
178
178
|
def freeze
|
179
179
|
@conversion_procs.freeze
|
@@ -195,13 +195,13 @@ module Sequel
|
|
195
195
|
end
|
196
196
|
|
197
197
|
private
|
198
|
-
|
198
|
+
|
199
199
|
def adapter_initialize
|
200
200
|
@conversion_procs = SQLITE_TYPES.dup
|
201
201
|
@conversion_procs['datetime'] = @conversion_procs['timestamp'] = method(:to_application_timestamp)
|
202
202
|
set_integer_booleans
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
# Yield an available connection. Rescue any Extralite::Error and turn
|
206
206
|
# them into DatabaseErrors.
|
207
207
|
def _execute(type, sql, opts, &block)
|
@@ -226,7 +226,7 @@ module Sequel
|
|
226
226
|
raise_error(e)
|
227
227
|
end
|
228
228
|
end
|
229
|
-
|
229
|
+
|
230
230
|
# The SQLite adapter does not need the pool to convert exceptions.
|
231
231
|
# Also, force the max connections to 1 if a memory database is being
|
232
232
|
# used, as otherwise each connection gets a separate database.
|
@@ -237,7 +237,7 @@ module Sequel
|
|
237
237
|
o[:max_connections] = 1 if @opts[:database] == ':memory:' || blank_object?(@opts[:database])
|
238
238
|
o
|
239
239
|
end
|
240
|
-
|
240
|
+
|
241
241
|
def prepared_statement_argument(arg)
|
242
242
|
case arg
|
243
243
|
when Date, DateTime, Time
|
@@ -281,9 +281,9 @@ module Sequel
|
|
281
281
|
log_sql << ")"
|
282
282
|
end
|
283
283
|
if block
|
284
|
-
log_connection_yield(log_sql, conn, args){cps.
|
284
|
+
log_connection_yield(log_sql, conn, args){cps.query(ps_args, &block)}
|
285
285
|
else
|
286
|
-
log_connection_yield(log_sql, conn, args){cps.
|
286
|
+
log_connection_yield(log_sql, conn, args){cps.query(ps_args){|r|}}
|
287
287
|
case type
|
288
288
|
when :insert
|
289
289
|
conn.last_insert_rowid
|
@@ -292,7 +292,7 @@ module Sequel
|
|
292
292
|
end
|
293
293
|
end
|
294
294
|
end
|
295
|
-
|
295
|
+
|
296
296
|
# # SQLite3 raises ArgumentError in addition to SQLite3::Exception in
|
297
297
|
# # some cases, such as operations on a closed database.
|
298
298
|
def database_error_classes
|
@@ -311,7 +311,7 @@ module Sequel
|
|
311
311
|
end
|
312
312
|
end
|
313
313
|
end
|
314
|
-
|
314
|
+
|
315
315
|
# Dataset adapter for Sequel
|
316
316
|
class Dataset < Sequel::Dataset
|
317
317
|
include ::Sequel::SQLite::DatasetMethods
|
@@ -319,9 +319,9 @@ module Sequel
|
|
319
319
|
# @!visibility private
|
320
320
|
module ArgumentMapper
|
321
321
|
include Sequel::Dataset::ArgumentMapper
|
322
|
-
|
322
|
+
|
323
323
|
protected
|
324
|
-
|
324
|
+
|
325
325
|
# Return a hash with the same values as the given hash,
|
326
326
|
# but with the keys converted to strings.
|
327
327
|
def map_to_prepared_args(hash)
|
@@ -329,16 +329,16 @@ module Sequel
|
|
329
329
|
hash.each{|k,v| args[k.to_s.gsub('.', '__')] = v}
|
330
330
|
args
|
331
331
|
end
|
332
|
-
|
332
|
+
|
333
333
|
private
|
334
|
-
|
334
|
+
|
335
335
|
# SQLite uses a : before the name of the argument for named
|
336
336
|
# arguments.
|
337
337
|
def prepared_arg(k)
|
338
338
|
LiteralString.new("#{prepared_arg_placeholder}#{k.to_s.gsub('.', '__')}")
|
339
339
|
end
|
340
340
|
end
|
341
|
-
|
341
|
+
|
342
342
|
# @!visibility private
|
343
343
|
BindArgumentMethods = prepared_statements_module(:bind, ArgumentMapper)
|
344
344
|
# @!visibility private
|
@@ -369,9 +369,9 @@ module Sequel
|
|
369
369
|
# end
|
370
370
|
# end
|
371
371
|
end
|
372
|
-
|
372
|
+
|
373
373
|
private
|
374
|
-
|
374
|
+
|
375
375
|
# The base type name for a given type, without any parenthetical part.
|
376
376
|
def base_type_name(t)
|
377
377
|
(t =~ /^(.*?)\(/ ? $1 : t).downcase if t
|
data/test/test_sequel.rb
CHANGED
@@ -4,21 +4,43 @@ require_relative 'helper'
|
|
4
4
|
require 'sequel'
|
5
5
|
|
6
6
|
class SequelExtraliteTest < MiniTest::Test
|
7
|
-
def
|
8
|
-
db = Sequel.connect('extralite::memory:')
|
9
|
-
db.create_table :items do
|
7
|
+
def setup
|
8
|
+
@db = Sequel.connect('extralite::memory:')
|
9
|
+
@db.create_table :items do
|
10
10
|
primary_key :id
|
11
11
|
String :name, unique: true, null: false
|
12
12
|
Float :price, null: false
|
13
13
|
end
|
14
14
|
|
15
|
-
items = db[:items]
|
16
|
-
|
15
|
+
items = @db[:items]
|
17
16
|
items.insert(name: 'abc', price: 123)
|
18
17
|
items.insert(name: 'def', price: 456)
|
19
18
|
items.insert(name: 'ghi', price: 789)
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
@db.disconnect
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_sequel
|
26
|
+
items = @db[:items]
|
20
27
|
|
21
28
|
assert_equal 3, items.count
|
22
29
|
assert_equal (123+456+789) / 3, items.avg(:price)
|
23
30
|
end
|
31
|
+
|
32
|
+
def test_prepared_statement
|
33
|
+
items = @db[:items]
|
34
|
+
prepared_query = items.where(name: :$name).prepare(:select, :select_by_name)
|
35
|
+
prepared_insert = items.prepare(:insert, :insert_with_name_and_price, name: :$name, price: :$price)
|
36
|
+
|
37
|
+
assert_equal prepared_query.call(name: 'def'), [{ id: 2, name: 'def', price: 456 }]
|
38
|
+
assert_equal @db.call(:select_by_name, name: 'def'), [{ id: 2, name: 'def', price: 456 }]
|
39
|
+
|
40
|
+
id = prepared_insert.call(name: 'jkl', price: 444)
|
41
|
+
assert_equal items[id: id], { id: id, name: 'jkl', price: 444 }
|
42
|
+
|
43
|
+
id = @db.call(:insert_with_name_and_price, name: 'mno', price: 555)
|
44
|
+
assert_equal items[id: id], { id: id, name: 'mno', price: 555 }
|
45
|
+
end
|
24
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extralite-bundle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.27'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|