• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Working with Data and Titanium
 

Working with Data and Titanium

on

  • 379 views

Slides from Pratik Patel from the February 2014, London Titanium Meetup.

Slides from Pratik Patel from the February 2014, London Titanium Meetup.

Statistics

Views

Total Views
379
Views on SlideShare
372
Embed Views
7

Actions

Likes
0
Downloads
3
Comments
0

1 Embed 7

http://www.slideee.com 7

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Working with Data and Titanium Working with Data and Titanium Presentation Transcript

    • Working with Data in Titanium Presentation by: PRATIK PATEL | CTO | TripLingo Labs | @prpatel PRATIK@mypatelspace.com
    • @prpatel @TripLingo
    • TOPICS • working with data • Strategies: SQL & NOSQL • architecture • synchronization PRATIK PATEL | CTO
    • TRANSFORMING DATA PRATIK PATEL | CTO
    • can be frustrating PRATIK PATEL | CTO
    • Use the FUNC, Luke • functional programming in • break down the problem • json is very flexible JavaScript PRATIK PATEL | CTO
    • take 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 dan gerous, but feel like the whole prototypical language thing is still a mys tery. In this session, we'll go from basic JavaScript to advanced JavaScri pt. We'll discuss and code modular JavaScript with CommonJS. We'll look in to the details of a prototype language and discuss things like parasitic i nheritance. 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 spee d with the latest and greatest JavaScript techniques and tools. Whether yo u're building client side JavaScript with HTML5 or Appcelerator Titanium,  or serverside 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"    } make this PRATIK PATEL | CTO
    • underscore.js • use it • master it • think functional PRATIK PATEL | CTO
    • 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
    • flatten •Flattens a nested array (the nesting can be to any depth) PRATIK PATEL | CTO
    • sortBy • sorts (duh!) • can sort arrays and even an array of objects! PRATIK PATEL | CTO
    • live coding
    • SQLite & NoSQL
    • SQLite • Embedded sql-92 compliant db • file based • fast(!) PRATIK PATEL | CTO
    • sqlite var  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
    • SQLite • Pre-bundling data • fast! • structured data PRATIK PATEL | CTO
    • NOSQL OPTIONS • SCuleJS - like mongodb • MongloDB • plain json as we saw! PRATIK PATEL | CTO
    • PLAIN JSON • can get alot of mileage out of this • small = store using Ti.App.Properties! • big = store in a file PRATIK PATEL | CTO
    • SCULEJS / MongloDB • Mongodb-like • relationships • advanced queries PRATIK PATEL | CTO
    • 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
    • now the boring stuff PRATIK PATEL | CTO
    • SYNCHRONIZATION PRATIK PATEL | CTO
    • PLAIN JSON + REST • Standard REST endpoints • You manage the sync yourself PRATIK PATEL | CTO
    • 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
    • ARCHITECTURAL CONSIDERATIONS PRATIK PATEL | CTO
    • PERFORMANCE • Large datasets - handle with care • “cache” operations if possible PRATIK PATEL | CTO
    • PERFORMANCE • SQLite is native code = queries fast • data extraction = expensive PRATIK PATEL | CTO
    • PERFORMANCE • JSON queries slow (non-indexed iteration) • data extraction cost is ZERO • SculeJS has indexed find ops PRATIK PATEL | CTO
    • NETWORK • Know what your users are running on - 3G? - Wireless? PRATIK PATEL | CTO
    • NETWORK • Speed over 3G networks is usually good • LATENCY is the killer! • Each request => 150-500ms latency PRATIK PATEL | CTO
    • LOCAL STORAGE • SQLite = File • JSON can use Ti.App.Properties • Props get loaded into MEMORY • Not GC-able PRATIK PATEL | CTO
    • WHAT ABOUT ALLOY? PRATIK PATEL | CTO
    • i’m glad you asked PRATIK PATEL | CTO
    • ALLOY + DATA • Alloy uses Backbone models • Backbone uses…. PRATIK PATEL | CTO
    • UNDERSCORE! PRATIK PATEL | CTO
    • ALLOY + UNDERSCORE • The code demo shown earlier just works with ALLOY: • collection.map • collection.sortBy PRATIK PATEL | CTO
    • ALLOY + SYNC • Alloy uses Backbone models • Backbone adapters • Titanium specific adapters PRATIK PATEL | CTO
    • AU REVOIR PRATIK PATEL @PRPATEL PRATIK@mypatelspace.com