My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members

MorphineDB is a database abstraction layer in Javascript for local storage with Google Gears, Adobe AIR and Firefox extension developer. Your application is exactly the same for all this ; write once, work everywhere. This project is just a start...

The aims of this project is to be as easy to use as possible :

  • relatively short to write, and 2 stylish syntax
  • adapter can be gears, AIR, FFExtension
  • simple method to define a table : tableName, primaryKeyName, arrayFields, arrayIndexes
  • primary key is auto-increment by default, with UUID key (36 char) in option
  • simple method to get row or rows
  • implement callback in insert, update, delete, truncate or drop
  • easy to join tables
  • fts2 implemented (very soon !!!), full text search for Gears (and next for Firefox)
  • only 1 file, only 10Ko minified

See User-end documentation to learn how to use this library.

See samples for Gears, Air and FF Extension

A little sample :

DB_Obj.connect({ adapter: "gears", auto_detect_adapter: false, database: "myDatabase" }) ;

// new DB_Table(<table_name>, <primary_key>, <array_of_fields_and_types>)
// create table if not exists
var contacts = new DB_Table("co_contacts", "co_id", ["co_name", "co_type INTEGER", "created DATE"]) ;

contacts.on("beforeInsert", function(tabProps, id) {
	tabProps.created = DB_Obj.formatDate(new Date()) ;
}

var newId = contacts.insert({ co_name: "Migliore", co_type: 1 }) ;

contacts.update_id({ co_name: "Miglior" }, newId) ;

contacts.replace_id({ co_name: "Bercot" }, 3) ;// insert or update (insert in this case)

var row3 = contacts.get_row_id(3) ; 
alert(row3.co_name+" "+new Date(row3.created)) ; // return "Bercot <current_date>"

var rows = contacts.execute_query_where("co_name like ? order by co_name","Mig%") ;
for (i=0 ; i<rows.length ; i++) {
	alert(rows[i].co_id) ;
}

contacts.drop() ;

A second stylish syntax :

var contacts = new DB_Table({
	name: "co_contacts", // table name
	auto_create: true, // auto create table to definition, default true
	primary: {
		name: "co_id", // primary name
		type: "TEXT", //  if TEXT then auto_increment create UID 36 chars
		auto_increment: true // by default to true
	},
	fields: [
		{
			name: "co_name", //field name
			type: "TEXT", // TEXT (default), NUMERIC, DATE, REAL are suffisant for SQLite !!
			indexed: true // field is indexed
		}, 
			"co_firstname", // use default fields
		{
			name: "co_type",
			type: "NUMERIC"
		}, {
			name: "created",
			type: "DATE",
			auto_date: true // if not specified in datas array, date is set automatically
		}
	],
	indexes: ["co_firstname"]
}) ;

var row1 = contacts.create_empty_row() ;
row1.co_name = "Miglior" ;
row1.co_firstname = "Michael" ;
row1.save() ; // insert

var row2 = contacts.get_row_id(1) ;
if (row2) {
	row2.co_firstname = "Jean-Michael" ;
	row2.save() ; // update
}

Powered by Google Project Hosting