Class: Browser::Database::SQL
- Includes:
- Native
- Defined in:
- opal/browser/database/sql.rb
Defined Under Namespace
Classes: Error, Result, Row, Transaction
Instance Attribute Summary collapse
-
#description ⇒ String
readonly
The description for the database.
-
#name ⇒ String
readonly
The name of the database.
-
#size ⇒ Integer
readonly
The size constraint in bytes.
Class Method Summary collapse
-
.supported? ⇒ Boolean
Check if the browser supports WebSQL.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ SQL
constructor
Open a database with the given name and options.
-
#transaction {|transaction| ... } ⇒ Object
Start a transaction on the database.
- #version(from = nil, to = nil, &block) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ SQL
Open a database with the given name and options.
49 50 51 52 53 54 55 56 |
# File 'opal/browser/database/sql.rb', line 49 def initialize(name, = {}) @name = name @description = [:description] || name @version = [:version] || '' @size = [:size] || 2 * 1024 * 1024 super(`window.openDatabase(#{name}, #{@version}, #{@description}, #{@size})`) end |
Instance Attribute Details
#description ⇒ String (readonly)
Returns the description for the database.
36 37 38 |
# File 'opal/browser/database/sql.rb', line 36 def description @description end |
#name ⇒ String (readonly)
Returns the name of the database.
33 34 35 |
# File 'opal/browser/database/sql.rb', line 33 def name @name end |
#size ⇒ Integer (readonly)
Returns the size constraint in bytes.
39 40 41 |
# File 'opal/browser/database/sql.rb', line 39 def size @size end |
Class Method Details
Instance Method Details
#transaction {|transaction| ... } ⇒ Object
Start a transaction on the database.
82 83 84 85 86 |
# File 'opal/browser/database/sql.rb', line 82 def transaction(&block) raise ArgumentError, 'no block given' unless block `#@native.transaction(#{-> t { block.call(Transaction.new(self, t)) }})` end |
#version ⇒ String #version(from, to) {|transaction| ... } ⇒ Object
72 73 74 75 76 77 |
# File 'opal/browser/database/sql.rb', line 72 def version(from = nil, to = nil, &block) return `#@native.version` unless block `#@native.changeVersion(#{from}, #{to}, #{-> t { block.call(Transaction.new(self, t)) }})` end |