Using Parse to Save Your Stuff

By Raymond Camden / @cfjedimaster

Who am I?

  • Raymond Camden
  • Creative Cloud Evangelist for Adobe
  • Web Standards, HTML5, JavaScript, ColdFusion
  • Blogging at raymondcamden.com
  • @cfjedimaster
ray

Storing Stuff with PhoneGap

  • LocalStorage
  • Database
  • FileSystem (so easy!)


Only exist on the device!

Parse logo
  • Cloud-based service (with free + paid tiers)
  • Data storage
  • Site hosting
  • APIs for iOS, Android, Windows 8, Windows Phone 8, OSX, and JavScript!
  • REST-based API (integration with other servers)

Basics

  • Sign up at Parse.com
  • Create an Application at Parse.com
  • Copy one JavaScript file
  • Copy Application and JavaScript keys
  • Write code

Demo

What You Can Code

  • CRUD for simple data
  • Query + Collections
  • File storage
  • Geopoints
  • Users
  • Cloud Functions (think server-side JS)
  • Push notifications

Initialize Parse


Parse.initialize("app ID", "js ID");
					

Make Something



Parse.initialize("app ID", "js ID");
var BeerObject = Parse.Object.extend("BeerObject");

var beer = new BeerObject();
beer.set("name","FooBeer");
beer.set("brewer","Me, Myself, and I");
beer.set("abv",9.2);
					

Demo

/demos/p1/test.html

Save Something


Parse.initialize("app ID", "js ID");
var BeerObject = Parse.Object.extend("BeerObject");

var beer = new BeerObject();
beer.set("name","FooBeer");
beer.set("brewer","Me, Myself, and I");
beer.set("abv",9.2);

beer.save(null, {
	success:function(ob) {
		//do something
	},
	error:function(ob, err) {
		//oh no! woe is me!
	}
});

Demo

/demos/p1/test2.html

Get Something


Parse.initialize("app ID", "js ID");
var BeerObject = Parse.Object.extend("BeerObject");

var q = new Parse.Query(BeerObject);
q.get("someid", {
	success:function(ob) {
		console.log("I got beer "+ ob.get("name"));
	},
	error:function(ob, err) {
		//oh no! woe is me!
	}
});

Deleting Something



//Assume b is a beer object we got...
//NOW DESTROY IT! MUHAHAHAHAH!

b.destroy({
	success:function(ob) {

	},
	error:function(ob, err) {

	}
});

Relations (One to One, One to Many)


var BeerObject = Parse.Object.extend("BeerObject");
var BreweryObject = Parse.Object.extend("Brewery");

var b = new BeerObject();
b.set("name","Epic Beer of Epicnesss");

var brewery = new BreweryObject();
brewery.set("name","Uncle Joe");

b.set("brewer", brewery);

Demo

/demos/p1/test3.html

Relations (Many to Many)


var BeerObject = Parse.Object.extend("BeerObject");
var TagObject = Parse.Object.extend("Tag");

var b = new BeerObject();
b.set("name","Epic Beer of Epicnesss");

var t = new TagObject();
t.set("name","Bitter");
var t2 = new TagObject();
t2.set("name","Smelly");

var relation = b.relation("tags");
releation.add([t, t2]);

b.save();

Demo

/demos/p1/test4.html

Queries

  • Built with constraints (equal to, not equal to, greater than, less than, contained in, not contained in, property exists, starts with)
  • Limits and Starting indexes
  • Sorting
  • Just a count
  • Multiple queries at once (OR)

Query Example


var BeerObject = Parse.Object.extend("BeerObject");
//query ob based on type
var query = new Parse.Query(BeerObject);

//add a constraint
query.greaterThan("abv", 10);

//do it
query.find({
	success:function(results) {
		//array of beer - that sounds awesome
	},
	error:function(err) {
	}
});

					

Demo

/demos/p1/test5.html

Special Data Types - Geopoints

  • Record longitude and latitude
  • Search within a radius (miles, kilometers, radians)
  • Search within a box (SW and NE)

Demo

/demos/p1/test6.html

Special Data Types - Users

  • username + password required, email options (you can add additional stuff)
  • Parse provides a signUp method (checks username,password and hashes password)
  • Parse provides a login method - stores a user locally (logout too)
  • Parse can do email verification
  • Parse can do password resets

A Brief Note on Parse and Security

Objects can be set such that only a user can look at them. You can also explicitly set read and write permissions for data.

Parse also supports Roles to help aggregate this at a higher level.

Admin Console

  • Let's you track usage
  • Let's you CRUD data
  • Settings (including good lockdown stuff)
dash
dash

Parse & PhoneGap

Chocolate peanut butter mower

Demo!

More Info!

  • Docs (https://parse.com/docs/js_guide)
  • Demos (raymondcamden.com, search for parse)
Adobe logo