Click here to Skip to main content
15,867,704 members
Articles / Programming Languages / Javascript
Article

JavaScript Database Engine (JS-DBE)

Rate me:
Please Sign up or sign in to vote.
4.60/5 (4 votes)
12 Feb 2013CPOL4 min read 21.2K   477   12   1
This is a simple JavaScript database engine implementation

Introduction

This article is about the JavaScript database engine implementation. JS-DBE engine presented in this article supports relational database model and offer limited data processing features. Like in other database engines this engine works only with the tabular data representations (data arranged in arrays and columns).

Background

The relational JavaScript database engine can offer a significant improvements, considering the client-side performance, in generating the end-user reports. It minimizes the correspondence with the web-server. It also uses the pre-filtered data, exported in the plain textual XML file, on the web-server, from any available database system. It also offers the ability to format the processed data and automatically populate HTML page controls like tables and combo boxes.

JS-DBE engine structure (version 1.0)

There are two main objects inside the JS-DBE engine presented in this article: DataSet and DataTables.

Like in the modern programming languages (C# or Java) the DataSet object represents the collection of DataTables, and it is the core object. The DataSet object is used to asynchronously (or synchronously) load the exported XML file (the XML database file) from the web-server.

Here is how to use the DataSet object to load the data from the seb-server:

<script type="text/javascript">
    var ds = new DataSet("Test Database.xml", true, onLoadFinished);
    function onLoadFinished()
    {
        // do something here when the loading is finished
    }
}
</script>

The first argument of the DataSet constructor is the location (the URL) for the external XML file. The second one is the flag which determines how the AJAX call will be made (sync or async). The third argument is the callback method that the JS-DBE engine will call when the loading and parsing is finished (makes sence when using it with asynchronous AJAX call).

After the loading is complete, the Tables property of the DataSet object holds the collection of DataTables loaded. The DataTable, as said before, is the relational table exported from the database on the server.

All processing features and implemented inside the DataTable object. The DataTable object has general properties like: Name, Rows, Columns. It also has two special formatting properties, for table columns and rows: HeaderStyle and BodyStyle. You can pass any CSS-formatted string to this properties in order to have a nice-looking HTML table on the output.

Below are listed the supported operations for the DataTable object:

  • joinTable(table, primaryKey, foreignKey) - joins two DataTables and returns new DataTable object as the result
  • sortTable(columnName, direction) - sorts the original DataTable
  • groupTable(columnName) - groups the data inside the original DataTable by specified column
  • where(condition) - selects the part of the original DataTable that satisfy the condition and returns the new DataTable object as the result
  • select(columnNames) - selects the part of the original DataTable from list of the columns passed as argument and returns the new DataTable object as the result
  • sum(columnName) - calculates the SUM inside the original DataTable and returns the new DataTable object as the result
  • count(columnName) - calculates the COUNT inside the original DataTable and returns the new DataTable object as the result
  • min(columnName) - calculates the MIN inside the original DataTable and returns the new DataTable object as the result
  • max(columnName) - calculates the MAX inside the original DataTable and returns the new DataTable object as the result
  • avg(columnName) - calculates the AVG inside the original DataTable and returns the new DataTable object as the result
  • distinct(columnName) - selects the distinct part of the original DataTable by specified column and returns the new DataTable object as the result
  • updateTable(tableId) - fills the HTML table element on the web page with the items from the original DataTable object
  • updateComboBox(comboBoxId, columnName) - fills the HTML combo box element on the web page with the items, for the specified column, from the original DataTable object

This article includes the demo HTML page which shows all currently implemented features of the JS-DBE JavaScript database engine.

Also, please consult the included PDF document that covers the detailed specification considering the each feature of the JS-DBE engine.

XML database file structure (version 1.0)

Below is shown the structure of the XML database file that is exported on the web-server:

XML
<tables>
    <table>
        <DataTable1>
            <column1>data1</column1>
            <column2>data2</column2>
            <column3>data3</column3>
        </DataTable1>
        <DataTable1>
            <column1>data4</column1>
            <column2>data5</column2>
            <column3>data6</column3>
        </DataTable1>
        <DataTable1>
            <column1>data7</column1>
            <column2>data8</column2>
            <column3>data9</column3>
        </DataTable1>
    </table>
    <table>
        <DataTable2>
            <column1>data1</column1>
            <column2>data2</column2>
        </DataTable2>
        <DataTable2>
            <column1>data3</column1>
            <column2>data4</column2>
        </DataTable2>
        <DataTable2>
            <column1>data5</column1>
            <column2>data6</column2>
        </DataTable2>
    </table>
</tables>

This file structure should be followed in order to correctly import the XML file to JS-DBE engine.

Points of Interest

This is a pilot project on the research I am currently doing considering the client-side reporting using the plain JavaScript.

History

  • February, 2013. - JS-DBE JavaScript Database Engine Specification, version 1.0

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Elektromehanika d.o.o. Nis
Serbia Serbia
He has a master degree in Computer Science at Faculty of Electronics in Nis (Serbia), and works as a C++/C# application developer for Windows platforms since 2001. He likes traveling, reading and meeting new people and cultures.

Comments and Discussions

 
GeneralMy vote of 3 Pin
Prasyee13-Feb-13 2:11
Prasyee13-Feb-13 2:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.