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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e069e8ccb9d0cbe316d0ed625a7ae24a5108b2a9
4
- data.tar.gz: 3e39c34f538d22ed9fd39ef0848d723027152fd5
3
+ metadata.gz: 629bf314f8f57718df393bab1a02e5fcf0b105f3
4
+ data.tar.gz: 8cf6aa3dec52b3f3563826355f5d4036d81d6d6b
5
5
  SHA512:
6
- metadata.gz: 2a5de2afcc95af499e92e65b2d922700bde7d2960a6e9fe5c1ba83f78d6535213475f7e42a42e81968a1a6c8aa5ca44787eb0b3e4cf91580bd06f0d48d7c7a3d
7
- data.tar.gz: be52987770f9bfd896718be81f1dc065750088e71da426acd7f22d683c0dd08bbc22d2870b81f452f0b66e1e826027a0821eb702c6c03d058802ccce6a440480
6
+ metadata.gz: 242b4db12046c61892a20fc7316a1fca7bd3b06219f83d6f470158f6fcc6295944e140b8f8635506c23cff1cad8bcf38c14c19b70e798571c124920e4d4690f9
7
+ data.tar.gz: effd34b8ec5c10fba53454ce01b0048f5c0df4bd3eb631867df74cb9c2962b0f659e2a58d0f5e77d266b89405905520ef5c9d0fc42560174761ffe39bad31d5e
checksums.yaml.gz.sig CHANGED
Binary file
@@ -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
- rs = @db.query 'select * from ' + table
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
- O"�I��� �˒�HZ��$��%e�,KH������Ŷ��w_�-��ɮp�gT'���o숾�MgU��_]�X`���r]{��)Koȋ fT㔥���
2
- C?�x��b�eͤ�>�T�w����
1
+ I����>9&���Hב�-\ %��Ϭ�>���|���Rr�]t{4d���! /�A�L�����b�����X��|��(�� "��ʨ������k��3��cZ�EP��t~�KaW���EiG���c^,)������r���[zD��]�.J� �ɜ��5]I�a�� :�:�cdAz� ��µ���y@D{�w_�����~�D^ٸ��n�߶Ln�3L���~2�QTG���Ó�D+����vr;
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.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file