quickbase_record 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTQ2NTdmMWRhOTIyN2U2MjZkODJlODVmNjZjZGUwYmNmMTM4NGE0Mg==
4
+ MjQxYzVlNzkwN2NhMTQ4NWZlN2MzODQwOWU1NzI2MTQ0ZTMyN2YxYg==
5
5
  data.tar.gz: !binary |-
6
- M2U4N2Q3MmNhNjcyMzI4ZmRiNmU4NGMwNGIzZTZmNmQ0Y2E1ZTgxNQ==
6
+ ZmNiZmQ4ZDY0MzZmYWU2ZTY3MWE4MGM5Y2U2ODkxNmRhYzFjMjA0Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGQ2YThlZDk3MGYxMWRlNmM4NWUyYTliZjAwODM1YTk2Zjc0NzVlM2JjNjg5
10
- M2M0MDE2YWJmZTFmMzgxZjgxODNlZjI5YmRhZTRkYjVmM2U1ZjljZTY3MWI2
11
- NGE2Yzc5NjU4MjIxZTIyZmZhMmFmOGI3Mzk3NjcwNzU0Yjk1MWQ=
9
+ MTIyMWZkOTk2OGI4ZWZiOGMwNzE3NGY4OGY2MTBlNjVmNzlmZjkwYTE1OWM4
10
+ OTFmMzIyNDBkYjYxZjczODY1NTk3MGFlMWE3NTZlZmQwOWFhYTAwMmM0ODUy
11
+ MmNjZTBjZjlkZjkxN2I5MTBjNjhhYmQxM2E5NDM3MDMzMWQ5ZTY=
12
12
  data.tar.gz: !binary |-
13
- NjQzZDNkYjFjZDhjZjY3NDQ1NTg1MmM4MDkwMWM5ZWJkYTI4MTI2MGQ4Mzc1
14
- ZjUyMGFkMGM2ODAwODcyMDYxZjgyOWIwYjRkNjM0ZWVjYmIyZjg5ZDgwODcy
15
- ZWFlN2JkZjExNDk5OWM1Zjk5OGRmODg0OGRkM2Q5MDA3Nzk4Zjk=
13
+ YjM1NGQ0ZjI5NDM2MWEzNzJmMjhmMWU2YzE4NTJlNzQ0NDdlNjQ2NmIzMTcy
14
+ MWJkOWQ1NGU1MTYyNzg2YmY3Y2JjYzA2NWE4YzNlOWZiMTk1ZmExNWUyZDhl
15
+ MTJmM2U0MTM0YzU4NjZiZGYwYjUzMjc2OWFhODVlN2ViZTM0Y2M=
data/README.md CHANGED
@@ -103,35 +103,6 @@ Post.build_query(author: 'Cullen', title: 'Some Title')
103
103
  => "{'8'.EX.'Cullen'}AND{'9'.EX.'Some Title'}"
104
104
  ```
105
105
 
106
- ### What You Get
107
- Classes that include QuickbaseRecord::Model and define their fields will have a handful of class and instance methods for interacting with your QuickBase application similar to ActiveRecord. The goal is to be able to use QuickBase as a database and treat your models the same way you would with a traditional database.
108
-
109
- ```
110
- @post = Post.find(1) => <Post: @id=1, @content="Amazing post content", @author: 'Cullen Jett'>
111
-
112
- --
113
-
114
- <%= form_for @post do |f| %>
115
- # code...
116
- <% end %>
117
-
118
- --
119
-
120
- @post = Post.where(author: 'Cullen Jett').first
121
- @post.update_attributes(author: 'THE Cullen Jett')
122
-
123
- --
124
-
125
- etc.
126
- ```
127
-
128
-
129
- Also included/extended are ActiveModel::Naming, ActiveModel::Callbacks, ActiveModel::Validations, and ActiveModel::Conversion ([see ActiveModel docs for details](https://github.com/rails/rails/tree/master/activemodel/lib/active_model)). The biggest benefit here is the availability of `.validates` on your class to validate attributes and capture invalid attributes with `#valid?`.
130
-
131
- Be aware that validations needing context from the database (i.e. `validates_uniqueness_of`) are not yet supported and will need to be implemented manually.
132
-
133
- Database callbacks (i.e. `before_save :create_token!`) are not fully functional yet, so stay tuned.
134
-
135
106
  ## Available Methods
136
107
  * **.create(attributes_hash)**
137
108
  - Intantiate *and* save a new object with the given attributes
@@ -207,6 +178,12 @@ Database callbacks (i.e. `before_save :create_token!`) are not fully functional
207
178
  Post.where(author: ['Cullen Jett', 'Socrates'], query_options: {clist: 'id.author', slist: 'author'})
208
179
  ```
209
180
 
181
+ * **.batch_where(attributes_hash, count=1000)**
182
+ - Same as .where, but queries in batches of {count}
183
+ ```
184
+ Post.where({date_created: ['today', 'yesterday']}, 500) # note the necessary "{}" around the attributes_hash
185
+ ```
186
+
210
187
  * **.qid(id)**
211
188
  - Accepts a QID (QuickBase report ID)
212
189
  - Returns an array of objects
@@ -17,7 +17,10 @@ module QuickbaseRecord
17
17
  else
18
18
  clist = self.clist
19
19
  end
20
- query = { query: build_query(id: id), clist: clist }.merge(query_options)
20
+ # TODO: ':id' in build_query needs to be the primary key field name instead
21
+ query_hash = {}
22
+ query_hash[self.new.primary_key_field_name] = id
23
+ query = { query: build_query(query_hash), clist: clist }.merge(query_options)
21
24
  query_response = qb_client.do_query(dbid, query).first
22
25
 
23
26
  return nil if query_response.nil?
@@ -63,17 +66,33 @@ module QuickbaseRecord
63
66
  end
64
67
 
65
68
  def save_collection(objects)
66
- converted_objects = objects.map do |object|
67
- current_object = {}
68
- fields.each do |field_name, field|
69
- current_object[field.fid] = object.send(field_name)
70
- end
71
- new.remove_unwritable_fields(current_object)
72
- end
69
+ converted_objects = objects.map { |obj| build_quickbase_request(obj) }
73
70
 
74
71
  qb_client.import_from_csv(dbid, converted_objects)
75
72
  end
76
73
 
74
+ def batch_where(query_hash, count=1000)
75
+ all_query_results = []
76
+ skip = 0
77
+
78
+ begin
79
+ query = query_hash.merge(query_options: {options: "num-#{count}.skp-#{skip}"})
80
+ query_result = where(query)
81
+ all_query_results << query_result
82
+ skip += count
83
+ end until query_result.length < count
84
+
85
+ all_query_results.flatten
86
+ end
87
+
88
+ def build_quickbase_request(object)
89
+ converted_object = {}
90
+ fields.each do |field_name, field|
91
+ converted_object[field.fid] = object.send(field_name)
92
+ end
93
+ new.remove_unwritable_fields(converted_object)
94
+ end
95
+
77
96
  def build_query(query_hash)
78
97
  return convert_query_string(query_hash) if query_hash.is_a? String
79
98
 
@@ -1,3 +1,3 @@
1
1
  module QuickbaseRecord
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
data/spec/queries_spec.rb CHANGED
@@ -82,6 +82,13 @@ RSpec.describe QuickbaseRecord::Queries do
82
82
  end
83
83
  end
84
84
 
85
+ describe '.build_quickbase_request' do
86
+ it "converts an object to a hash of fid: value" do
87
+ teacher = TeacherFake.new(name: 'Mrs. Buttersworth', subject: 'Buttering')
88
+ expect(TeacherFake.build_quickbase_request(teacher)).to eq({6 => 'Mrs. Buttersworth', 7 => 'Buttering'})
89
+ end
90
+ end
91
+
85
92
  describe '.save_collection' do
86
93
  it "does something" do
87
94
  teacher1 = TeacherFake.new(name: 'Save collection teacher 1')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quickbase_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cullen Jett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler