Uploaded image for project: 'Alloy'
  1. Alloy
  2. ALOY-345

Load pre-existing SQLite DBs with sql adapter

    Details

      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"
      		}
      	}
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                tlukasavage Tony Lukasavage
              • Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Integration