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 +8 -8
- data/README.md +6 -29
- data/lib/quickbase_record/queries.rb +27 -8
- data/lib/quickbase_record/version.rb +1 -1
- data/spec/queries_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjQxYzVlNzkwN2NhMTQ4NWZlN2MzODQwOWU1NzI2MTQ0ZTMyN2YxYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZmNiZmQ4ZDY0MzZmYWU2ZTY3MWE4MGM5Y2U2ODkxNmRhYzFjMjA0Zg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTIyMWZkOTk2OGI4ZWZiOGMwNzE3NGY4OGY2MTBlNjVmNzlmZjkwYTE1OWM4
|
10
|
+
OTFmMzIyNDBkYjYxZjczODY1NTk3MGFlMWE3NTZlZmQwOWFhYTAwMmM0ODUy
|
11
|
+
MmNjZTBjZjlkZjkxN2I5MTBjNjhhYmQxM2E5NDM3MDMzMWQ5ZTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
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
|
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
|
|
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.
|
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
|
+
date: 2015-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|