[ALOY-345] Load pre-existing SQLite DBs with sql adapter
| GitHub Issue | n/a |
|---|---|
| Type | Improvement |
| Priority | Medium |
| Status | Resolved |
| Resolution | Fixed |
| Resolution Date | 2013-01-09T17:01:19.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Alloy 0.3.5, 2013 Sprint 02 |
| Components | Runtime |
| Labels | notable |
| Reporter | Tony Lukasavage |
| Assignee | Unknown |
| Created | 2012-10-25T17:12:57.000+0000 |
| Updated | 2018-03-07T22:26:06.000+0000 |
Description
see conversation here: https://groups.google.com/forum/?fromgroups=#!topic/appc-ti-alloy/1q1e36mT6f0
Developers should be able to preload sqlite databases with the sql adapter models. To do so, they can add the new "db_file" field with the location of their db file. In addition, you can also explicitly name the database with the "db_name" field. This allows developers to continue to access a named, pre-loaded database even if they remove the "db_file" field:
examples
// standard sql model using default _alloy_ db to create
// table "fighters" based on config.columns
exports.definition = {
config: {
"columns": {
"name":"text",
"nickname":"text"
},
"adapter": {
"type": "sql",
"collection_name": "fighters"
}
}
}
// sql model using specified customDb db to create
// table "fighters" based on config.columns. customDb
// can be referencing an existing db or creating a new one.
// This allows for multiple sqlite dbs in an Alloy app.
exports.definition = {
config: {
"columns": {
"name":"text",
"nickname":"text"
},
"adapter": {
"type": "sql",
"collection_name": "fighters",
"db_name": "customDb"
}
}
}
// load myapp.sqlite db file if myapp db does not exist, auto-populate
// config.columns based on pragma table_info("fighters"), which lists
// table info regarding the fighters table
exports.definition = {
config: {
"adapter": {
"type": "sql",
"db_file": "/sql_preload.sqlite",
"collection_name": "fighters"
}
}
}
pre-loaded databases supported as per the ticket description. An example can be found at: https://github.com/appcelerator/alloy/tree/master/test/apps/models/sql_preload