Store data to SQLite in AngularJS PhoneGap

When you work with a phonegap application, sometimes you need develop a work-offline mode for your app. In this case, SQLite is  a good choice. You can use SQLite to store data you loaded from server-side. If your device lost internet connection, application will load data from SQLite firstly.

Store data to SQLite in AngularJS PhoneGap

Common sense is not a gift, It’s a punishment. Because you have to deal with everyone who doesn’t have it.

To implement, you need install SQLite phonegap plugin for your app. And then, you write a service to handle get/set/remove data in SQLite. And now, I will show you a script that run in my app that uses angularjs, coffee script.

The below is coffee script that implement a factory to get/set/remove cache to SQLite

And DbCache factory should be injected to factories used to load data.  The below is my way:

– Load from SQLite cache firstly

– If Cache is empty,  use $http to load data from server-side

Code example:

 

Writing shell script to deploy changed file via ftp

When you work with a cheap host, you just have FTP account to push your file to host. It will be terrible if you have to pull all changed file to host via FTP. Because you must answer many stupid question as “what files I was change?”, “Where files I was change?”, “What is ftp account?” …

0284ed8e-26be-11e4-a4aa-12313d044945-medium

So I think that it is better if you write a script to handle all task and help you answer all question. The way is posted the below will run well in linux environment.

Firstly, we need a script to upload file via FTP.  The script below requires CURL. You just need to change value of REMOTE_HOST, REMOTE_USER, REMOTE_PASSWD. It will work well.

After that, you write a script to list all file that needs to push to your FTP host. That script is similar to the script below.

With the script above, you need to provide 2 tag name, and script will check all file changes between them.  Finally, It calls fpt.sh script to push that files to FTP host.

You can see full source code in my Github: https://github.com/thanhson1085/git2ftp