The Database class provides methods for working with HTML 5 SQLite databases in Palm's WebOS. It offers versions for both Enyo and Mojo (Enyo version is a Component, Mojo version a Prototype class).
To use the class, download either database-mojo.js or database-enyo.js and put it somewhere in your app (I usually use a top-level javascripts folder for this kind of generic script).
Add a reference to the file in your appropriate depends.js file:
enyo.depends(
"javascripts/database-enyo.js"
);
And then in your kind add the onecrayon.Database kind to your components:
components: [
{
name: "db",
kind: "onecrayon.Database",
database: 'ext:MyDatabase',
version: "",
debug: false
}
]
After your create
method has been called, you will then be able to access
the database methods using this.$.db
(in this case; may be different if you
named it differently). So for instance:
this.$.db.setSchemaFromURL('schemas/schema.json', {
onSuccess: enyo.bind(this, this.finishFirstRun)
});
Add the following line to your sources.json
file:
{"source": "javascripts/database.js"}
And then in any of your assistants or other Javascript files you should be able to instantiate the class like so:
var db = new Database('ext:my_database', {version: '1', estimatedSize: 1048576});
Currently all documentation for the class is inline in the source code.
In particular, you should read the comments for setSchema
, query
,
and queries
as these are the main methods you will need in everyday usage.
- Rewritten from the ground up for Enyo
The Database class is developed for and used by TapNote.
Let me know if you are using it, and I will note it here.
Copyright (c) 2010 Ian Beck
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.