recordx_sqlite 0.2.5 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/recordx_sqlite.rb +87 -10
- metadata +55 -31
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3db5139cd9c0e124459ca4a5f388ae556e6d7e07be90b5f6ed9c0c4e29e45005
|
4
|
+
data.tar.gz: 3d2966b40f159c7a07133ced693673540e0600f3a6da6cb5de8d0db33c6288cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9509b33e7e585b1103c2fcd60971ac528d403a4c99cb20faab6d91a98b0a8f066ffec030af063e642dcd387841f9619e162d71a74b031b68349af54b711fa1e8
|
7
|
+
data.tar.gz: 20bc3cecc3f045b40db81d7e6b8f3008ec0b21a12418474466f1ed995bf0b37f0499815be62a47c0dd1c1fdf538122b1eb11ce9e1a5769ea44e382cb3b034eb3
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/recordx_sqlite.rb
CHANGED
@@ -4,14 +4,17 @@
|
|
4
4
|
|
5
5
|
require 'sqlite3'
|
6
6
|
require 'recordx'
|
7
|
+
require 'drb_sqlite'
|
7
8
|
|
8
9
|
|
9
10
|
class RecordxSqlite
|
10
11
|
|
11
|
-
def initialize(dbfile, table:
|
12
|
-
sql: nil)
|
13
|
-
|
14
|
-
@
|
12
|
+
def initialize(dbfile, table: nil, primary_key: :id, pk: primary_key,
|
13
|
+
sql: nil, pagesize: 10, debug: false)
|
14
|
+
|
15
|
+
@debug = debug
|
16
|
+
sqlite = dbfile =~ /^sqlite:\/\// ? DRbSQLite : SQLite3::Database
|
17
|
+
@db = sqlite.new dbfile
|
15
18
|
|
16
19
|
@db.results_as_hash = true
|
17
20
|
|
@@ -26,19 +29,56 @@ class RecordxSqlite
|
|
26
29
|
@primary_key = h[@table].keys.first
|
27
30
|
|
28
31
|
create_table(@table, h[@table]) if @db.table_info(@table).empty?
|
32
|
+
|
33
|
+
else
|
34
|
+
|
35
|
+
if @db.respond_to? :tables then
|
36
|
+
@table = @db.tables.first
|
37
|
+
@primary_key = @db.fields(@table).first
|
38
|
+
else
|
39
|
+
|
40
|
+
sql = "SELECT name FROM sqlite_master WHERE type='table';"
|
41
|
+
r = @db.execute(sql)
|
42
|
+
puts 'r: ' + r.inspect if @debug
|
43
|
+
|
44
|
+
a = r.map {|x| x['name']}
|
45
|
+
puts 'a: ' + a.inspect if @debug
|
46
|
+
|
47
|
+
sys = a.grep /^sqlite_/
|
48
|
+
@table = (a - sys).first
|
49
|
+
puts '@table: ' + @table.inspect if @debug
|
50
|
+
|
51
|
+
@primary_key = @db.table_info(@table).map {|x| x['name'].to_sym }.first
|
52
|
+
puts '@primary_key: ' + @primary_key.inspect if @debug
|
53
|
+
|
54
|
+
end
|
29
55
|
|
30
56
|
end
|
31
57
|
|
32
|
-
@sql = sql
|
33
|
-
|
58
|
+
@sql = sql = 'select * from ' + @table.to_s
|
59
|
+
@default_sql = @sql
|
60
|
+
@pagesize = pagesize
|
34
61
|
@a = nil
|
35
62
|
|
63
|
+
# create the fhe find_by methods for each fields
|
64
|
+
@db.table_info(@table).each do |cols|
|
65
|
+
#puts 'cols: ' + cols.inspect
|
66
|
+
define_singleton_method ('find_by_' + cols['name']).to_sym do |val|
|
67
|
+
find_by(cols['name'], val)
|
68
|
+
end
|
69
|
+
|
70
|
+
define_singleton_method ('find_all_by_' + cols['name']).to_sym do |val|
|
71
|
+
find_all_by(cols['name'], val)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
36
75
|
end
|
37
76
|
|
38
77
|
# note: when using method all() you will need to call method refresh()
|
39
78
|
# first if a record had recently been added since the recordset was loaded
|
40
79
|
#
|
41
80
|
def all()
|
81
|
+
@sql = @default_sql
|
42
82
|
query(@sql) unless @a
|
43
83
|
@a
|
44
84
|
end
|
@@ -71,15 +111,52 @@ class RecordxSqlite
|
|
71
111
|
|
72
112
|
end
|
73
113
|
|
114
|
+
def find_by(field, val)
|
115
|
+
|
116
|
+
query(@sql) unless @a
|
117
|
+
@a.find {|x| x.method(field).call == val}
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
def find_all_by(field, val)
|
122
|
+
|
123
|
+
query(@sql) unless @a
|
124
|
+
@a.select {|x| x.method(field).call == val}
|
125
|
+
|
126
|
+
end
|
127
|
+
|
74
128
|
# returns the 1st n rows
|
75
129
|
#
|
76
130
|
def first(n=1)
|
77
131
|
query(@sql + ' LIMIT ' + n.to_s, cache: false)
|
78
132
|
end
|
79
|
-
|
80
|
-
def
|
133
|
+
|
134
|
+
def order(dir=:asc)
|
135
|
+
@sql += " ORDER BY #{@primary_key} #{dir.to_s.upcase}"
|
136
|
+
self
|
137
|
+
end
|
138
|
+
|
139
|
+
def page(n=1)
|
81
140
|
|
82
|
-
|
141
|
+
query(@sql + " ORDER BY %s DESC LIMIT %s OFFSET %s" %
|
142
|
+
[@primary_key, @pagesize, @pagesize*(n-1)], cache: false)
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
def query(sql=@sql, cache: true, heading: true)
|
147
|
+
|
148
|
+
if heading then
|
149
|
+
|
150
|
+
rs = @db.query sql
|
151
|
+
|
152
|
+
else
|
153
|
+
|
154
|
+
@db.results_as_hash = false
|
155
|
+
rs = @db.query(sql).to_a
|
156
|
+
@db.results_as_hash = true
|
157
|
+
|
158
|
+
return rs
|
159
|
+
end
|
83
160
|
|
84
161
|
a = rs.map do |h|
|
85
162
|
h2 = h.inject({}) {|r, x| k, v = x; r.merge(k.to_sym => v)}
|
@@ -130,4 +207,4 @@ WHERE #{@primary_key.to_s}='#{id}';"
|
|
130
207
|
|
131
208
|
end
|
132
209
|
|
133
|
-
end
|
210
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recordx_sqlite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,28 +10,32 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
+
|
31
|
-
|
32
|
-
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjEwMjI3MDk0NDA0WhcN
|
15
|
+
MjIwMjI3MDk0NDA0WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCWsEnT
|
17
|
+
HnD/rZuHzcxBKTeeYR1hc0Jfu7WK+Vjc2J2RO2Vc1+GNmNVNKpKJTpLQfgVRRe3p
|
18
|
+
By6GijiR4h9ThjMttAq5T615m77BClaWA6zwKew4VzSa8C2CDPuiDbk+QI0SbISb
|
19
|
+
0UFCtzgH/FpKp9GbqDpTn0EaBR2XcSBrRE5rZu9pqpA9EDc1q8KvKioNmKS+cOlV
|
20
|
+
eDdudbAIvzVnmMXkd9hl8uF8B2IWeh8RF5UHgEWPeObsZBovASQZC6SfeEcbvioL
|
21
|
+
WGFhKkidAy2G+10AXlofdJkMX7iWl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Xx/
|
36
|
+
VfP9/tWv/9cP4k9V2nUJNEmu
|
33
37
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
38
|
+
date: 2021-02-27 00:00:00.000000000 Z
|
35
39
|
dependencies:
|
36
40
|
- !ruby/object:Gem::Dependency
|
37
41
|
name: sqlite3
|
@@ -39,40 +43,60 @@ dependencies:
|
|
39
43
|
requirements:
|
40
44
|
- - "~>"
|
41
45
|
- !ruby/object:Gem::Version
|
42
|
-
version: '1.
|
46
|
+
version: '1.4'
|
43
47
|
- - ">="
|
44
48
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
49
|
+
version: 1.4.1
|
46
50
|
type: :runtime
|
47
51
|
prerelease: false
|
48
52
|
version_requirements: !ruby/object:Gem::Requirement
|
49
53
|
requirements:
|
50
54
|
- - "~>"
|
51
55
|
- !ruby/object:Gem::Version
|
52
|
-
version: '1.
|
56
|
+
version: '1.4'
|
53
57
|
- - ">="
|
54
58
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
59
|
+
version: 1.4.1
|
56
60
|
- !ruby/object:Gem::Dependency
|
57
61
|
name: recordx
|
58
62
|
requirement: !ruby/object:Gem::Requirement
|
59
63
|
requirements:
|
60
64
|
- - "~>"
|
61
65
|
- !ruby/object:Gem::Version
|
62
|
-
version: '0.
|
66
|
+
version: '0.5'
|
63
67
|
- - ">="
|
64
68
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.4
|
69
|
+
version: 0.5.4
|
66
70
|
type: :runtime
|
67
71
|
prerelease: false
|
68
72
|
version_requirements: !ruby/object:Gem::Requirement
|
69
73
|
requirements:
|
70
74
|
- - "~>"
|
71
75
|
- !ruby/object:Gem::Version
|
72
|
-
version: '0.
|
76
|
+
version: '0.5'
|
73
77
|
- - ">="
|
74
78
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.4
|
79
|
+
version: 0.5.4
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: drb_sqlite
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - "~>"
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0.3'
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.3.3
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.3'
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 0.3.3
|
76
100
|
description:
|
77
101
|
email: james@jamesrobertson.eu
|
78
102
|
executables: []
|
@@ -100,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
124
|
version: '0'
|
101
125
|
requirements: []
|
102
126
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.7.10
|
104
128
|
signing_key:
|
105
129
|
specification_version: 4
|
106
130
|
summary: RecordX-SQLite is an object relational mapper primarily designed for updating
|
metadata.gz.sig
CHANGED
Binary file
|