Breaking change

Type definitions for DB transaction event has changed starting from V1.0.5

Use the jdb.IDBCoreEvent for type registry, see examples below.

Upcoming changes

  • Nothing for now.

# jdb(DB_NAME, DB_VERSION)

  • Arguments

    • {string} DB_NAME (required)
    • {Number} DB_VERSION
  • Return

    {object} jDB Instance

  • Usage

  • # isClient()

    • Details

      Initialize isClient() method to set the env to production. default: dev

  • # requiresLogin()

    • Details

      Initialize requiresLogin() method to set the login flag for a database. default: false

  • # open([definition])

    • Arguments

      • {object} definition
    • return: jDB Open Instance

      • Instances:
      • onCreate(CB) createMode Triggers when creating the DB for the first time.

      • onUpgrade(CB) createMode|upgradeMode Triggers when creating the DB and also when DB upgrades.

      • onSuccess(CB) JDB Promise instance

      • onError(CB) JDB Promise instance

      • then(success, error) JDB Promise instance

    • Details

      Definition

      • Storage types: [localstorage, sessionstorage, memory] (in-built)

        Other storage types are sql(sqlite, websql), indexedDB and flatfile which requires jdb adapter to perform.

      • location{String}
      • key{String}
      • folderPath{String}
      • schemaPath {String} (Available in V1.1.0)

        Path to your schemaFolder.

      • useFrontendOnlySchema {Boolean} (Available in V1.1.0)

        Only set to true if you re using Frontendonly storage service.

      • live:{boolean} (default:false)

        Set to true for autoSyncService to always sync client changes to server.

      • isClientMode:{boolean} (default:false)

        Equivalent to isClient()

      • isLoginRequired:{boolean} (default:false)

        Equivalent to isLoginRequired()

      • serviceHost{String}

        Define the URL of your server, by default is null

        Don't have a server? Frontendonly is available for free.

      • disableApiLoading {Boolean}

        Set to false to stop JDB from loading all configured API from the server.

      • ignoreSync {Boolean|Array }

        Set to true to disable auto syncing or use array to list tables to disable.

      • ajax{Function}

        Define Ajax method to be used within JDB for transporting data to server

      • interceptor{Function}

        This method is trigger before actuall call to server are made.

      • organisation {String} required

        Define your organisation name, this is used within jdb-frontendonly

      • conflictResolver{Function}

        This function is only initialized when there is a conflict between server and client records.

        Parameter: serverData, clientData

        Only define a function if you don't want jdbSyncService to resolve the conflict.

      • logService{Function}

        Define a function that can register all logs thrown from the syncService.

        Parameter: message

      • handler

        • onSuccess

          Define a function that will perform an action when sync is successfull

        • onError

          Define a function that will perform an action when sync fails.

      Note : onCreate() is called when creating the database for the first time while onUpgrade() function is called when the version number of the DB changes.

# SchemaManager (Available in V1.1.0)

  • This feature is introduced for managing database schemas and versioning.

    Schema filename should be in this format "version_VERSION NUMBER" e.g version_1.json

    These are operations accepted in a schema file: DROP | RENAME | ALTER | TRUNCATE | CREATE | CRUD(insert|update|delete|batch|insertreplace)

    Below are examples of different operations that can be performed with schemaManager.

    In CRUD Insert or Update operations, if filePath and data are defined filePath will be used instead of data, so choose which is best for your requirement.

  • Below are examples of different schema definition.

CREATE and CRUD operation are standalone and cannot be included with other operations.

# DB.ENV

  • DB.env.usage()

    returns the DB usage

  • DB.env.apiKey()

    returns the DB API key: {OBJECT}

    This is available only when using JDB server (https://frontendonly.com).

  • DB.env.dataTypes()

    returns all supported dataTypes in JDB

    You can also remove or add custom dataTypes, but i bet you won't be needing this.

# DB.createTbl(name, schema)

  • Arguments

    • {string} name (required)
    • {Array} schema
    • Schema Definition

      • {JDB_DATATYPES} type required
      • {boolean} AUTO_INCREMENT (optional)
      • {string} ON_UPDATE Allowed Types: DATE | CURRENT_TIMESTAMP | DATE_TIME | USER DEFINED (optional)
      • {string} defaultValue Allowed Types: DATE | CURRENT_TIMESTAMP | DATE_TIME | USER DEFINED (optional)
      • {boolean} PRIMARY_KEY (optional)
      • {boolean} NOT_NULL introduced in v1.0.7-beta (optional)
  • Return

    jDB Promise Instance

  • Usage

  • Arguments

    • {string | ARRAY} TBL_NAME (required)
    • {string} MODE
  • Return

    jDB Promise Instance

    • Usage

      • # drop(columnName)

        Drop column from current table

      • # add(type)

        Types: [mode, key, index, column]

        return {function} type instance

        Instance

        • # key(type, tableName)

          Types: [primary, foreign]

          TableName: required only for adding foreign key

        • # column(columnName,config)

          columnName: {string}

          config: {Object}

        • # index(columnName,settings)

          columnName: {string}

          settings: {Object}

        • # mode(mode)

          mode: {string} [readonly, writeonly]

    • Arguments

      • {string} flag (YES | NO)
    • Details

      Flag must be set to yes to empty the table.

      Note : NO flag will trigger an error. @DEFAULT : NO

    • Arguments

      • {string} flag (YES | NO)
    • Details

      Flag must be set to yes to empty the table.

      Note : NO flag will trigger an error. @DEFAULT : NO

  • Arguments

    • {string | ARRAY} TBL_NAME (required)
    • {string} MODE
  • Return

    {object} jDB Promise Instance

    • Arguments

      • {ARRAY} DATA (required)
      • {Boolean} hardInsert (optional) introduced in v1.0.5-beta
    • Mode: write or writeonly

    • hardInsert parameter is used when importing a jQl file format.

    • Usage

      Column name must be defined when using OBJECT, while for ARRAY the data must follow the order of column in the table. When inserting data in ARRAY format, data in each arraylist will be Mapped to the table column according to their index. Fields can be ommited only if they have a default value.
    • #InsertTransactionSuccess Instance

      • lastInsertId()

        Details:

        Returns the last insert id of a table, usually this is determined if there's a column with AUTO_INCREMENT configuration.

    • Arguments

      • {ARRAY} DATA (required)
      • {String} columnName
    • #InsertReplaceTransactionSuccess Instance

    • Mode: write

    • Usage

      columnName is used for replacing matching rows on the table. If parameter is omitted, jdb will try to find matching rows using column defined as unique.
    • Arguments

      • {OBJECT|STRING} DATA (required)
      • {OBJECT|STRING} Condition (optional)

        If parameter is empty, all rows in table will be updated.

    • Mode: write or writeonly

    • Usage

    • Arguments

      • {OBJECT|STRING} condition
    • Mode: write or writeonly

    • Usage

    • Arguments

      • {String} fields (required)
      • {Object} queryDefinition (optional)
      • column types

        • * To select all columns
        • -columnName : Select a column set from given table ( Seperate multiple columns with a comma)
        • -columnName as user-defined : select columns and return as user-defined prop (eg : -fullName as fName)
        • Extra select statement
          • COUNT() total result in a query
          • LOWERCASE(field) convert field value to lowercase
          • UPPERCASE(field) convert field value to uppercase
          • CURDATE() return current date string
          • DATE_DIFF(field1, field2)returns difference between 2 DATE
          • TIMESTAMP(FIELD) converts DATETIME value to timestamp
          • CASE( WHEN COLUMN = CONDITION THEN COLUMN2 ELSE WHEN COLUMN2 = CONDITION THEN COLUMN ELSE NULL) for field conditional statement
          • GET(column) return column_VALUE
          • New CLAUSE version 1.0.5-beta
          • CURDATETIME() return current date and time string
          • MIN(column) return minimum value in column
          • MAX(column) return maximum value in column
          • SUM(column) return sum of all value in column
          • AVG(column) return average of all value in column
          • DIV(column_1:column_2) return division of 2 column in a table
          • REVERSE(column) return reverse string of a column
          • LENGTH(column) return string length of a column
          • CONCAT(${column} ...) return concatenated parameter, specify column using placeholder.
          • RIGHT(column:length) return substr from right.
          • LEFT(column:length) return substr from left.
          • INSTR(column:needle) return indexof of a needle in a column.
          • TRIM(column) return trimmed value of a column
          • SUBSTR(column:start:length) return substring of a column by specifying the start position and length
    • Mode: read or readonly

    • Using Query Builder

      • WHERE:

        eg : where(COLUMN = VALUE)

        Please refer to JQL.select for more on string WHERE CLAUSE

      • Join:

        List of Join Clause to use

        • INNER
        • LEFT
        • RIGHT
        • OUTER
      • Limit:

        eg: limit(0,10)

      • gorupBy:

        eg: groupBy(field)

      • orderBy:

        eg: orderBy(fields:'ASC | DESC')

      • groupByStrict:

        eg: groupByStrict(field)

    • #SelectTransactionEvent Instance

      • jDBNumRows()

        Details:

        Returns number of row in result set

      • getRow(index)

        Details:

        Returns a row from result set by specifying the index of the row.

      • getResult()

        Details:

        Returns result set

      • first()

        Details:

        Returns first element in the result set.

      • openCursor(listener)

        Details:

        Iterate through the result set using cursor mode. Cursor event is passed as first parameter to the listener.

        CursorEvent Instance
        • result
        • continue()
        • prev()
        • index()
      • limit(start, end)

        Details:

        Returns sets of elements in the result set by specifying the start and end index.

Note : If "MODE" is undefined transaction is treated as read_only, for insert writeonly mode should be specified when opening a transaction.
  • Arguments

    • {ARRAY} transactions (required)

      transaction definition

      • {string} table TableName
      • {string} type transaction types (insert|update|delete)
      • {Array} data defined only in (insert|update) transactions.
      • {string|object} query defined only in (delete|update) transactions.
  • Details:

    Use this method to perform transactions on multiple tables. Failed validation on a single transaction will cause all transaction to also fail.

  • Arguments

    • {string} TBL_NAME
    • {object} definition
  • return: jDB Promise Instance

  • Details

    Importing record opens a dialog box to select the file you want to import to the table, accepted files are (.csv,.jql,.html,.json)

  • Arguments

    • {string} FORMAT
  • return: export Instance

  • Details

    Export a table record for referrence, accepted format are (.csv,.html,.json,.jql)

    Task List

    • Download
    • Print

# DB Promise Instance

  • onSuccess Function(CB)
  • onError Function(CB)
  • then Function(success, error)

# DB.jQl(command, [Handlers])

  • Arguments

    • {string} command (required)
    • {object} handlers

      Define how to handle response from jQl method.
      • onSuccess
      • onError
  • Details

    jQL is the best feature of jEliDB, it have the ability to perform query using it's own query Syntax, it's easy to use, with or without SQL knowledge. Aside using JQL to perform query task, it can also be used for other actions like calling REST APIS provided by JELIDB Applications.

    For more on JQL please click here

  • Create Custom jQL

  • Details

    Get information about a database

  • Example Response:

  • Methods
  • Details

    A stored procedure is a prepared jQl statement that you can save, so the code can be reused over and over again. You can also pass parameters to a stored procedure query, so that the stored procedure can act based on the parameter value(s) that is passed during execution state.

  • Arguments

    {boolean} flag (required)

  • Details

    Close the database, this closes any open connection to the underlying storage and frees memory (event listeners) the database may be using.

Functionalities below can only work when serviceHost is set to true. Please refer to https://frontendonly.com for more details

  • return: Sync Instance

  • Details

    Synchronize changes on the client to the server, jdbSyncService adapter will compare and check for changes between client and server. If the server is having the latest changes, the client will be updated with the server records else changes will be pushed to server for update

    • return: Sync Instance

    • Arguments:[ARRAYLIST] ARRAY_OF_TABLES optional

    • Details

      Synchronize specific tables by defining them in the arguments, to sync complete DB set to null.

    • return: sync.processEntity || clientService Instance

    • Arguments: {OBJECT} Definition

    • Details:

      This configurations can also be define when creating the database and it's extensible. Please look at Create a database

  • return: user Instance
  • Details

    Protect your database by adding users and priviledges. It can also be used for login verification.

    • Arguments

      • {OBJECT} PARAM
    • Arguments

      • {OBJECT} PARAM
    • Arguments

      • {OBJECT} PARAM
    • Arguments

      • {OBJECT} PARAM

# DB.clientService

  • returns clientService Instance: {OBJECT}

  • # DB.clientService.getByRef(tbl, query)

    • Arguments:
      • tbl {STRING} required
      • query {OBJECT} required
  • # DB.clientService.getAll(tbl, query)

    • Arguments:
      • tbl {STRING} required
      • query {OBJECT} required
  • # DB.clientService.getOne(tbl, query)

    • Arguments:
      • tbl {STRING} required
      • query {OBJECT} required
  • # DB.clientService.getNumRows(tbl, query)

    • Arguments:
      • tbl {STRING} required
      • query {OBJECT} required
  • # DB.clientService.put(tbl, [data])

    • Arguments:
      • tbl {STRING} required
      • data {OBJECT} required
  • # DB.clientService.delete(tbl, [data])

    • Arguments:
      • tbl {STRING} required
      • data {OBJECT} required