recordx_sqlite 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/recordx_sqlite.rb +26 -12
- data.tar.gz.sig +1 -2
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 629bf314f8f57718df393bab1a02e5fcf0b105f3
|
4
|
+
data.tar.gz: 8cf6aa3dec52b3f3563826355f5d4036d81d6d6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 242b4db12046c61892a20fc7316a1fca7bd3b06219f83d6f470158f6fcc6295944e140b8f8635506c23cff1cad8bcf38c14c19b70e798571c124920e4d4690f9
|
7
|
+
data.tar.gz: effd34b8ec5c10fba53454ce01b0048f5c0df4bd3eb631867df74cb9c2962b0f659e2a58d0f5e77d266b89405905520ef5c9d0fc42560174761ffe39bad31d5e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/recordx_sqlite.rb
CHANGED
@@ -8,30 +8,43 @@ require 'recordx'
|
|
8
8
|
|
9
9
|
class RecordxSqlite
|
10
10
|
|
11
|
-
def initialize(dbfile, table: '', primary_key: :id, pk: primary_key
|
12
|
-
|
13
|
-
|
11
|
+
def initialize(dbfile, table: '', primary_key: :id, pk: primary_key,
|
12
|
+
sql: 'select * from ' + table)
|
13
|
+
|
14
14
|
@db = SQLite3::Database.new dbfile
|
15
15
|
|
16
16
|
@db.results_as_hash = true
|
17
|
-
|
18
|
-
|
19
|
-
@table, @primary_key = table, pk.to_sym
|
20
|
-
|
21
|
-
@a = rs.map do |h|
|
22
|
-
h2 = h.inject({}) {|r, x| k, v = x; r.merge(k.to_sym => v)}
|
23
|
-
RecordX.new(h2, self, h2[@primary_key])
|
24
|
-
end
|
17
|
+
@table, @primary_key, @sql = table, pk.to_sym, sql
|
18
|
+
@a = nil
|
25
19
|
|
26
20
|
end
|
27
21
|
|
28
|
-
def all()
|
22
|
+
def all()
|
23
|
+
query(@sql) unless @a
|
29
24
|
@a
|
30
25
|
end
|
31
26
|
|
32
27
|
def find(id)
|
28
|
+
query(@sql) unless @a
|
33
29
|
@a.find {|x| x.method(@primary_key).call == id}
|
34
30
|
end
|
31
|
+
|
32
|
+
def query(sql=@sql)
|
33
|
+
|
34
|
+
@sql = sql
|
35
|
+
rs = @db.query sql
|
36
|
+
|
37
|
+
@a = rs.map do |h|
|
38
|
+
h2 = h.inject({}) {|r, x| k, v = x; r.merge(k.to_sym => v)}
|
39
|
+
RecordX.new(h2, self, h2[@primary_key])
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def refresh()
|
45
|
+
query(@sql)
|
46
|
+
'refreshed'
|
47
|
+
end
|
35
48
|
|
36
49
|
def update(id, h={})
|
37
50
|
|
@@ -46,5 +59,6 @@ WHERE #{@primary_key.to_s}='#{id}';"
|
|
46
59
|
@db.execute(s)
|
47
60
|
|
48
61
|
end
|
62
|
+
|
49
63
|
end
|
50
64
|
|
data.tar.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
C?�x��b�eͤ�>�T�w����
|
1
|
+
I����>9&���Hב�-\%��Ϭ�>���|���R�r�]t{�4d���! /�A�L�����b�����X��|��(��"��ʨ������k��3��cZ�EP��t~�KaW���EiG���c^,)������r���[zD��]�.J��ɜ��5]I�a�� :�:�cd�Az���µ���y@D{�w_�����~�D^ٸ��n�߶Ln�3L���~2�QTG���Ó�D+����vr;
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|