Using Parse to Save Your Stuff

By Raymond Camden / @cfjedimaster

About Me

Fabio
  • Invented the Internet
  • Poop Kittens
  • Working on HTML7
  • I can divide by 0

Storing Stuff

  • 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

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);
					

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!
	}
});

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);

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();

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) {
	}
});

					

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