Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (android)
Viewing all articles
Browse latest Browse all 7655

Alloy , create model and save to sqlite Db

$
0
0

Hello, I want to know where is my data saved(what is DBs name or tables name) when I create model and save it to collection.

This is my model routeList.js:

exports.definition = {
    config: {
        columns: {
            "id": "INTEGER PRIMARY KEY AUTOINCREMENT",
            "name": "string",
            "status": "int"
        },
        adapter: {
            type: "sql",
            collection_name: "routeList",
            idAttribute: "id"
        }
    },
    extendModel: function(Model) {
        _.extend(Model.prototype, {
            // extended functions and properties go here
        });
 
        return Model;
    },
    extendCollection: function(Collection) {
        _.extend(Collection.prototype, {
            // extended functions and properties go here
        });
 
        return Collection;
    }
};
alloy.js
Alloy.Collections.routeList = Alloy.createCollection("routeList");
view:
<TableView id="routeListTable" dataCollection="routeList">
            <TableViewRow id="routeListTableRow" dataId="" model="{alloy_id}">
                <View id="rowContainer" hasChild ="true">
                    <Label class="routeListRowName" text="{name}" >
                </View>
            </TableViewRow>
        </TableView>
and on button click I read json file and path data to my model, add model to collection and save it to sqlite db:
function fillRouteList(){
 
    var file = Ti.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'Routes.txt');
    var data = file.read().text;
    var response = JSON.parse(data);
 
    var routes = Alloy.Collections.routeList;
 
    if(routes.length==0) {
         for(var i =0;i<response.count;i++){
            var route = Alloy.createModel("routeList", response.path[i]);
            routes.add(route);
            route.save(route);
            routes.fetch();
        }
    }else{
        alert("??? ???? ?????????????");
    }
}
So this works; and I can see data in tableview.

But I want to know where is this data saved? how can I select this data? what is DBs or Tables name?

Please answer , thanks


Viewing all articles
Browse latest Browse all 7655

Trending Articles