Created
August 8, 2018 14:07
-
-
Save hansemannn/54f24dad214e67d19f0e5934e9f304b1 to your computer and use it in GitHub Desktop.
Use the SQLite JSON1-extension in Appcelerator Titanium.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dbobj = require('appcelerator.encrypteddatabase'); | |
var win = Ti.UI.createWindow({ backgroundColor: 'white' }); | |
var btn = Ti.UI.createButton({ title: 'Trigger' }); | |
btn.addEventListener('click', accessDatabase); | |
win.add(btn); | |
win.open(); | |
function accessDatabase() { | |
dbobj.setPassword('secret'); | |
Ti.API.info('Opening DB ...'); | |
const instance = dbobj.open('test.db'); | |
instance.execute('CREATE TABLE IF NOT EXISTS user(name string, phone string);'); | |
instance.execute('insert into user (name, phone) values("oz", json(\'{"cell":"+491765", "home":"+498973"}\'));'); | |
const dataToInsertHandle = instance.execute('select user.phone from user where user.name==\'oz\''); | |
const result = dataToInsertHandle.isValidRow() ? dataToInsertHandle.fieldByName('phone') : null; | |
alert('Fetched data: ' + result); | |
Ti.API.info('Closing DB ...'); | |
instance.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment