recordx_sqlite 0.1.2 → 0.1.3

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: 9323b4c82ce89a36aabab387780e377c0db10ba7
4
- data.tar.gz: b7fd2bf0bd1ee50fd4b3ce9da277d3eb084efebc
3
+ metadata.gz: e069e8ccb9d0cbe316d0ed625a7ae24a5108b2a9
4
+ data.tar.gz: 3e39c34f538d22ed9fd39ef0848d723027152fd5
5
5
  SHA512:
6
- metadata.gz: 77b3f0b2d2c57bf6c7bea34c5b0f004b5c7b03d313d9416f795ac08fcbf228d4547157c700b7e94a6be51e4e4f5d7ff1b0a189ad386221e7a53bb0c47f3e013b
7
- data.tar.gz: faa156cb198c9fe6d90b8aea54a15c6c720d2463c0aa650e5ead4b49425fe524941b166694ba2ad27b7bb7aede8ea6fcf29d43113f7758664553044d365058f9
6
+ metadata.gz: 2a5de2afcc95af499e92e65b2d922700bde7d2960a6e9fe5c1ba83f78d6535213475f7e42a42e81968a1a6c8aa5ca44787eb0b3e4cf91580bd06f0d48d7c7a3d
7
+ data.tar.gz: be52987770f9bfd896718be81f1dc065750088e71da426acd7f22d683c0dd08bbc22d2870b81f452f0b66e1e826027a0821eb702c6c03d058802ccce6a440480
checksums.yaml.gz.sig CHANGED
Binary file
@@ -8,36 +8,43 @@ require 'recordx'
8
8
 
9
9
  class RecordxSqlite
10
10
 
11
- def initialize(dbfile, table)
12
-
11
+ def initialize(dbfile, table: '', primary_key: :id, pk: primary_key)
12
+
13
+
13
14
  @db = SQLite3::Database.new dbfile
15
+
14
16
  @db.results_as_hash = true
15
17
  rs = @db.query 'select * from ' + table
16
18
 
19
+ @table, @primary_key = table, pk.to_sym
20
+
17
21
  @a = rs.map do |h|
18
22
  h2 = h.inject({}) {|r, x| k, v = x; r.merge(k.to_sym => v)}
19
- RecordX.new(h2, self, h2[:uid])
23
+ RecordX.new(h2, self, h2[@primary_key])
20
24
  end
21
25
 
22
- @table = table
23
-
24
26
  end
25
27
 
26
28
  def all()
27
29
  @a
28
30
  end
31
+
32
+ def find(id)
33
+ @a.find {|x| x.method(@primary_key).call == id}
34
+ end
29
35
 
30
36
  def update(id, h={})
31
37
 
32
38
  col, value = h.to_a.first
33
- return if col == :id
39
+ return if col == @primary_key
34
40
 
35
41
  s = "
36
42
  UPDATE #{@table}
37
43
  SET #{col}='#{value}'
38
- WHERE id='#{id}';"
44
+ WHERE #{@primary_key.to_s}='#{id}';"
39
45
 
40
46
  @db.execute(s)
41
47
 
42
48
  end
43
49
  end
50
+
data.tar.gz.sig CHANGED
Binary file
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  pewreBQ0QCPuPbV1FPlyX5N5qsGIMHFIYqUlaykOA8156Y6fbIbqQsLwxaSr8WkD
32
32
  eojajR/fTTvliw==
33
33
  -----END CERTIFICATE-----
34
- date: 2016-07-16 00:00:00.000000000 Z
34
+ date: 2016-07-17 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
metadata.gz.sig CHANGED
Binary file