squongo 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +37 -0
- data/lib/squongo/connection.rb +36 -0
- data/lib/squongo/document.rb +31 -0
- data/lib/squongo/namespace.rb +1 -0
- data/lib/squongo/version.rb +1 -1
- data/lib/squongo/writer.rb +42 -0
- data/squongo.gemspec +1 -1
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5b74adddee6c579512aa4c4491916f473b66461c8df28439fff0093f4e02157
|
4
|
+
data.tar.gz: 7a7dfb309e5f4d15561bd814a1f771082b199101928dde803e9ffd336d73464e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad5fc59027aba44b575ccb1200c472c80af99d33c329370d7f039d596db8b92ebdc1abed813b9b46e13b63e28581d1264d8d3af03f2fdff0aacf2cb89cbf3d73
|
7
|
+
data.tar.gz: 4bd2b038a20046c64f4d3f081a718bae8ccd4f1726f1b6ca6ca1355721e0bbe85330df1ab2004d36b15a30a01d37320b7be7bbbced6f067b98aa053f764243f5
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
squongo (0.1.0)
|
5
|
+
sqlite3
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
rake (10.5.0)
|
12
|
+
rspec (3.8.0)
|
13
|
+
rspec-core (~> 3.8.0)
|
14
|
+
rspec-expectations (~> 3.8.0)
|
15
|
+
rspec-mocks (~> 3.8.0)
|
16
|
+
rspec-core (3.8.2)
|
17
|
+
rspec-support (~> 3.8.0)
|
18
|
+
rspec-expectations (3.8.4)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.8.0)
|
21
|
+
rspec-mocks (3.8.1)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.8.0)
|
24
|
+
rspec-support (3.8.2)
|
25
|
+
sqlite3 (1.4.1)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 2.0)
|
32
|
+
rake (~> 10.0)
|
33
|
+
rspec (~> 3.0)
|
34
|
+
squongo!
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
2.0.2
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sqlite3'
|
4
|
+
|
5
|
+
class Squongo::Connection
|
6
|
+
WAL_QUERY = 'PRAGMA journal_mode=WAL;'
|
7
|
+
|
8
|
+
attr_reader :db, :path
|
9
|
+
|
10
|
+
def initialize(path)
|
11
|
+
@path = path
|
12
|
+
@db = SQLite3::Database.open(path)
|
13
|
+
ensure_mode
|
14
|
+
end
|
15
|
+
|
16
|
+
def reconnect
|
17
|
+
@db = SQLite3::Database.open(path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.connect(path)
|
21
|
+
self.new(path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def ensure_mode
|
25
|
+
return unless first_connection
|
26
|
+
wal_mode
|
27
|
+
end
|
28
|
+
|
29
|
+
def wal_mode
|
30
|
+
@db.execute WAL_QUERY
|
31
|
+
end
|
32
|
+
|
33
|
+
def first_connection
|
34
|
+
!(File.exist?(path))
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Squongo::Document
|
2
|
+
attr_accessor :data
|
3
|
+
|
4
|
+
def initialize(data: {})
|
5
|
+
@data = data
|
6
|
+
end
|
7
|
+
|
8
|
+
def save
|
9
|
+
Squongo.save({ table: table, data: data })
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.first
|
13
|
+
Squongo.connection.db.execute "SELECT * FROM #{table} ORDER BY id LIMIT 1"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.last
|
17
|
+
Squongo.connection.db.execute "SELECT * FROM #{table} ORDER BY id DESC LIMIT 1"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.all
|
21
|
+
Squongo.connection.db.execute "SELECT * FROM #{table}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def table
|
25
|
+
self.class.table
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.table
|
29
|
+
self.const_get :TABLE
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
module Squongo; end
|
data/lib/squongo/version.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
class Squongo::Writer
|
2
|
+
attr_reader :reader, :writer
|
3
|
+
|
4
|
+
def initialize(reader, writer, parent_pid)
|
5
|
+
@reader = reader
|
6
|
+
@writer = writer
|
7
|
+
@parent_pid = parent_pid
|
8
|
+
end
|
9
|
+
|
10
|
+
def start
|
11
|
+
monitor_parent
|
12
|
+
|
13
|
+
while packet = @reader.gets
|
14
|
+
model_information = Squongo.ipc_decode(packet)
|
15
|
+
|
16
|
+
table = model_information['table']
|
17
|
+
data = model_information['data']
|
18
|
+
|
19
|
+
insert(table, data)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def insert(table, data)
|
24
|
+
Squongo.connection.db.execute "INSERT INTO #{table} (data, updated_at) VALUES(?, ?)", data.to_json, Squongo.timestamp
|
25
|
+
end
|
26
|
+
|
27
|
+
def should_live
|
28
|
+
Process.getpgid(@parent_pid)
|
29
|
+
true
|
30
|
+
rescue Errno::ESRCH
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
def monitor_parent
|
35
|
+
@monitor_thread = Thread.new do
|
36
|
+
loop do
|
37
|
+
exit unless should_live
|
38
|
+
sleep 0.1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/squongo.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: squongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Albritton
|
@@ -77,12 +77,17 @@ files:
|
|
77
77
|
- ".rspec"
|
78
78
|
- ".travis.yml"
|
79
79
|
- Gemfile
|
80
|
+
- Gemfile.lock
|
80
81
|
- README.md
|
81
82
|
- Rakefile
|
82
83
|
- bin/console
|
83
84
|
- bin/setup
|
84
85
|
- lib/squongo.rb
|
86
|
+
- lib/squongo/connection.rb
|
87
|
+
- lib/squongo/document.rb
|
88
|
+
- lib/squongo/namespace.rb
|
85
89
|
- lib/squongo/version.rb
|
90
|
+
- lib/squongo/writer.rb
|
86
91
|
- squongo.gemspec
|
87
92
|
homepage: https://wa9ace.net/projects/squongo
|
88
93
|
licenses: []
|