jsormdb--an Embedded JavaScript Database
The jsormdb library introduces several concepts and implementations that are necessary for creating and using a database. Note that all of these are detailed in the JavaScriptDoc distributed with jsormdb, in the doc folder.
The database: this class is JSORM.db.db(), and it represents a single database instance.
The parser: responsible for taking input data and transforming it into records that are stored in an instance of JSORM.db.db or taking entries in a jsormdb database and transforming them into an acceptable output format. For example, the data you load into the library may be in JSON, XML, JavaScript objects or even Pig Latin. jsormdb does not care, provided you provide a parser that can convert between your preferred encoding and an array of native JavaScript objects. jsormdb comes with a parser for JSON and Objects; an XML parser is being developed.
The channel: responsible for loading data from or saving data to a remote data store. An HTTP channel can use AJAX to retrieve data from and post data to the server from which the Web page itself was loaded. You also can use another jsormdb as a source for your database, but a channel for that is unnecessary.
Putting it all together, you can create a database instance JSORM.db.db that retrieves data via HTTP from your server using JSORM.db.channel.http and parses it in JSON format using JSORM.db.parser.json. Figure 3 shows how all the pieces work together.
It is important to note that all classes follow Douglas Crockford's principles and are instantiated directly, without the “new” keyword:
var parser = JSORM.db.parser.json(); // right var parser = new JSORM.db.parser.json(); // WRONG!
As much as possible, jsormdb semantics follow those of classical SQL. Thus, adding records is an insert; modifying records is an update, and so forth.
Installing jsormdb involves a few simple steps.
1) Download and unzip the library from the jsorm site, where it is available as a zip file from the Download link.
2) Install the library. The download includes two versions of the library. jsormdb.js is minified at just under 25KB. jsormdb-src.js is not minified, is used primarily for debugging and is 77KB. You can reduce their sizes further with gzip. You need to install the library you want to use in a path accessible to your browsers. For the purposes of this example, install file jsormdb.js in the same directory as your Web page.
3) Include the library in your Web page. Normally this is done in the header as follows:
<script type="text/javascript" src="jsormdb.js"></script>
Now that you have downloaded and installed the library, as well as included it in your page, you are ready to create a database.
In the simplest form, you create a database by simply instantiating it:
var db = JSORM.db.db();
Although this creates a database, you may want to add some initial configuration parameters. For example, you may want to indicate the parser and/or the channel to use, or even to load some data directly.
jsormdb supports loading data in two ways: directly, using raw data, and remotely, via a channel:
var conf, db;
// to use a channel and parser
conf = {
channel: JSORM.db.channel.http({updateUrl: "/send/text.php",
loadUrl: "/receive/text.json"}),
parser: JSORM.db.parser.json()
}
db = JSORM.db.db(conf);
// to load data directly
conf = {data: [{name: "Joe", age: 25},
{name: "Jill", age: 30},
{name: "James", age: 35}]}
db = JSORM.db.db(conf);
JSORM.db.db has many options for instantiation. See the API docs or the Wiki entry, both of which are listed in the Resources for this article.
Whichever manner you choose to load data, jsormdb expects the data passed to it to be an array of simple JavaScript object literals. jsormdb is not rigid about the data structure, and it does not care what fields exist on each object. Both of the following are equally valid:
data = [{name: "Joe", age: 25},
{name: "Jill", age: 30},
{name: "James", age: 35}];
data = [{name: "Joe", age: 25},
{firstName: "Jill"},
{surname: "James", city: "London"}];
An important note about the records is that each can have a type. When a record has a type, it is specially marked and can be searched more easily along with others of the same type. This can improve search times greatly, akin to putting records in different tables in an RDBMS:
data = [
{name: "Joe", age: 25, type: "person"},
{name: "Jill", age: 30, type: "person"},
{name: "James", age: 35, type: "person"},
{name: "Fiat", color: "yellow", type: "car"},
{name: "Ferrari", color: "red", type: "car"},
{name: "GM", color: "white", type: "car",
status: "bankrupt"}
];
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
Web Development News
Developer Poll
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- New Products
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)









2 min 12 sec ago
4 hours 33 min ago
4 hours 34 min ago
6 hours 34 min ago
15 hours 19 min ago
15 hours 54 min ago
16 hours 52 min ago
17 hours 42 min ago
21 hours 44 min ago
1 day 1 hour ago