commutator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,607 @@
1
+ require 'ice_nine'
2
+
3
+ module Commutator
4
+ module Util
5
+ # Provides a placeholder string for a name or value for use in DynamoDB
6
+ # expressions.
7
+ #
8
+ # Name placeholders will return the name itself if it is not
9
+ # a reserved word (and therefore safe to use).
10
+ #
11
+ # Value placeholders are always generated.
12
+ module Placeholders
13
+ def self.value(value)
14
+ ":V_#{hash(value)}"
15
+ end
16
+
17
+ def self.name(name)
18
+ RESERVED_WORDS.include?(name.downcase) ? "#N_#{hash(name)}" : name
19
+ end
20
+
21
+ private
22
+
23
+ # Wow. Dang.
24
+ RESERVED_WORDS = IceNine.deep_freeze(%w(
25
+ abort
26
+ absolute
27
+ action
28
+ add
29
+ after
30
+ agent
31
+ aggregate
32
+ all
33
+ allocate
34
+ alter
35
+ analyze
36
+ and
37
+ any
38
+ archive
39
+ are
40
+ array
41
+ as
42
+ asc
43
+ ascii
44
+ asensitive
45
+ assertion
46
+ asymmetric
47
+ at
48
+ atomic
49
+ attach
50
+ attribute
51
+ auth
52
+ authorization
53
+ authorize
54
+ auto
55
+ avg
56
+ back
57
+ backup
58
+ base
59
+ batch
60
+ before
61
+ begin
62
+ between
63
+ bigint
64
+ binary
65
+ bit
66
+ blob
67
+ block
68
+ boolean
69
+ both
70
+ breadth
71
+ bucket
72
+ bulk
73
+ by
74
+ byte
75
+ call
76
+ called
77
+ calling
78
+ capacity
79
+ cascade
80
+ cascaded
81
+ case
82
+ cast
83
+ catalog
84
+ char
85
+ character
86
+ check
87
+ class
88
+ clob
89
+ close
90
+ cluster
91
+ clustered
92
+ clustering
93
+ clusters
94
+ coalesce
95
+ collate
96
+ collation
97
+ collection
98
+ column
99
+ columns
100
+ combine
101
+ comment
102
+ commit
103
+ compact
104
+ compile
105
+ compress
106
+ condition
107
+ conflict
108
+ connect
109
+ connection
110
+ consistency
111
+ consistent
112
+ constraint
113
+ constraints
114
+ constructor
115
+ consumed
116
+ continue
117
+ convert
118
+ copy
119
+ corresponding
120
+ count
121
+ counter
122
+ create
123
+ cross
124
+ cube
125
+ current
126
+ cursor
127
+ cycle
128
+ data
129
+ database
130
+ date
131
+ datetime
132
+ day
133
+ deallocate
134
+ dec
135
+ decimal
136
+ declare
137
+ default
138
+ deferrable
139
+ deferred
140
+ define
141
+ defined
142
+ definition
143
+ delete
144
+ delimited
145
+ depth
146
+ deref
147
+ desc
148
+ describe
149
+ descriptor
150
+ detach
151
+ deterministic
152
+ diagnostics
153
+ directories
154
+ disable
155
+ disconnect
156
+ distinct
157
+ distribute
158
+ do
159
+ domain
160
+ double
161
+ drop
162
+ dump
163
+ duration
164
+ dynamic
165
+ each
166
+ element
167
+ else
168
+ elseif
169
+ empty
170
+ enable
171
+ end
172
+ equal
173
+ equals
174
+ error
175
+ escape
176
+ escaped
177
+ eval
178
+ evaluate
179
+ exceeded
180
+ except
181
+ exception
182
+ exceptions
183
+ exclusive
184
+ exec
185
+ execute
186
+ exists
187
+ exit
188
+ explain
189
+ explode
190
+ export
191
+ expression
192
+ extended
193
+ external
194
+ extract
195
+ fail
196
+ false
197
+ family
198
+ fetch
199
+ fields
200
+ file
201
+ filter
202
+ filtering
203
+ final
204
+ finish
205
+ first
206
+ fixed
207
+ flattern
208
+ float
209
+ for
210
+ force
211
+ foreign
212
+ format
213
+ forward
214
+ found
215
+ free
216
+ from
217
+ full
218
+ function
219
+ functions
220
+ general
221
+ generate
222
+ get
223
+ glob
224
+ global
225
+ go
226
+ goto
227
+ grant
228
+ greater
229
+ group
230
+ grouping
231
+ handler
232
+ hash
233
+ have
234
+ having
235
+ heap
236
+ hidden
237
+ hold
238
+ hour
239
+ identified
240
+ identity
241
+ if
242
+ ignore
243
+ immediate
244
+ import
245
+ in
246
+ including
247
+ inclusive
248
+ increment
249
+ incremental
250
+ index
251
+ indexed
252
+ indexes
253
+ indicator
254
+ infinite
255
+ initially
256
+ inline
257
+ inner
258
+ innter
259
+ inout
260
+ input
261
+ insensitive
262
+ insert
263
+ instead
264
+ int
265
+ integer
266
+ intersect
267
+ interval
268
+ into
269
+ invalidate
270
+ is
271
+ isolation
272
+ item
273
+ items
274
+ iterate
275
+ join
276
+ key
277
+ keys
278
+ lag
279
+ language
280
+ large
281
+ last
282
+ lateral
283
+ lead
284
+ leading
285
+ leave
286
+ left
287
+ length
288
+ less
289
+ level
290
+ like
291
+ limit
292
+ limited
293
+ lines
294
+ list
295
+ load
296
+ local
297
+ localtime
298
+ localtimestamp
299
+ location
300
+ locator
301
+ lock
302
+ locks
303
+ log
304
+ loged
305
+ long
306
+ loop
307
+ lower
308
+ map
309
+ match
310
+ materialized
311
+ max
312
+ maxlen
313
+ member
314
+ merge
315
+ method
316
+ metrics
317
+ min
318
+ minus
319
+ minute
320
+ missing
321
+ mod
322
+ mode
323
+ modifies
324
+ modify
325
+ module
326
+ month
327
+ multi
328
+ multiset
329
+ name
330
+ names
331
+ national
332
+ natural
333
+ nchar
334
+ nclob
335
+ new
336
+ next
337
+ no
338
+ none
339
+ not
340
+ null
341
+ nullif
342
+ number
343
+ numeric
344
+ object
345
+ of
346
+ offline
347
+ offset
348
+ old
349
+ on
350
+ online
351
+ only
352
+ opaque
353
+ open
354
+ operator
355
+ option
356
+ or
357
+ order
358
+ ordinality
359
+ other
360
+ others
361
+ out
362
+ outer
363
+ output
364
+ over
365
+ overlaps
366
+ override
367
+ owner
368
+ pad
369
+ parallel
370
+ parameter
371
+ parameters
372
+ partial
373
+ partition
374
+ partitioned
375
+ partitions
376
+ path
377
+ percent
378
+ percentile
379
+ permission
380
+ permissions
381
+ pipe
382
+ pipelined
383
+ plan
384
+ pool
385
+ position
386
+ precision
387
+ prepare
388
+ preserve
389
+ primary
390
+ prior
391
+ private
392
+ privileges
393
+ procedure
394
+ processed
395
+ project
396
+ projection
397
+ property
398
+ provisioning
399
+ public
400
+ put
401
+ query
402
+ quit
403
+ quorum
404
+ raise
405
+ random
406
+ range
407
+ rank
408
+ raw
409
+ read
410
+ reads
411
+ real
412
+ rebuild
413
+ record
414
+ recursive
415
+ reduce
416
+ ref
417
+ reference
418
+ references
419
+ referencing
420
+ regexp
421
+ region
422
+ reindex
423
+ relative
424
+ release
425
+ remainder
426
+ rename
427
+ repeat
428
+ replace
429
+ request
430
+ reset
431
+ resignal
432
+ resource
433
+ response
434
+ restore
435
+ restrict
436
+ result
437
+ return
438
+ returning
439
+ returns
440
+ reverse
441
+ revoke
442
+ right
443
+ role
444
+ roles
445
+ rollback
446
+ rollup
447
+ routine
448
+ row
449
+ rows
450
+ rule
451
+ rules
452
+ sample
453
+ satisfies
454
+ save
455
+ savepoint
456
+ scan
457
+ schema
458
+ scope
459
+ scroll
460
+ search
461
+ second
462
+ section
463
+ segment
464
+ segments
465
+ select
466
+ self
467
+ semi
468
+ sensitive
469
+ separate
470
+ sequence
471
+ serializable
472
+ session
473
+ set
474
+ sets
475
+ shard
476
+ share
477
+ shared
478
+ short
479
+ show
480
+ signal
481
+ similar
482
+ size
483
+ skewed
484
+ smallint
485
+ snapshot
486
+ some
487
+ source
488
+ space
489
+ spaces
490
+ sparse
491
+ specific
492
+ specifictype
493
+ split
494
+ sql
495
+ sqlcode
496
+ sqlerror
497
+ sqlexception
498
+ sqlstate
499
+ sqlwarning
500
+ start
501
+ state
502
+ static
503
+ status
504
+ storage
505
+ store
506
+ stored
507
+ stream
508
+ string
509
+ struct
510
+ style
511
+ sub
512
+ submultiset
513
+ subpartition
514
+ substring
515
+ subtype
516
+ sum
517
+ super
518
+ symmetric
519
+ synonym
520
+ system
521
+ table
522
+ tablesample
523
+ temp
524
+ temporary
525
+ terminated
526
+ text
527
+ than
528
+ then
529
+ throughput
530
+ time
531
+ timestamp
532
+ timezone
533
+ tinyint
534
+ to
535
+ token
536
+ total
537
+ touch
538
+ trailing
539
+ transaction
540
+ transform
541
+ translate
542
+ translation
543
+ treat
544
+ trigger
545
+ trim
546
+ true
547
+ truncate
548
+ ttl
549
+ tuple
550
+ type
551
+ under
552
+ undo
553
+ union
554
+ unique
555
+ unit
556
+ unknown
557
+ unlogged
558
+ unnest
559
+ unprocessed
560
+ unsigned
561
+ until
562
+ update
563
+ upper
564
+ url
565
+ usage
566
+ use
567
+ user
568
+ users
569
+ using
570
+ uuid
571
+ vacuum
572
+ value
573
+ valued
574
+ values
575
+ varchar
576
+ variable
577
+ variance
578
+ varint
579
+ varying
580
+ view
581
+ views
582
+ virtual
583
+ void
584
+ wait
585
+ when
586
+ whenever
587
+ where
588
+ while
589
+ window
590
+ with
591
+ within
592
+ without
593
+ work
594
+ wrapped
595
+ write
596
+ year
597
+ zone
598
+ ))
599
+
600
+ private_constant :RESERVED_WORDS
601
+
602
+ def self.hash(val)
603
+ Digest::SHA1.hexdigest(val.to_json).first(10)
604
+ end
605
+ end
606
+ end
607
+ end
@@ -0,0 +1,3 @@
1
+ module Commutator
2
+ VERSION = "0.1.0"
3
+ end
data/lib/commutator.rb ADDED
@@ -0,0 +1,64 @@
1
+ require "aws-sdk"
2
+
3
+ require "active_model"
4
+
5
+ require "active_support"
6
+ require "active_support/core_ext"
7
+
8
+
9
+ module Commutator
10
+ API_TABLE_OPERATIONS = [
11
+ :create_table,
12
+ :delete_table,
13
+ :describe_table,
14
+ :list_tables,
15
+ :update_table
16
+ ].freeze
17
+
18
+ API_ITEM_OPERATIONS = [
19
+ :batch_get_item,
20
+ :batch_write_item,
21
+ :delete_item,
22
+ :get_item,
23
+ :put_item,
24
+ :update_item,
25
+ :query,
26
+ :scan
27
+ ].freeze
28
+
29
+ API_OPERATIONS = (
30
+ API_TABLE_OPERATIONS +
31
+ API_ITEM_OPERATIONS
32
+ ).freeze
33
+
34
+ autoload :Collection, "commutator/collection"
35
+ autoload :ItemModifiers, "commutator/item_modifiers"
36
+ autoload :Model, "commutator/model"
37
+ autoload :SimpleClient, "commutator/simple_client"
38
+
39
+ module Expressions
40
+ autoload :AttributeNames, "commutator/expressions/attribute_names"
41
+ autoload :AttributeValues, "commutator/expressions/attribute_values"
42
+ autoload :ConditionExpression, "commutator/expressions/condition_expression"
43
+ autoload :ProjectionExpression, "commutator/expressions/projection_expression"
44
+ autoload :Statement, "commutator/expressions/statement"
45
+ autoload :UpdateExpression, "commutator/expressions/update_expression"
46
+ end
47
+
48
+ module Options
49
+ autoload :DeleteItem, "commutator/options/delete_item"
50
+ autoload :GetItem, "commutator/options/get_item"
51
+ autoload :Proxy, "commutator/options/proxy"
52
+ autoload :PutItem, "commutator/options/put_item"
53
+ autoload :Query, "commutator/options/query"
54
+ autoload :Scan, "commutator/options/scan"
55
+ autoload :UpdateItem, "commutator/options/update_item"
56
+ end
57
+
58
+ module Util
59
+ autoload :Fluent, "commutator/util/fluent"
60
+ autoload :Placeholders, "commutator/util/placeholders"
61
+ end
62
+ end
63
+
64
+ require "commutator/version"