HTML and CSS Reference
In-Depth Information
persistence.js
Supporting all major mobile browser platforms, persistence.js ( http://persistencejs.org )
is an asynchronous JavaScript object-relational mapper. It integrates with Node.js and
server-side MySQL databases and is recommended for server-side use, because using
in-memory data storage seems to slow down filtering and sorting. The download size
is much heavier than that of LawnChair.
For page setup, use:
<!DOCTYPE html>
<html>
<head>
<title> my app </title>
</head>
<body>
<script src= "persistence.js" type= "application/javascript" ></script>
<script src= "persistence.store.sql.js" type= "application/javascript" ></script>
<script src= "persistence.store.websql.js" type= "application/javascript" ></script>
</body>
</html>
if ( window . openDatabase ) {
persistence . store . websql . config ( persistence , "jquerymobile" , 'database' ,
5 * 1024 * 1024 );
} else {
persistence . store . memory . config ( persistence );
}
persistence . define ( 'Order' , {
shipping : "TEXT"
});
persistence . schemaSync ();
Similar to Hibernate (JBoss's persistence framework), persistence.js uses a tracking
mechanism to determine which objects changes have to be persisted to the database.
All objects retrieved from the database are automatically tracked for changes. New en‐
tities can be tracked and persisted using the persistence.add function:
var c = new Category ({ name : "Main category" });
persistence . add ( c );
All changes made to tracked objects can be flushed to the database by using persis
tence.flush , which takes a transaction object and callback function as arguments. You
can start a new transaction using persistence.transaction :
persistence . transaction ( function ( tx ) {
persistence . flush ( tx , function () {
alert ( 'Done flushing!' );
});
});
Search WWH ::




Custom Search