litedb 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +9 -1
- data/lib/litedb/connection.rb +98 -0
- data/lib/litedb/version.rb +2 -4
- data/lib/litedb.rb +2 -91
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '03940873fc6d049cf80790e80b04325ad29d0b51af711ad5dc4442df01396cb5'
|
4
|
+
data.tar.gz: ce364a86c99bc2ad9211163f606a850b9f943838579ec3d53225de7fb7fcd41d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2392eabd26b22e60b87559d984481c7b1d029df091a22994cbabedd42bc8fc5700423c840c749eee0e72d1b8a5c5658d91df262bfdd7124601014cff0cb128db
|
7
|
+
data.tar.gz: 104675e33444e702ffaba66e1908464800f5432ee00bbc717bb0514ad8f983b308ed9355650193f4ef790d5f36a6a7cc5bf5372ac6add652f85a4c95b0f00306
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.1] - 2023-08-11
|
4
|
+
|
5
|
+
- Move the `SQLite3::Database` wrapper to `Litedb::Connection` class. This both makes it easier to extend the gem to wrap other SQLite3 classes (like `Statement`) and also makes dealing with the VERSION reasonable (and possible). Keeping VERSION in a separate file proved impossible when having Litedb be a class that inherited from SQLite3::Database, because the gemspec needed the version before sqlite3 was required.
|
6
|
+
|
3
7
|
## [0.2.0] - 2023-08-10
|
4
8
|
|
5
9
|
- Initial release of usable code
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
litedb (0.2.
|
4
|
+
litedb (0.2.1)
|
5
5
|
litescheduler (>= 0.2.0)
|
6
6
|
sqlite3 (>= 1.5.0)
|
7
7
|
|
@@ -9,6 +9,7 @@ GEM
|
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
ast (2.4.2)
|
12
|
+
docile (1.4.0)
|
12
13
|
json (2.6.3)
|
13
14
|
language_server-protocol (3.17.0.3)
|
14
15
|
lint_roller (1.1.0)
|
@@ -39,6 +40,12 @@ GEM
|
|
39
40
|
rubocop (>= 1.7.0, < 2.0)
|
40
41
|
rubocop-ast (>= 0.4.0)
|
41
42
|
ruby-progressbar (1.13.0)
|
43
|
+
simplecov (0.22.0)
|
44
|
+
docile (~> 1.1)
|
45
|
+
simplecov-html (~> 0.11)
|
46
|
+
simplecov_json_formatter (~> 0.1)
|
47
|
+
simplecov-html (0.12.3)
|
48
|
+
simplecov_json_formatter (0.1.4)
|
42
49
|
sqlite3 (1.6.3-arm64-darwin)
|
43
50
|
sqlite3 (1.6.3-x86_64-linux)
|
44
51
|
standard (1.30.1)
|
@@ -63,6 +70,7 @@ DEPENDENCIES
|
|
63
70
|
litedb!
|
64
71
|
minitest (~> 5.0)
|
65
72
|
rake (~> 13.0)
|
73
|
+
simplecov
|
66
74
|
standard (~> 1.3)
|
67
75
|
|
68
76
|
BUNDLED WITH
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sqlite3"
|
4
|
+
require "litescheduler"
|
5
|
+
|
6
|
+
module Litedb
|
7
|
+
class Connection < SQLite3::Database
|
8
|
+
DEFAULT_FILE = ":memory:"
|
9
|
+
DEFAULT_OPTIONS = {
|
10
|
+
synchronous: :NORMAL,
|
11
|
+
mmap_size: 32 * 1024, # 32 kilobytes
|
12
|
+
journal_size_limit: 64 * 1024 * 1024 # 64 megabytes
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
attr_reader :config
|
16
|
+
|
17
|
+
def initialize(file = nil, options = {}, zvfs = nil)
|
18
|
+
@scheduler = Litescheduler.instance
|
19
|
+
file ||= DEFAULT_FILE
|
20
|
+
options = options.transform_keys { |key|
|
21
|
+
begin
|
22
|
+
key.to_sym
|
23
|
+
rescue
|
24
|
+
key
|
25
|
+
end
|
26
|
+
}
|
27
|
+
@config = DEFAULT_OPTIONS.merge(options)
|
28
|
+
|
29
|
+
super(file, @config, zvfs)
|
30
|
+
|
31
|
+
set_pragmas
|
32
|
+
run_migrations
|
33
|
+
prepare_statements
|
34
|
+
end
|
35
|
+
|
36
|
+
def run_statement(statement, *args)
|
37
|
+
statements[statement].execute!(*args)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def set_pragmas
|
43
|
+
# set a custom busy handler to override the `busy_timeout`
|
44
|
+
# this ensures we either switch to another execution context or try again to connect
|
45
|
+
# https://www.sqlite.org/pragma.html#pragma_busy_timeout
|
46
|
+
busy_handler { @scheduler.switch || sleep(rand * 0.001) }
|
47
|
+
# Journal mode WAL allows for greater concurrency (many readers + one writer)
|
48
|
+
# https://www.sqlite.org/pragma.html#pragma_journal_mode
|
49
|
+
self.journal_mode = :WAL
|
50
|
+
# level of database durability
|
51
|
+
# 2 = "FULL" (sync on every write)
|
52
|
+
# 1 = "NORMAL" (sync every 1000 written pages)
|
53
|
+
# 0 = "OFF" (don't sync)
|
54
|
+
# https://www.sqlite.org/pragma.html#pragma_synchronous
|
55
|
+
self.synchronous = @config[:synchronous]
|
56
|
+
# set the global memory map so all processes can share data
|
57
|
+
# https://www.sqlite.org/pragma.html#pragma_mmap_size
|
58
|
+
# https://www.sqlite.org/mmap.html
|
59
|
+
self.mmap_size = @config[:mmap_size]
|
60
|
+
# impose a limit on the WAL file to prevent unlimited growth (with a negative impact on read performance as well)
|
61
|
+
# https://www.sqlite.org/pragma.html#pragma_journal_size_limit
|
62
|
+
self.journal_size_limit = @config[:journal_size_limit]
|
63
|
+
end
|
64
|
+
|
65
|
+
def run_migrations
|
66
|
+
return if @config[:migrations].nil?
|
67
|
+
|
68
|
+
migrations = if @config[:migrations].is_a?(Hash)
|
69
|
+
@config[:migrations].values
|
70
|
+
elsif @config[:migrations].is_a?(Array)
|
71
|
+
@config[:migrations]
|
72
|
+
else
|
73
|
+
raise Error.new("`migrations` option must be either a Hash or an Array")
|
74
|
+
end
|
75
|
+
|
76
|
+
transaction(:immediate) do
|
77
|
+
migrations.each do |sql|
|
78
|
+
execute(clean_sql(sql))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def prepare_statements
|
84
|
+
instance_variable_set(:@statements, {})
|
85
|
+
self.class.attr_reader(:statements) unless respond_to?(:statements)
|
86
|
+
|
87
|
+
return if @config[:statements].nil?
|
88
|
+
|
89
|
+
@config[:statements].each do |key, sql|
|
90
|
+
statements[key.to_sym] = prepare(clean_sql(sql))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def clean_sql(sql)
|
95
|
+
sql.gsub(/[[:space:]]+/, " ").strip
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/litedb/version.rb
CHANGED
data/lib/litedb.rb
CHANGED
@@ -1,100 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "litedb/version"
|
4
|
+
require_relative "litedb/connection"
|
4
5
|
|
5
6
|
require "sqlite3"
|
6
7
|
require "litescheduler"
|
7
8
|
|
8
|
-
|
9
|
+
module Litedb
|
9
10
|
class Error < StandardError; end
|
10
|
-
|
11
|
-
DEFAULT_FILE = ":memory:"
|
12
|
-
DEFAULT_OPTIONS = {
|
13
|
-
synchronous: :NORMAL,
|
14
|
-
mmap_size: 32 * 1024, # 32 kilobytes
|
15
|
-
journal_size_limit: 64 * 1024 * 1024 # 64 megabytes
|
16
|
-
}.freeze
|
17
|
-
|
18
|
-
attr_reader :config
|
19
|
-
|
20
|
-
def initialize(file = nil, options = {}, zvfs = nil)
|
21
|
-
@scheduler = Litescheduler.instance
|
22
|
-
file ||= DEFAULT_FILE
|
23
|
-
options = options.transform_keys { |key|
|
24
|
-
begin
|
25
|
-
key.to_sym
|
26
|
-
rescue
|
27
|
-
key
|
28
|
-
end
|
29
|
-
}
|
30
|
-
@config = DEFAULT_OPTIONS.merge(options)
|
31
|
-
|
32
|
-
super(file, @config, zvfs)
|
33
|
-
|
34
|
-
set_pragmas
|
35
|
-
run_migrations
|
36
|
-
prepare_statements
|
37
|
-
end
|
38
|
-
|
39
|
-
def run_statement(statement, *args)
|
40
|
-
statements[statement].execute!(*args)
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def set_pragmas
|
46
|
-
# set a custom busy handler to override the `busy_timeout`
|
47
|
-
# this ensures we either switch to another execution context or try again to connect
|
48
|
-
# https://www.sqlite.org/pragma.html#pragma_busy_timeout
|
49
|
-
busy_handler { @scheduler.switch || sleep(rand * 0.001) }
|
50
|
-
# Journal mode WAL allows for greater concurrency (many readers + one writer)
|
51
|
-
# https://www.sqlite.org/pragma.html#pragma_journal_mode
|
52
|
-
self.journal_mode = :WAL
|
53
|
-
# level of database durability
|
54
|
-
# 2 = "FULL" (sync on every write)
|
55
|
-
# 1 = "NORMAL" (sync every 1000 written pages)
|
56
|
-
# 0 = "OFF" (don't sync)
|
57
|
-
# https://www.sqlite.org/pragma.html#pragma_synchronous
|
58
|
-
self.synchronous = @config[:synchronous]
|
59
|
-
# set the global memory map so all processes can share data
|
60
|
-
# https://www.sqlite.org/pragma.html#pragma_mmap_size
|
61
|
-
# https://www.sqlite.org/mmap.html
|
62
|
-
self.mmap_size = @config[:mmap_size]
|
63
|
-
# impose a limit on the WAL file to prevent unlimited growth (with a negative impact on read performance as well)
|
64
|
-
# https://www.sqlite.org/pragma.html#pragma_journal_size_limit
|
65
|
-
self.journal_size_limit = @config[:journal_size_limit]
|
66
|
-
end
|
67
|
-
|
68
|
-
def run_migrations
|
69
|
-
return if @config[:migrations].nil?
|
70
|
-
|
71
|
-
migrations = if @config[:migrations].is_a?(Hash)
|
72
|
-
@config[:migrations].values
|
73
|
-
elsif @config[:migrations].is_a?(Array)
|
74
|
-
@config[:migrations]
|
75
|
-
else
|
76
|
-
raise Error.new("`migrations` option must be either a Hash or an Array")
|
77
|
-
end
|
78
|
-
|
79
|
-
transaction(:immediate) do
|
80
|
-
migrations.each do |sql|
|
81
|
-
execute(clean_sql(sql))
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def prepare_statements
|
87
|
-
instance_variable_set(:@statements, {})
|
88
|
-
self.class.attr_reader(:statements) unless respond_to?(:statements)
|
89
|
-
|
90
|
-
return if @config[:statements].nil?
|
91
|
-
|
92
|
-
@config[:statements].each do |key, sql|
|
93
|
-
statements[key.to_sym] = prepare(clean_sql(sql))
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def clean_sql(sql)
|
98
|
-
sql.gsub(/[[:space:]]+/, " ").strip
|
99
|
-
end
|
100
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: litedb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mohamed Hassan
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-08-
|
12
|
+
date: 2023-08-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sqlite3
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 0.2.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: simplecov
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
42
56
|
description:
|
43
57
|
email:
|
44
58
|
- oldmoe@gmail.com
|
@@ -56,6 +70,7 @@ files:
|
|
56
70
|
- README.md
|
57
71
|
- Rakefile
|
58
72
|
- lib/litedb.rb
|
73
|
+
- lib/litedb/connection.rb
|
59
74
|
- lib/litedb/version.rb
|
60
75
|
- sig/litedb.rbs
|
61
76
|
homepage: https://github.com/litestack-ruby/litedb
|