Class: Cloudflare::D1Statement
- Inherits:
-
Object
- Object
- Cloudflare::D1Statement
- Defined in:
- lib/cloudflare_workers.rb
Instance Method Summary collapse
-
#all ⇒ Object
Returns a JS Promise that resolves to a Ruby Array of Ruby Hashes.
- #bind(*args) ⇒ Object
-
#first ⇒ Object
Returns a JS Promise that resolves to a single Ruby Hash (or nil).
-
#initialize(js) ⇒ D1Statement
constructor
A new instance of D1Statement.
-
#run ⇒ Object
Returns a JS Promise that resolves to a Ruby Hash with the D1 meta.
Constructor Details
#initialize(js) ⇒ D1Statement
Returns a new instance of D1Statement.
617 618 619 |
# File 'lib/cloudflare_workers.rb', line 617 def initialize(js) @js = js end |
Instance Method Details
#all ⇒ Object
Returns a JS Promise that resolves to a Ruby Array of Ruby Hashes.
629 630 631 632 633 634 |
# File 'lib/cloudflare_workers.rb', line 629 def all js_stmt = @js cf = Cloudflare err_cls = Cloudflare::D1Error `#{js_stmt}.all().then(function(res) { return #{cf}.$js_rows_to_ruby(res.results); }).catch(function(e) { #{Kernel}.$raise(#{err_cls}.$new(e.message || String(e), Opal.hash({binding_type: 'D1', operation: 'all'}))); })` end |
#bind(*args) ⇒ Object
621 622 623 624 625 626 |
# File 'lib/cloudflare_workers.rb', line 621 def bind(*args) js_args = `[]` args.each { |a| `#{js_args}.push(#{a})` } js = @js D1Statement.new(`#{js}.bind.apply(#{js}, #{js_args})`) end |
#first ⇒ Object
Returns a JS Promise that resolves to a single Ruby Hash (or nil).
637 638 639 640 641 642 |
# File 'lib/cloudflare_workers.rb', line 637 def first js_stmt = @js cf = Cloudflare err_cls = Cloudflare::D1Error `#{js_stmt}.first().then(function(res) { return res == null ? nil : #{cf}.$js_object_to_hash(res); }).catch(function(e) { #{Kernel}.$raise(#{err_cls}.$new(e.message || String(e), Opal.hash({binding_type: 'D1', operation: 'first'}))); })` end |
#run ⇒ Object
Returns a JS Promise that resolves to a Ruby Hash with the D1 meta.
645 646 647 648 649 650 |
# File 'lib/cloudflare_workers.rb', line 645 def run js_stmt = @js cf = Cloudflare err_cls = Cloudflare::D1Error `#{js_stmt}.run().then(function(res) { return #{cf}.$js_object_to_hash(res); }).catch(function(e) { #{Kernel}.$raise(#{err_cls}.$new(e.message || String(e), Opal.hash({binding_type: 'D1', operation: 'run'}))); })` end |