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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bea30fa0ae7d919dc8589e30330249ea6e095aa7
4
- data.tar.gz: 63f42ad1e7a55ca312af2de5c5617f1570c19810
2
+ SHA256:
3
+ metadata.gz: 76a8fff25e7ab18a811036ec5bd56bb13a27d54ccc0b87a0c40b65b214bb65a9
4
+ data.tar.gz: 046e030da21737657fc29dfbfa25eb6e0d837d706800964ca636fe70bacb1412
5
5
  SHA512:
6
- metadata.gz: f0b83a05495a1fa7ed4d1fd89967f25a20337f90dde0931b93bd15e91e629a8955f227e77d661c7c31e41ccb786fab3e34c61b7f109d3d4a7893a6c17738d903
7
- data.tar.gz: 6ad6164c430baebe6397357b71fc9c4e2108f4dc86f2a1fc9c026a373eec11e25cd840837b1aad770e0b14bb7678721999d17f4af5c51edde69ac3ae0dca1729
6
+ metadata.gz: 9786640fe5e958a18a816975ff8df6c7bf6e6ed7636bb4826710eca30e5f5489151e440b57eba1241a10fe45ec6b436c37566cb5a065f63f05b0f7b8ece8e728
7
+ data.tar.gz: b2d35d1179f24aba6421c18f9075e411bd2b993a8d780883073ea95e2094b4ee54e2ce566e6a5a5cc831ad72dd2be30195f171c8ab7db094d5068f49229187e4
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -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: '', primary_key: :id, pk: primary_key,
12
- sql: nil)
13
-
14
- @db = SQLite3::Database.new dbfile
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 || 'select * from ' + @table.to_s
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 query(sql=@sql, cache: true)
138
+
139
+ def page(n=1)
88
140
 
89
- rs = @db.query sql
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.2.6
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
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
- YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTE2MDcxNjE5MzI1NFoXDTE3MDcxNjE5MzI1NFowSDESMBAG
16
- A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
- EjAQBgoJkiaJk/IsZAEZF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MQaWtlf/f0CLHjjImuj/UUMqBU+XxGIQTjw01kCuErBIYH
30
+ KNPAv7P2Jm7ZOMNubvFTjPE6KvoslFbXEs0FPTf+MjiP/J1F6pHx4rcnxWoQ2qSq
31
+ uK7Zi8j3bRGDUGdW8c1btU8bUe3XsdfIwYRUvDm3E9fiHThH4Ta3uPLfeN6TCAje
32
+ qz2w2H+8jTC9zGdKh31dK9GUKneJiJ6EW8G27E9QWlZ0jezMLrjqzekSPGYREJBT
33
+ 45cJ79L4CUPnD+9WR75jGp2G3em8e/4nUlh29GvXOHi5SzpjuqEgLRRHLMG19mrg
34
+ Uy13/a2YkENgSlY9Q9bZW7jpb1CwVscJ4n+HLVb0fj8HKwsceJzeYf9JXHzJ2ykt
35
+ 14GYRdzYfQotOw5CFtPk6K1OgKW7WoEyiUBKdJanTGfXkAOum4dHWdWD7mm0RXx/
36
+ VfP9/tWv/9cP4k9V2nUJNEmu
33
37
  -----END CERTIFICATE-----
34
- date: 2017-07-02 00:00:00.000000000 Z
38
+ date: 2021-04-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.3'
46
+ version: '1.4'
43
47
  - - ">="
44
48
  - !ruby/object:Gem::Version
45
- version: 1.3.11
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.3'
56
+ version: '1.4'
53
57
  - - ">="
54
58
  - !ruby/object:Gem::Version
55
- version: 1.3.11
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.4'
66
+ version: '0.5'
63
67
  - - ">="
64
68
  - !ruby/object:Gem::Version
65
- version: 0.4.0
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.4'
76
+ version: '0.5'
73
77
  - - ">="
74
78
  - !ruby/object:Gem::Version
75
- version: 0.4.0
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.6.8
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