litestack 0.3.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.standard.yml +3 -0
- data/BENCHMARKS.md +34 -7
- data/CHANGELOG.md +21 -0
- data/Gemfile +1 -5
- data/Gemfile.lock +92 -0
- data/README.md +120 -6
- data/ROADMAP.md +45 -0
- data/Rakefile +3 -1
- data/WHYLITESTACK.md +1 -1
- data/assets/litecache_metrics.png +0 -0
- data/assets/litedb_metrics.png +0 -0
- data/assets/litemetric_logo_teal.png +0 -0
- data/assets/litesearch_logo_teal.png +0 -0
- data/bench/bench.rb +17 -10
- data/bench/bench_cache_rails.rb +10 -13
- data/bench/bench_cache_raw.rb +17 -22
- data/bench/bench_jobs_rails.rb +19 -13
- data/bench/bench_jobs_raw.rb +17 -10
- data/bench/bench_queue.rb +4 -6
- data/bench/rails_job.rb +5 -7
- data/bench/skjob.rb +4 -4
- data/bench/uljob.rb +6 -6
- data/lib/action_cable/subscription_adapter/litecable.rb +5 -8
- data/lib/active_job/queue_adapters/litejob_adapter.rb +6 -8
- data/lib/active_record/connection_adapters/litedb_adapter.rb +65 -75
- data/lib/active_support/cache/litecache.rb +38 -41
- data/lib/generators/litestack/install/install_generator.rb +3 -3
- data/lib/generators/litestack/install/templates/database.yml +7 -1
- data/lib/litestack/liteboard/liteboard.rb +269 -149
- data/lib/litestack/litecable.rb +44 -40
- data/lib/litestack/litecable.sql.yml +22 -11
- data/lib/litestack/litecache.rb +80 -89
- data/lib/litestack/litecache.sql.yml +81 -22
- data/lib/litestack/litecache.yml +1 -1
- data/lib/litestack/litedb.rb +39 -38
- data/lib/litestack/litejob.rb +31 -31
- data/lib/litestack/litejobqueue.rb +107 -106
- data/lib/litestack/litemetric.rb +83 -95
- data/lib/litestack/litemetric.sql.yml +244 -234
- data/lib/litestack/litemetric_collector.sql.yml +38 -41
- data/lib/litestack/litequeue.rb +39 -41
- data/lib/litestack/litequeue.sql.yml +39 -31
- data/lib/litestack/litescheduler.rb +84 -0
- data/lib/litestack/litesearch/index.rb +260 -0
- data/lib/litestack/litesearch/model.rb +179 -0
- data/lib/litestack/litesearch/schema.rb +190 -0
- data/lib/litestack/litesearch/schema_adapters/backed_adapter.rb +143 -0
- data/lib/litestack/litesearch/schema_adapters/basic_adapter.rb +137 -0
- data/lib/litestack/litesearch/schema_adapters/contentless_adapter.rb +14 -0
- data/lib/litestack/litesearch/schema_adapters/standalone_adapter.rb +31 -0
- data/lib/litestack/litesearch/schema_adapters.rb +4 -0
- data/lib/litestack/litesearch.rb +34 -0
- data/lib/litestack/litesupport.rb +85 -186
- data/lib/litestack/railtie.rb +1 -1
- data/lib/litestack/version.rb +2 -2
- data/lib/litestack.rb +7 -4
- data/lib/railties/rails/commands/dbconsole.rb +11 -15
- data/lib/sequel/adapters/litedb.rb +18 -22
- data/lib/sequel/adapters/shared/litedb.rb +168 -168
- data/scripts/build_metrics.rb +91 -0
- data/scripts/test_cable.rb +30 -0
- data/scripts/test_job_retry.rb +33 -0
- data/scripts/test_metrics.rb +60 -0
- data/template.rb +2 -2
- metadata +112 -7
@@ -0,0 +1,34 @@
|
|
1
|
+
module Litesearch
|
2
|
+
class Index; end
|
3
|
+
|
4
|
+
class Schema; end
|
5
|
+
end
|
6
|
+
|
7
|
+
require_relative "./litesearch/index"
|
8
|
+
require_relative "./litesearch/model"
|
9
|
+
|
10
|
+
module Litesearch
|
11
|
+
def litesearch_index_cache
|
12
|
+
@litesearch_index_cache ||= {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def search_index(name)
|
16
|
+
# normalize the index name
|
17
|
+
# find the index in the db cache
|
18
|
+
name = name.to_s.downcase.to_sym
|
19
|
+
index = litesearch_index_cache[name]
|
20
|
+
# if the index is in the cache and no block is given then return it
|
21
|
+
return index if index && !block_given?
|
22
|
+
# if either there is no index in the cache or a block is given
|
23
|
+
# create a new index instance and then place it in the cache and return
|
24
|
+
index = if block_given?
|
25
|
+
Index.new(self, name) do |schema|
|
26
|
+
yield schema
|
27
|
+
schema.name(name)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
Index.new(self, name)
|
31
|
+
end
|
32
|
+
litesearch_index_cache[name] = index
|
33
|
+
end
|
34
|
+
end
|
@@ -1,20 +1,16 @@
|
|
1
1
|
# frozen_stringe_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
3
|
+
require "sqlite3"
|
4
|
+
require "logger"
|
5
|
+
require "oj"
|
6
|
+
require "yaml"
|
7
|
+
require "pathname"
|
8
|
+
require "fileutils"
|
9
9
|
|
10
|
-
|
10
|
+
require_relative "./litescheduler"
|
11
11
|
|
12
|
+
module Litesupport
|
12
13
|
class Error < StandardError; end
|
13
|
-
|
14
|
-
def self.max_contexts
|
15
|
-
return 50 if scheduler == :fiber || scheduler == :polyphony
|
16
|
-
5
|
17
|
-
end
|
18
14
|
|
19
15
|
# Detect the Rack or Rails environment.
|
20
16
|
def self.detect_environment
|
@@ -33,88 +29,10 @@ module Litesupport
|
|
33
29
|
@environment ||= detect_environment
|
34
30
|
end
|
35
31
|
|
36
|
-
# cache the scheduler we are running in
|
37
|
-
# it is an error to change the scheduler for a process
|
38
|
-
# or for a child forked from that process
|
39
|
-
def self.scheduler
|
40
|
-
@scehduler ||= detect_scheduler
|
41
|
-
end
|
42
|
-
|
43
|
-
# identify which scheduler we are running in
|
44
|
-
# we currently support :fiber, :polyphony, :iodine & :threaded
|
45
|
-
# in the future we might want to expand to other schedulers
|
46
|
-
def self.detect_scheduler
|
47
|
-
return :fiber if Fiber.scheduler
|
48
|
-
return :polyphony if defined? Polyphony
|
49
|
-
return :iodine if defined? Iodine
|
50
|
-
return :threaded # fall back for all other schedulers
|
51
|
-
end
|
52
|
-
|
53
|
-
# spawn a new execution context
|
54
|
-
def self.spawn(&block)
|
55
|
-
if self.scheduler == :fiber
|
56
|
-
Fiber.schedule(&block)
|
57
|
-
elsif self.scheduler == :polyphony
|
58
|
-
spin(&block)
|
59
|
-
elsif self.scheduler == :threaded or self.scheduler == :iodine
|
60
|
-
Thread.new(&block)
|
61
|
-
end
|
62
|
-
# we should never reach here
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.context
|
66
|
-
if scheduler == :fiber || scheduler == :poylphony
|
67
|
-
Fiber.current.storage
|
68
|
-
else
|
69
|
-
Thread.current
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.current_context
|
74
|
-
if scheduler == :fiber || scheduler == :poylphony
|
75
|
-
Fiber.current
|
76
|
-
else
|
77
|
-
Thread.current
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# switch the execution context to allow others to run
|
82
|
-
def self.switch
|
83
|
-
if self.scheduler == :fiber
|
84
|
-
Fiber.scheduler.yield
|
85
|
-
true
|
86
|
-
elsif self.scheduler == :polyphony
|
87
|
-
Fiber.current.schedule
|
88
|
-
Thread.current.switch_fiber
|
89
|
-
true
|
90
|
-
else
|
91
|
-
#Thread.pass
|
92
|
-
false
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# mutex initialization
|
97
|
-
def self.mutex
|
98
|
-
# a single mutex per process (is that ok?)
|
99
|
-
@@mutex ||= Mutex.new
|
100
|
-
end
|
101
|
-
|
102
|
-
# bold assumption, we will only synchronize threaded code!
|
103
|
-
# If some code explicitly wants to synchronize a fiber
|
104
|
-
# they must send (true) as a parameter to this method
|
105
|
-
# else it is a no-op for fibers
|
106
|
-
def self.synchronize(fiber_sync = false, &block)
|
107
|
-
if self.scheduler == :fiber or self.scheduler == :polyphony
|
108
|
-
yield # do nothing, just run the block as is
|
109
|
-
else
|
110
|
-
self.mutex.synchronize(&block)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
32
|
# common db object options
|
115
33
|
def self.create_db(path)
|
116
34
|
db = SQLite3::Database.new(path)
|
117
|
-
db.busy_handler{ switch || sleep(0.0001) }
|
35
|
+
db.busy_handler { Litescheduler.switch || sleep(0.0001) }
|
118
36
|
db.journal_mode = "WAL"
|
119
37
|
db.instance_variable_set(:@stmts, {})
|
120
38
|
class << db
|
@@ -124,12 +42,12 @@ module Litesupport
|
|
124
42
|
end
|
125
43
|
|
126
44
|
# Databases will be stored by default at this path.
|
127
|
-
def self.root
|
128
|
-
|
45
|
+
def self.root(env = Litesupport.environment)
|
46
|
+
ensure_root_volume detect_root(env)
|
129
47
|
end
|
130
48
|
|
131
49
|
# Default path where we'll store all of the databases.
|
132
|
-
def self.detect_root
|
50
|
+
def self.detect_root(env)
|
133
51
|
path = if ENV["LITESTACK_DATA_PATH"]
|
134
52
|
ENV["LITESTACK_DATA_PATH"]
|
135
53
|
elsif defined? Rails
|
@@ -138,7 +56,7 @@ module Litesupport
|
|
138
56
|
"."
|
139
57
|
end
|
140
58
|
|
141
|
-
Pathname.new(path).join(
|
59
|
+
Pathname.new(path).join(env)
|
142
60
|
end
|
143
61
|
|
144
62
|
def self.ensure_root_volume(path)
|
@@ -147,125 +65,106 @@ module Litesupport
|
|
147
65
|
end
|
148
66
|
|
149
67
|
class Mutex
|
150
|
-
|
151
68
|
def initialize
|
152
69
|
@mutex = Thread::Mutex.new
|
153
70
|
end
|
154
|
-
|
71
|
+
|
155
72
|
def synchronize(&block)
|
156
|
-
if
|
157
|
-
@mutex.synchronize{ block.call }
|
73
|
+
if Litescheduler.backend == :threaded || Litescheduler.backend == :iodine
|
74
|
+
@mutex.synchronize { block.call }
|
158
75
|
else
|
159
76
|
block.call
|
160
77
|
end
|
161
78
|
end
|
162
|
-
|
163
79
|
end
|
164
|
-
|
80
|
+
|
165
81
|
class Pool
|
166
|
-
|
167
82
|
def initialize(count, &block)
|
168
83
|
@count = count
|
169
84
|
@block = block
|
170
|
-
@resources =
|
85
|
+
@resources = Thread::Queue.new
|
171
86
|
@mutex = Litesupport::Mutex.new
|
172
87
|
@count.times do
|
173
|
-
resource = @mutex.synchronize{ block.call }
|
174
|
-
@resources <<
|
88
|
+
resource = @mutex.synchronize { block.call }
|
89
|
+
@resources << resource
|
175
90
|
end
|
176
91
|
end
|
177
|
-
|
92
|
+
|
178
93
|
def acquire
|
179
|
-
# check for pid changes
|
180
|
-
acquired = false
|
181
94
|
result = nil
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
result = yield resource[0]
|
188
|
-
rescue Exception => e
|
189
|
-
raise e
|
190
|
-
ensure
|
191
|
-
resource[1] = :free
|
192
|
-
acquired = true
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
sleep 0.001 unless acquired
|
95
|
+
resource = @resources.pop
|
96
|
+
begin
|
97
|
+
result = yield resource
|
98
|
+
ensure
|
99
|
+
@resources << resource
|
197
100
|
end
|
198
101
|
result
|
199
102
|
end
|
200
|
-
|
201
103
|
end
|
202
|
-
|
104
|
+
|
203
105
|
module ForkListener
|
204
106
|
def self.listeners
|
205
107
|
@listeners ||= []
|
206
108
|
end
|
207
|
-
|
109
|
+
|
208
110
|
def self.listen(&block)
|
209
111
|
listeners << block
|
210
112
|
end
|
211
113
|
end
|
212
114
|
|
213
115
|
module Forkable
|
214
|
-
|
215
116
|
def _fork(*args)
|
216
117
|
ppid = Process.pid
|
217
118
|
result = super
|
218
|
-
if Process.pid != ppid && [:threaded, :iodine].include?(
|
219
|
-
ForkListener.listeners.each{|l| l.call }
|
119
|
+
if Process.pid != ppid && [:threaded, :iodine].include?(Litescheduler.backend)
|
120
|
+
ForkListener.listeners.each { |l| l.call }
|
220
121
|
end
|
221
122
|
result
|
222
123
|
end
|
223
|
-
|
224
124
|
end
|
225
|
-
|
125
|
+
|
226
126
|
module Liteconnection
|
227
|
-
|
228
127
|
include Forkable
|
229
128
|
|
230
129
|
# close, setup, run_stmt and run_sql assume a single connection was created
|
231
|
-
|
130
|
+
|
232
131
|
def options
|
233
132
|
@options
|
234
133
|
end
|
235
|
-
|
134
|
+
|
236
135
|
def close
|
237
136
|
@running = false
|
238
|
-
@conn.acquire do |q|
|
239
|
-
q.stmts.each_pair {|k, v| q.stmts[k].close }
|
137
|
+
@conn.acquire do |q|
|
138
|
+
q.stmts.each_pair { |k, v| q.stmts[k].close }
|
240
139
|
q.close
|
241
140
|
end
|
242
141
|
end
|
243
142
|
|
244
143
|
def size
|
245
|
-
run_sql("SELECT size.page_size * count.page_count FROM pragma_page_size() AS size, pragma_page_count() AS count")[0][0].to_f / (1024*1024)
|
144
|
+
run_sql("SELECT size.page_size * count.page_count FROM pragma_page_size() AS size, pragma_page_count() AS count")[0][0].to_f / (1024 * 1024)
|
246
145
|
end
|
247
146
|
|
248
147
|
def journal_mode
|
249
148
|
run_method(:journal_mode)
|
250
149
|
end
|
251
|
-
|
150
|
+
|
252
151
|
def synchronous
|
253
152
|
run_method(:synchronous)
|
254
153
|
end
|
255
|
-
|
154
|
+
|
256
155
|
def path
|
257
156
|
run_method(:filename)
|
258
157
|
end
|
259
|
-
|
158
|
+
|
260
159
|
private # all methods are private
|
261
|
-
|
160
|
+
|
262
161
|
def init(options = {})
|
263
|
-
#c configure the object, loading options from the appropriate location
|
264
|
-
configure(options)
|
162
|
+
# c configure the object, loading options from the appropriate location
|
163
|
+
configure(options)
|
265
164
|
# setup connections and background threads
|
266
|
-
setup
|
165
|
+
setup
|
267
166
|
# handle process exiting
|
268
|
-
at_exit do
|
167
|
+
at_exit do
|
269
168
|
exit_callback
|
270
169
|
end
|
271
170
|
# handle forking (restart connections and background threads)
|
@@ -276,9 +175,17 @@ module Litesupport
|
|
276
175
|
|
277
176
|
def configure(options = {})
|
278
177
|
# detect enviornment (production, development, etc.)
|
279
|
-
defaults =
|
178
|
+
defaults = begin
|
179
|
+
self.class::DEFAULT_OPTIONS
|
180
|
+
rescue
|
181
|
+
{}
|
182
|
+
end
|
280
183
|
@options = defaults.merge(options)
|
281
|
-
config =
|
184
|
+
config = begin
|
185
|
+
YAML.load_file(@options[:config_path])
|
186
|
+
rescue
|
187
|
+
{}
|
188
|
+
end # an empty hash won't hurt
|
282
189
|
config = config[Litesupport.environment] if config[Litesupport.environment] # if there is a config for the current enviornment defined then use it, otherwise use the top level declaration
|
283
190
|
config.keys.each do |k| # symbolize keys
|
284
191
|
config[k.to_sym] = config[k]
|
@@ -287,51 +194,50 @@ module Litesupport
|
|
287
194
|
@options.merge!(config)
|
288
195
|
@options.merge!(options) # make sure options passed to initialize trump everything else
|
289
196
|
end
|
290
|
-
|
197
|
+
|
291
198
|
def setup
|
292
199
|
@conn = create_pooled_connection
|
293
200
|
@logger = create_logger
|
294
201
|
@running = true
|
295
202
|
end
|
296
|
-
|
203
|
+
|
297
204
|
def create_logger
|
298
205
|
@options[:logger] = nil unless @options[:logger]
|
299
206
|
return @options[:logger] if @options[:logger].respond_to? :info
|
300
|
-
return Logger.new(
|
301
|
-
return Logger.new(
|
302
|
-
return Logger.new(@options[:logger]) if @options[:logger].is_a? String
|
303
|
-
|
207
|
+
return Logger.new($stdout) if @options[:logger] == "STDOUT"
|
208
|
+
return Logger.new($stderr) if @options[:logger] == "STDERR"
|
209
|
+
return Logger.new(@options[:logger]) if @options[:logger].is_a? String
|
210
|
+
Logger.new(IO::NULL)
|
304
211
|
end
|
305
|
-
|
212
|
+
|
306
213
|
def exit_callback
|
307
214
|
close
|
308
215
|
end
|
309
|
-
|
216
|
+
|
310
217
|
def run_stmt(stmt, *args)
|
311
|
-
@conn.acquire{|q| q.stmts[stmt].execute!(*args) }
|
218
|
+
@conn.acquire { |q| q.stmts[stmt].execute!(*args) }
|
312
219
|
end
|
313
220
|
|
314
221
|
def run_sql(sql, *args)
|
315
|
-
@conn.acquire{|q| q.execute(sql,
|
222
|
+
@conn.acquire { |q| q.execute(sql, args) }
|
316
223
|
end
|
317
|
-
|
224
|
+
|
318
225
|
def run_method(method, *args)
|
319
|
-
@conn.acquire{|q| q.send(method, *args)}
|
226
|
+
@conn.acquire { |q| q.send(method, *args) }
|
320
227
|
end
|
321
228
|
|
322
229
|
def run_stmt_method(stmt, method, *args)
|
323
|
-
@conn.acquire{|q| q.stmts[stmt].send(method, *args)}
|
230
|
+
@conn.acquire { |q| q.stmts[stmt].send(method, *args) }
|
324
231
|
end
|
325
232
|
|
326
|
-
|
327
233
|
def create_pooled_connection(count = 1)
|
328
|
-
Litesupport::Pool.new(1){create_connection}
|
234
|
+
Litesupport::Pool.new(1) { create_connection }
|
329
235
|
end
|
330
236
|
|
331
237
|
# common db object options
|
332
238
|
def create_connection(path_to_sql_file = nil)
|
333
239
|
conn = SQLite3::Database.new(@options[:path])
|
334
|
-
conn.busy_handler{
|
240
|
+
conn.busy_handler { Litescheduler.switch || sleep(rand * 0.002) }
|
335
241
|
conn.journal_mode = "WAL"
|
336
242
|
conn.synchronous = @options[:sync] || 1
|
337
243
|
conn.mmap_size = @options[:mmap_size] || 0
|
@@ -344,38 +250,31 @@ module Litesupport
|
|
344
250
|
unless path_to_sql_file.nil?
|
345
251
|
sql = YAML.load_file(path_to_sql_file)
|
346
252
|
version = conn.get_first_value("PRAGMA user_version")
|
347
|
-
sql["schema"].each_pair do |v, obj|
|
253
|
+
sql["schema"].each_pair do |v, obj|
|
348
254
|
if v > version
|
349
|
-
conn.transaction do
|
350
|
-
obj.each do |k, s|
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
raise e
|
357
|
-
end
|
255
|
+
conn.transaction do
|
256
|
+
obj.each do |k, s|
|
257
|
+
conn.execute(s)
|
258
|
+
rescue Exception => e # standard:disable Lint/RescueException
|
259
|
+
warn "Error parsing #{k}"
|
260
|
+
warn s
|
261
|
+
raise e
|
358
262
|
end
|
359
263
|
conn.user_version = v
|
360
264
|
end
|
361
265
|
end
|
362
|
-
end
|
363
|
-
sql["stmts"].each do |k, v|
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
raise e
|
370
|
-
end
|
266
|
+
end
|
267
|
+
sql["stmts"].each do |k, v|
|
268
|
+
conn.stmts[k.to_sym] = conn.prepare(v)
|
269
|
+
rescue Exception => e # standard:disable Lint/RescueException
|
270
|
+
warn "Error parsing #{k}"
|
271
|
+
warn v
|
272
|
+
raise e
|
371
273
|
end
|
372
274
|
end
|
373
275
|
conn
|
374
276
|
end
|
375
|
-
|
376
277
|
end
|
377
|
-
|
378
|
-
end
|
278
|
+
end
|
379
279
|
|
380
280
|
Process.singleton_class.prepend(Litesupport::Forkable)
|
381
|
-
|
data/lib/litestack/railtie.rb
CHANGED
data/lib/litestack/version.rb
CHANGED
data/lib/litestack.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# load core classes
|
4
4
|
require_relative "./litestack/version"
|
5
|
+
require_relative "./litestack/litescheduler"
|
5
6
|
require_relative "./litestack/litesupport"
|
6
7
|
require_relative "./litestack/litemetric"
|
7
8
|
require_relative "./litestack/litedb"
|
@@ -12,14 +13,16 @@ require_relative "./litestack/litecable"
|
|
12
13
|
# conditionally load integration with other libraries
|
13
14
|
require_relative "./sequel/adapters/litedb" if defined? Sequel
|
14
15
|
require_relative "./active_record/connection_adapters/litedb_adapter" if defined? ActiveRecord
|
15
|
-
require_relative "./railties/rails/commands/dbconsole" if defined?
|
16
|
+
require_relative "./railties/rails/commands/dbconsole" if defined?(Rails) && defined?(ActiveRecord)
|
16
17
|
require_relative "./active_support/cache/litecache" if defined? ActiveSupport
|
17
18
|
require_relative "./active_job/queue_adapters/litejob_adapter" if defined? ActiveJob
|
18
19
|
require_relative "./action_cable/subscription_adapter/litecable" if defined? ActionCable
|
19
20
|
require_relative "./litestack/railtie" if defined? Rails::Railtie
|
20
21
|
|
21
22
|
module Litestack
|
22
|
-
class NotImplementedError <
|
23
|
-
|
24
|
-
class
|
23
|
+
class NotImplementedError < RuntimeError; end
|
24
|
+
|
25
|
+
class TimeoutError < RuntimeError; end
|
26
|
+
|
27
|
+
class DeadlockError < RuntimeError; end
|
25
28
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Rails
|
2
2
|
class DBConsole
|
3
|
-
|
4
3
|
def start
|
5
4
|
ENV["RAILS_ENV"] ||= @options[:environment] || environment
|
6
5
|
config = db_config.configuration_hash
|
@@ -31,14 +30,14 @@ module Rails
|
|
31
30
|
find_cmd_and_exec(["mysql", "mysql5"], *args)
|
32
31
|
|
33
32
|
when /^postgres|^postgis/
|
34
|
-
ENV["PGUSER"]
|
35
|
-
ENV["PGHOST"]
|
36
|
-
ENV["PGPORT"]
|
37
|
-
ENV["PGPASSWORD"]
|
38
|
-
ENV["PGSSLMODE"]
|
39
|
-
ENV["PGSSLCERT"]
|
40
|
-
ENV["PGSSLKEY"]
|
41
|
-
ENV["PGSSLROOTCERT"]
|
33
|
+
ENV["PGUSER"] = config[:username] if config[:username]
|
34
|
+
ENV["PGHOST"] = config[:host] if config[:host]
|
35
|
+
ENV["PGPORT"] = config[:port].to_s if config[:port]
|
36
|
+
ENV["PGPASSWORD"] = config[:password].to_s if config[:password] && @options[:include_password]
|
37
|
+
ENV["PGSSLMODE"] = config[:sslmode].to_s if config[:sslmode]
|
38
|
+
ENV["PGSSLCERT"] = config[:sslcert].to_s if config[:sslcert]
|
39
|
+
ENV["PGSSLKEY"] = config[:sslkey].to_s if config[:sslkey]
|
40
|
+
ENV["PGSSLROOTCERT"] = config[:sslrootcert].to_s if config[:sslrootcert]
|
42
41
|
find_cmd_and_exec("psql", db_config.database)
|
43
42
|
|
44
43
|
when "sqlite3", "litedb"
|
@@ -50,7 +49,6 @@ module Rails
|
|
50
49
|
|
51
50
|
find_cmd_and_exec("sqlite3", *args)
|
52
51
|
|
53
|
-
|
54
52
|
when "oracle", "oracle_enhanced"
|
55
53
|
logon = ""
|
56
54
|
|
@@ -65,9 +63,9 @@ module Rails
|
|
65
63
|
when "sqlserver"
|
66
64
|
args = []
|
67
65
|
|
68
|
-
args += ["-d",
|
69
|
-
args += ["-U",
|
70
|
-
args += ["-P",
|
66
|
+
args += ["-d", db_config.database.to_s] if db_config.database
|
67
|
+
args += ["-U", config[:username].to_s] if config[:username]
|
68
|
+
args += ["-P", config[:password].to_s] if config[:password]
|
71
69
|
|
72
70
|
if config[:host]
|
73
71
|
host_arg = +"tcp:#{config[:host]}"
|
@@ -81,7 +79,5 @@ module Rails
|
|
81
79
|
abort "Unknown command-line client for #{db_config.database}."
|
82
80
|
end
|
83
81
|
end
|
84
|
-
|
85
|
-
|
86
82
|
end
|
87
83
|
end
|
@@ -1,48 +1,44 @@
|
|
1
|
-
require_relative
|
2
|
-
require
|
3
|
-
require
|
4
|
-
#require 'shared/litedb'
|
1
|
+
require_relative "../../litestack/litedb"
|
2
|
+
require "sequel"
|
3
|
+
require "sequel/adapters/sqlite"
|
5
4
|
|
6
5
|
module Sequel
|
7
6
|
module Litedb
|
8
|
-
|
7
|
+
include SQLite
|
9
8
|
|
10
9
|
LITEDB_TYPES = SQLITE_TYPES
|
11
|
-
|
10
|
+
|
12
11
|
class Database < Sequel::SQLite::Database
|
13
|
-
|
14
12
|
set_adapter_scheme :litedb
|
15
|
-
|
13
|
+
|
16
14
|
def connect(server)
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
Sequel.extension :fiber_concurrency if [:fiber, :polyphony].include? Litescheduler.backend
|
16
|
+
|
20
17
|
opts = server_opts(server)
|
21
|
-
opts[:database] =
|
18
|
+
opts[:database] = ":memory:" if blank_object?(opts[:database])
|
22
19
|
sqlite3_opts = {}
|
23
20
|
sqlite3_opts[:readonly] = typecast_value_boolean(opts[:readonly]) if opts.has_key?(:readonly)
|
24
21
|
db = ::Litedb.new(opts[:database].to_s, sqlite3_opts)
|
25
22
|
|
26
23
|
self.transaction_mode = :immediate
|
27
|
-
|
28
|
-
|
24
|
+
|
25
|
+
if sqlite_version >= 104
|
29
26
|
db.extended_result_codes = true
|
30
27
|
end
|
31
|
-
|
32
|
-
connection_pragmas.each{|s| log_connection_yield(s, db){db.execute_batch(s)}}
|
33
|
-
|
28
|
+
|
29
|
+
connection_pragmas.each { |s| log_connection_yield(s, db) { db.execute_batch(s) } }
|
30
|
+
|
34
31
|
class << db
|
35
32
|
attr_reader :prepared_statements
|
36
33
|
end
|
37
|
-
|
34
|
+
|
38
35
|
db.instance_variable_set(:@prepared_statements, {})
|
36
|
+
@raw_db = db
|
39
37
|
db
|
40
38
|
end
|
41
|
-
|
42
39
|
end
|
43
|
-
|
44
|
-
class Dataset < Sequel::SQLite::Dataset
|
40
|
+
|
41
|
+
class Dataset < Sequel::SQLite::Dataset
|
45
42
|
end
|
46
|
-
|
47
43
|
end
|
48
44
|
end
|