Class: Browser::Database::SQL
- Includes:
- Native::Wrapper
- 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.
48 49 50 51 52 53 54 55 |
# File 'opal/browser/database/sql.rb', line 48 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.
35 36 37 |
# File 'opal/browser/database/sql.rb', line 35 def description @description end |
#name ⇒ String (readonly)
Returns the name of the database.
32 33 34 |
# File 'opal/browser/database/sql.rb', line 32 def name @name end |
#size ⇒ Integer (readonly)
Returns the size constraint in bytes.
38 39 40 |
# File 'opal/browser/database/sql.rb', line 38 def size @size end |
Class Method Details
Instance Method Details
#transaction {|transaction| ... } ⇒ Object
Start a transaction on the database.
81 82 83 84 85 |
# File 'opal/browser/database/sql.rb', line 81 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
71 72 73 74 75 76 |
# File 'opal/browser/database/sql.rb', line 71 def version(from = nil, to = nil, &block) return `#@native.version` unless block `#@native.changeVersion(#{from}, #{to}, #{->(t) { block.call(Transaction.new(self, t)) }})` end |