DataAdapter

most-data/types~ DataAdapter

Represents an abstract data connector to a database

There are several data adapters for connections to common database engines:

  • MOST Web Framework MySQL Adapter for connecting with MySQL Database Server

    Install the data adapter:

    npm install most-data-mysql

    Append the adapter type in application configuration (app.json#adapterTypes):

    
     ...
     "adapterTypes": [
     ...
     { "name":"MySQL Data Adapter", "invariantName": "mysql", "type":"most-data-mysql" }
     ...
     ]
     

    Register an adapter in application configuration (app.json#adapters):

    
     adapters: [
     ...
     { "name":"development", "invariantName":"mysql", "default":true,
         "options": {
           "host":"localhost",
           "port":3306,
           "user":"user",
           "password":"password",
           "database":"test"
         }
     }
     ...
     ]
     
  • MOST Web Framework MSSQL Adapter for connecting with Microsoft SQL Database Server

    Install the data adapter:

    npm install most-data-mssql

    Append the adapter type in application configuration (app.json#adapterTypes):

    
     ...
     "adapterTypes": [
     ...
     { "name":"MSSQL Data Adapter", "invariantName": "mssql", "type":"most-data-mssql" }
     ...
     ]
     

    Register an adapter in application configuration (app.json#adapters):

    
     adapters: [
     ...
     { "name":"development", "invariantName":"mssql", "default":true,
            "options": {
              "server":"localhost",
              "user":"user",
              "password":"password",
              "database":"test"
            }
        }
     ...
     ]
     
  • MOST Web Framework PostgreSQL Adapter for connecting with PostgreSQL Database Server

    Install the data adapter:

    npm install most-data-pg

    Append the adapter type in application configuration (app.json#adapterTypes):

    
     ...
     "adapterTypes": [
     ...
     { "name":"PostgreSQL Data Adapter", "invariantName": "postgres", "type":"most-data-pg" }
     ...
     ]
     

    Register an adapter in application configuration (app.json#adapters):

    
     adapters: [
     ...
     { "name":"development", "invariantName":"postgres", "default":true,
            "options": {
              "host":"localhost",
              "post":5432,
              "user":"user",
              "password":"password",
              "database":"db"
            }
        }
     ...
     ]
     
  • MOST Web Framework Oracle Adapter for connecting with Oracle Database Server

    Install the data adapter:

    npm install most-data-oracle

    Append the adapter type in application configuration (app.json#adapterTypes):

    
     ...
     "adapterTypes": [
     ...
     { "name":"Oracle Data Adapter", "invariantName": "oracle", "type":"most-data-oracle" }
     ...
     ]
     

    Register an adapter in application configuration (app.json#adapters):

    
     adapters: [
     ...
     { "name":"development", "invariantName":"oracle", "default":true,
            "options": {
              "host":"localhost",
              "port":1521,
              "user":"user",
              "password":"password",
              "service":"orcl",
              "schema":"PUBLIC"
            }
        }
     ...
     ]
     
  • MOST Web Framework SQLite Adapter for connecting with Sqlite Databases

    Install the data adapter:

    npm install most-data-sqlite

    Append the adapter type in application configuration (app.json#adapterTypes):

    
     ...
     "adapterTypes": [
     ...
     { "name":"SQLite Data Adapter", "invariantName": "sqlite", "type":"most-data-sqlite" }
     ...
     ]
     

    Register an adapter in application configuration (app.json#adapters):

    
     adapters: [
     ...
     { "name":"development", "invariantName":"sqlite", "default":true,
            "options": {
                database:"db/local.db"
            }
        }
     ...
     ]
     
  • MOST Web Framework Data Pool Adapter for connection pooling

    Install the data adapter:

    npm install most-data-pool

    Append the adapter type in application configuration (app.json#adapterTypes):

    
     ...
     "adapterTypes": [
     ...
     { "name":"Pool Data Adapter", "invariantName": "pool", "type":"most-data-pool" }
     { "name":"...", "invariantName": "...", "type":"..." }
     ...
     ]
     

    Register an adapter in application configuration (app.json#adapters):

    
     adapters: [
     { "name":"development", "invariantName":"...", "default":false,
        "options": {
          "server":"localhost",
          "user":"user",
          "password":"password",
          "database":"test"
        }
    },
     { "name":"development_with_pool", "invariantName":"pool", "default":true,
        "options": {
          "adapter":"development"
        }
    }
     ...
     ]
     

Constructor

(abstract) new DataAdapter(options)

Parameters:
Name Type Description
options * The database connection options
Properties:
Name Type Description
rawConnection * Gets or sets the native database connection
options * Gets or sets the database connection options
Source:

Methods

close(callbackopt)

Closes the underlying database connection
Parameters:
Name Type Attributes Description
callback function <optional>
A callback function where the first argument will contain the Error object if an error occured, or null otherwise.
Source:

createView(name, query, callbackopt)

A helper method for creating a database view if the current data adapter supports views
Parameters:
Name Type Attributes Description
name string A string that represents the name of the view to be created
query QueryExpression | * A query expression that represents the database view
callback function <optional>
A callback function where the first argument will contain the Error object if an error occured, or null otherwise.
Source:

execute(query, values, callback)

Executes the given query against the underlying database.
Parameters:
Name Type Description
query string | * A string or a query expression to execute.
values * An object which represents the named parameters that are going to used during query parsing
callback function A callback function where the first argument will contain the Error object if an error occured, or null otherwise. The second argument will contain the result.
Source:

executeBatch(batch, callbackopt)

Executes a batch query expression and returns the result.
Parameters:
Name Type Attributes Description
batch DataModelBatch The batch query expression to execute
callback function <optional>
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. The second argument will contain the result.
Deprecated:
  • This method is deprecated.
Source:

executeInTransaction(fn, callbackopt)

Begins a transactional operation and executes the given function
Parameters:
Name Type Attributes Description
fn function The function to execute
callback function <optional>
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. The second argument will contain the result.
Source:

open(callback)

Opens the underlying database connection
Parameters:
Name Type Description
callback function A callback function where the first argument will contain the Error object if an error occured, or null otherwise.
Source:

selectIdentity(entity, attribute, callbackopt)

Produces a new identity value for the given entity and attribute.
Parameters:
Name Type Attributes Description
entity string A string that represents the target entity name
attribute string A string that represents the target attribute name
callback function <optional>
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. The second argument will contain the result.
Source: