# Class: LocalDatabaseTransport

## LocalDatabaseTransport

#### new LocalDatabaseTransport(config)

Database transport for IndexedDB.

  Database transport for IndexedDB

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `config`

  object

  Transport configuration

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `version` | number | Database version. Same as IndexedDB database version.
  `tables` | object | Database tables. Dexie tables configuration.
  `dbName` | string | Database name. Same as IndexedDB database name.

  Author:
    - Eduardo Perotta de Almeida
  Source:
    - LocalDatabaseTransport.js, line 8
  See:
    - The Data Transport is set into the `Foundation` stack and it is consumed inside `DataEntity` to persist data locally.
    - `LocalDatabaseTransport` extends Dexie as database handler for IndexedDB. See Dexie

  ##### Example

          import LocalDatabaseTransport from './LocalDatabaseTransport'
          import { Schema } from './utils'

          const UserSchema = new Schema({
            name: {
              type: String,
              required: true
            },
            username: {
              type: String,
              required: true
            }
          })

          const ProductSchema = new Schema({
            // ...
          })

          const dbName = 'MyDatabaseName'

          const localDataTransport = new LocalDatabaseTransport({
            version: 1,   // default 1
            tables: {},   // default {}
            dbName
          })

          // or

          const localDataTransport = new LocalDatabaseTransport({ dbName })

          localDataTransport.addSchema('User', UserSchema)

          localDataTransport.addSchema('Product', ProductSchema)

          await localDataTransport.connect()

          const Biden = await localDataTransport.table('User').add({ name: 'Joe Biden', username: 'biden'})

          const Ferrari = await localDataTransport.table('Product').add({ name: 'Ferrari', vendor: 'Ferrari', price_cost: 3000000})

### Extends

- dexie

### Methods

#### <static> addSchema(schemaName, schema)

A a Data Schema into the Schema tree.

  A a Data Schema into the Schema tree

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `schemaName` | string | The schema name. Same as Entity name.
  `schema` | object | A valid mongoose like schema

  Source:
    - LocalDatabaseTransport.js, line 90

  ##### Returns:

  schema - The schema enty from inside the Schema tree
  Type
    object

  ##### Example

      const UserSchema = new Schema({
              name: {
                type: String,
                required: true
              },
              username: {
                type: String,
                required: true
              }
            })
            localDataTransport.addSchema('User', UserSchema)

#### <async, static> connect()

Setup connection to local database.

  Setup connection to local database
  Source:
    - LocalDatabaseTransport.js, line 114

  ##### Returns:

  - Foundation GUID saved on localStorage
  - signature - Default methods signature format { error, data }
    Type
      object
  - signature.error - Execution error information
    Type
      string | object
  - signature.data - Connection information
    Type
      object

  ##### Example

      await localDataTransport.connect()

#### Search results