+ All Categories
Home > Technology > Working with Data and Titanium

Working with Data and Titanium

Date post: 30-Jun-2015
Category:
Upload: londontitanium
View: 1,242 times
Download: 1 times
Share this document with a friend
Description:
Slides from Pratik Patel from the February 2014, London Titanium Meetup.
39
in Titanium Working with Data Presentation by: PRATIK PATEL | CTO | TripLingo Labs | @prpatel [email protected]
Transcript
Page 1: Working with Data and Titanium

in Titanium Working with Data

Presentation by: PRATIK PATEL | CTO | TripLingo Labs | @prpatel [email protected]

Page 2: Working with Data and Titanium

@prpatel @TripLingo

Page 3: Working with Data and Titanium

TOPICS• working with data

• Strategies: SQL & NOSQL

• architecture

• synchronization

PRATIK PATEL | CTO

Page 4: Working with Data and Titanium

TRANSFORMING DATA

PRATIK PATEL | CTO

Page 5: Working with Data and Titanium

PRATIK PATEL | CTO

can be frustrating

Page 6: Working with Data and Titanium

Use the FUNC, Luke• functional programming in JavaScript

• break down the problem

• json is very flexible

PRATIK PATEL | CTO

Page 7: Working with Data and Titanium

PRATIK PATEL | CTO

take this

make this

[{       "id":30445,       "speakerNames":"Pratik Patel",       "smallImageSq":"/s/images/bio/14890_Patel_20110408_052535_small_sq.jpg",       "mediumImageSq":"/s/images/bio/14890_Patel_20110408_052535_medium_sq.jpg",       "roomId":1554,       "ordinal":2,       "showId":327,       "slotId":7956,       "featured":true,       "modified":"2013-12-17T21:19:05",       "topicId":3193,       "eventId":null,       "title":"Advanced JavaScript for Java Devs",       "summary":"So you think you've picked up enough JavaScript to be dangerous, but feel like the whole prototypical language thing is still a mystery. In this session, we'll go from basic JavaScript to advanced JavaScript. We'll discuss and code modular JavaScript with CommonJS. We'll look into the details of a prototype language and discuss things like parasitic inheritance. We'll also look at JavaScript libraries that will help you get the most out of JavaScript - not jQuery, but a library like UnderscoreJS and SugarJS.",       "detail":"This is a fast paced session meant to bring you up to speed with the latest and greatest JavaScript techniques and tools. Whether you're building client side JavaScript with HTML5 or Appcelerator Titanium, or server-side JavaScript with node.js, you'll come away with knowledge and patterns for how the pro's use JavaScript for building real apps.",       "prerequisite":null,       "workshopRequirements":null,       "endTime":"2014-03-07T14:45:00",       "startTime":"2014-03-07T13:15:00",       "speakerIds":[          14890       ],       "missingSlides":false,       "dayNumber":0,       "startTimeString":"Fri 01:15 PM",       "roomName":"Room 2"    }

Page 8: Working with Data and Titanium

underscore.js• use it

• master it

• think functional

PRATIK PATEL | CTO

Page 9: Working with Data and Titanium

map • map is the name of a higher-order function that applies a given function to each element of a list, returning a list of results

• like doing a transformation

PRATIK PATEL | CTO

Page 10: Working with Data and Titanium

flatten •Flattens a nested array (the nesting can be to any depth)

PRATIK PATEL | CTO

Page 11: Working with Data and Titanium

sortBy • sorts (duh!)

• can sort arrays and even an array of objects!

PRATIK PATEL | CTO

Page 12: Working with Data and Titanium
Page 13: Working with Data and Titanium

live coding

Page 14: Working with Data and Titanium

SQLite &

NoSQL

PRA

Page 15: Working with Data and Titanium

SQLite• Embedded sql-92 compliant db

• file based

• fast(!)

PRATIK PATEL | CTO

Page 16: Working with Data and Titanium

sqlitevar  db  =  Titanium.Database.open('mydb');  !db.execute('CREATE  TABLE  IF  NOT  EXISTS  DATABASETEST    (ID  INTEGER,  NAME  TEXT)');  db.execute('DELETE  FROM  DATABASETEST');  !db.execute('INSERT  INTO  DATABASETEST  (ID,  NAME  )  VALUES(?,?)',1,'Name  1');  db.execute('UPDATE  DATABASETEST  SET  NAME  =  ?  WHERE  ID  =  ?',  updateName,  updateId);  var  rows  =  db.execute('SELECT  *  FROM  DATABASETEST');  !while  (rows.isValidRow())  {     Titanium.API.info('ID:  '  +  rows.field(0)  +  '  NAME:  '  +          rows.fieldByName('name')  +  '  COLUMN  NAME  '  +  rows.fieldName(0));     rows.next();  }

PRATIK PATEL | CTO

Page 17: Working with Data and Titanium

SQLite• Pre-bundling data

• fast!

• structured data

PRATIK PATEL | CTO

Page 18: Working with Data and Titanium

NOSQL OPTIONS• SCuleJS - like mongodb

• MongloDB

• plain json as we saw!

PRATIK PATEL | CTO

Page 19: Working with Data and Titanium

PLAIN JSON• can get alot of mileage out of this

• small = store using Ti.App.Properties!

• big = store in a file

PRATIK PATEL | CTO

Page 20: Working with Data and Titanium

SCULEJS / MongloDB• Mongodb-like

• relationships

• advanced queries

PRATIK PATEL | CTO

Page 21: Working with Data and Titanium

SculeJS

var scollection = scule.factoryCollection('scule+dummy://test', {secret:’mysecretkey'});!scollection.save({ name : ‘pratik', session : 'javascript'}, { name : ‘ket', session : 'design'});!scollection.find({$within:{name:’pratik’}}, {$limit:10, $sort:{name:-1}}, function(results) { // do something with results here});

PRATIK PATEL | CTO

Page 22: Working with Data and Titanium

PRATIK PATEL | CTO

now the boring stuff

Page 23: Working with Data and Titanium

SYNCHRONIZATION

PRATIK PATEL | CTO

Page 24: Working with Data and Titanium

PLAIN JSON + REST• Standard REST endpoints

• You manage the sync yourself

PRATIK PATEL | CTO

Page 25: Working with Data and Titanium

SQLite• You manage the sync yourself

• Manual conversion to/from SQL

• ORM’s for Titanium

• BUT: why not send the actual SQLite file over the wire???

PRATIK PATEL | CTO

Page 26: Working with Data and Titanium

ARCHITECTURAL CONSIDERATIONS

PRATIK PATEL | CTO

Page 27: Working with Data and Titanium

PERFORMANCE• Large datasets - handle with care

• “cache” operations if possible

PRATIK PATEL | CTO

Page 28: Working with Data and Titanium

PERFORMANCE• SQLite is native code = queries fast

• data extraction = expensive

PRATIK PATEL | CTO

Page 29: Working with Data and Titanium

PERFORMANCE• JSON queries slow (non-indexed iteration)

• data extraction cost is ZERO

• SculeJS has indexed find ops

PRATIK PATEL | CTO

Page 30: Working with Data and Titanium

NETWORK• Know what your users are running on - 3G? - Wireless?

PRATIK PATEL | CTO

Page 31: Working with Data and Titanium

NETWORK• Speed over 3G networks is usually good

• LATENCY is the killer!

• Each request => 150-500ms latency

PRATIK PATEL | CTO

Page 32: Working with Data and Titanium

LOCAL STORAGE• SQLite = File

• JSON can use Ti.App.Properties

• Props get loaded into MEMORY

• Not GC-able

PRATIK PATEL | CTO

Page 33: Working with Data and Titanium

WHAT ABOUT ALLOY?

PRATIK PATEL | CTO

Page 34: Working with Data and Titanium

PRATIK PATEL | CTO

i’m glad you asked

Page 35: Working with Data and Titanium

ALLOY + DATA• Alloy uses Backbone models

• Backbone uses….

PRATIK PATEL | CTO

Page 36: Working with Data and Titanium

UNDERSCORE!

PRATIK PATEL | CTO

Page 37: Working with Data and Titanium

ALLOY + UNDERSCORE• The code demo shown earlier just works with ALLOY:

• collection.map

• collection.sortBy

PRATIK PATEL | CTO

Page 38: Working with Data and Titanium

ALLOY + SYNC• Alloy uses Backbone models

• Backbone adapters

• Titanium specific adapters

PRATIK PATEL | CTO

Page 39: Working with Data and Titanium

AU REVOIRPRATIK PATEL

@PRPATEL [email protected]


Recommended