recordx_sqlite 0.2.6 → 0.3.3
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 +80 -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: 76a8fff25e7ab18a811036ec5bd56bb13a27d54ccc0b87a0c40b65b214bb65a9
|
4
|
+
data.tar.gz: 046e030da21737657fc29dfbfa25eb6e0d837d706800964ca636fe70bacb1412
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9786640fe5e958a18a816975ff8df6c7bf6e6ed7636bb4826710eca30e5f5489151e440b57eba1241a10fe45ec6b436c37566cb5a065f63f05b0f7b8ece8e728
|
7
|
+
data.tar.gz: b2d35d1179f24aba6421c18f9075e411bd2b993a8d780883073ea95e2094b4ee54e2ce566e6a5a5cc831ad72dd2be30195f171c8ab7db094d5068f49229187e4
|
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,14 +29,49 @@ 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
|
58
|
+
@sql = sql = 'select * from ' + @table.to_s
|
33
59
|
@default_sql = @sql
|
34
|
-
|
60
|
+
@pagesize = pagesize
|
35
61
|
@a = nil
|
36
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
|
+
|
37
75
|
end
|
38
76
|
|
39
77
|
# note: when using method all() you will need to call method refresh()
|
@@ -73,6 +111,20 @@ class RecordxSqlite
|
|
73
111
|
|
74
112
|
end
|
75
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.downcase == val.downcase}
|
125
|
+
|
126
|
+
end
|
127
|
+
|
76
128
|
# returns the 1st n rows
|
77
129
|
#
|
78
130
|
def first(n=1)
|
@@ -83,10 +135,28 @@ class RecordxSqlite
|
|
83
135
|
@sql += " ORDER BY #{@primary_key} #{dir.to_s.upcase}"
|
84
136
|
self
|
85
137
|
end
|
86
|
-
|
87
|
-
def
|
138
|
+
|
139
|
+
def page(n=1)
|
88
140
|
|
89
|
-
|
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
|
90
160
|
|
91
161
|
a = rs.map do |h|
|
92
162
|
h2 = h.inject({}) {|r, x| k, v = x; r.merge(k.to_sym => v)}
|
@@ -137,4 +207,4 @@ WHERE #{@primary_key.to_s}='#{id}';"
|
|
137
207
|
|
138
208
|
end
|
139
209
|
|
140
|
-
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.3
|
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+10AXlofdJkMX7iWlMZSkE1oWZ182rTYeIHxKUdAivEbYoHEX13z
|
22
|
+
wJzFFC0oS7ZBc/RfGf1ruDFHqDtN9xc2++ihbC4BYZEe+nF0WMFXNobysgTz6vkD
|
23
|
+
IhtPCkaj1hMHFLJRKIxlk3Zk2X0YUcDoCby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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
|