dimanche 2 août 2015

better approach to access datatabase and creating models in cross platform apps

for example , i have been using following approach in my cross platform apps to accessing sqlite database as follows

To access database i have made a saperate .js for UserProfile table

function DBUserProfile() 
{
this.selectUserName = function(userId, callback) 
    {
        try 
        {
            //Get Data
            localDB.transaction(function selectUserProfileData(tx) 
            {
                var objDBDatabaseSchema = new DBDatabaseSchema();
                var sqlCommand = 'SELECT username FROM '
                                + objDBDatabaseSchema.UserProfileMetaData.USER_PROFILE_TABLE_NAME
                                +' WHERE engineer_id='
                                + '="' + userId + '"';

                objDBDatabaseSchema = null;

                tx.executeSql(sqlCommand,[],function selectUserNameResult(tx, results) 
                {
                        if (results.rows.length > 0 ) 
                        {
                            var userId = results.rows.item(0).username ;
                            callback(userId);
                        }
                        else 
                        {
                            var userId = "";
                            callback(userId);
                        }


                }, errorDB);
            }, errorDB);
        } 
        catch (e) 
        {
            // TODO: handle exception
            console.log("DBUserProfile - selectUserName " + e);
        }
    };

} 

and this is how i use them in a pages

    var objDBUserProfile = new DBUserProfile();
    objDBUserProfile.selectUserName("3443" , function(id){

        //

   });

but the above approach is pretty time consuming i have been end up creating lot of models and db files to access tables and lot of new objects , so does anyone has a better approach in jquery to cut down the development time. any suggestions are welcome

Aucun commentaire:

Enregistrer un commentaire