Namespace ydn.db.schema
Catalog
ydn.db.schema.Catalog text
Full text catalog.
Full text catalog is a logical grouping of one or more
full-text indexes.
var catalog = { name: 'author-name', lang: 'en', sources: [{ storeName: 'author', keyPath: 'first', weight: 1.0 }, { storeName: 'author', keyPath: 'last', weight: 0.8 }]
- Fields:
- {string} name
- Full text catalog name.
- {string=} lang
- Language.
- {Array} sources
- Full text indexes.
ydn.db.schema.Database
Define database schema in JSON.
Database schema is used in creating Storage object to define object stores for IndexedDB and TABLE for WebSQL.
If a database schema has a version field, it is called explicit versioning and Storage object will connect to the specified version. Otherwise implicit versioning, Storage will connected to available version starting from version 0 and increase as version change is necessary.
If Stores is not defined, it is called auto-schema mode and object stores are created as necessary.
var schema = { stores: [ { name: 'player', keyPath: 'id' } ];
- Fields:
- {integer=} autoSchema
- Optional. If true, schema are updated as necessary.
- {Array.<!ydn.db.schema.Store>=} stores
- Optional. List of store schema.
- {integer=} version
- Optional. Schema version.
- {Array.<ydn.db.schema.Catalog>=} fullTextCatalogs
- Optional. Full text catalogs.
EncryptionOption
Define encryption options in JSON.
var options = { Encryption: { unsafeParse: false, method: 'acs-cbc', encryptKey: false, secrets: [{ name: 'aaaa', key: 'aYHF6vfuGHpfWS*eRLrPQxZjSó~É5c6HjCscqDqRtZasp¡JWSMGaW' }] } };
- Fields:
- {number=} expiration
- Optional. expiration time in ms.
- {boolean=} encryptKey
- Optional. Encrypt record key. By default only record value is encrypted.
- {string=} method
- Encryption key and name.
- {Array<Object>} secrets
- Optional. Cipher algorithms, either 'aes-cbc' or 'rc4', representing Advanced Encryption Standard with Cipher Block Chaining Mod or Rivest Cipher 4 respectively. Default to 'aes-cbc'.
ydn.db.schema.Index
Define index schema in JSON.
var user_store = { keyPath: 'email' type: 'TEXT' indexes: [{ name: 'last, first', keyPath: ['last', 'first'], }, { keyPath: 'hobby' multiEntry: true type: 'TEXT' }, { name: 'name', // index for case in-sensitive sorting generator: function(obj) { var name = obj.first + ' ' + obj.last; return name.toLowerCase(); } }] }; // example user record var user = { first: 'Aa', last: 'Ba email: 'ab@example.com', hobby: ['camping', 'guitar'], age: 24 }
- Fields:
- {string=} name
- Optional. Index name.
- {function(!Object)=} generator
- Optional. Index
key generator. Generator function will be invoked when a record
value is about to
add
orput
to the object store. Returning a validIDBKey
orundefined
will set to the index key of the record value while ignoring other return type. - {string} keyPath
- Key path defined field path to extract key from the record object. Use array to define compound index. User doted notation to define nested path. Use dotted notation to reference nested attributes. Use array to represent composite index.
- {(!Array.<string>|string)=} type
- Optional. Data
type of the key. If provided, WebSQL uses for optimization.
Possible value are
BLOB
,DATE
,INTEGER
,NUMERIC
andTEXT
. IfautoIncrement
is true and data type is defined, data type must beINTEGER
. - {boolean=} unique
- Optional.
Constrain unique index key value.
ConstrainError
will issue if duplicate index key is stored. - {boolean=} multiEntry
- Optional. For array index key, individual elements are indexed.
ydn.db.schema.Store
Define store schema in JSON.
var store = { name: 'player', keyPath: 'id.$t', indexes: [ { keyPath: 'age' } ] } // example player record var player_1 = { full_name: 'A B', id: { $t: 'ab' } age: 24 }
- Fields:
- {boolean=} autoIncrement
- Optional. Key will be generated if it is not provided.
- {(!Array.<string>|string)=} keyPath
- Key path defined field path to extract key from the record object. If keyPath is provided, it is called in-line-key, otherwise out-of-line key. Use dotted notation to reference nested attributes. Use array key path to represent compound key, composing multiple fields of record value. The key itself can be array, are terms as composite key.
- {string} name
- Optional. Store name.
- {Array.<ydn.db.schema.Index>=} indexes
- Optional. List of indexes.
- {string} dispatchEvents
- Optional. Install storage instance to dispatch change events.
- {ydn.db.schema.Sync} Sync
- Optional. Synchronization options.
- {boolean=} fixed
- Optional. Use
fixed table schema for WebSql. Record value are stored in
serialized string into a special BLOB column, which enable
schema-less storage to WebSql. When fixed table schema is used,
this default column is not created. Setting this value to
true
will save only indexed field of the record. - {(!Array.<string>|string)=} type
- Optional. Data
type of the key. If provided, WebSQL uses for optimization.
Possible value are
BLOB
,DATE
,INTEGER
,NUMERIC
andTEXT
. IfautoIncrement
is true and data type is defined, data type must beINTEGER
. If keyPath is array, type must also be array representing respective elements.
ydn.db.schema.Sync
Define synchronization options.
var store_schema = { name: 'author', keyPath: 'email', Sync: { format: 'gcs', Options: { bucket: 'ydn-data1', prefix: 'author/' } } }
- Fields:
- {string=} format
- Backend service format. Valid values are 'rest', 's3', 'gcs', 'odata', 'gdata'.
- {boolean=} immutable
- Set
true
for immutable object store, in which only read and create methods are allowed, while update and delete methods are prohibited. - {\{request: Function}=} transport
- HTTP transport object. A transport object has a request method
which make HTTP request. The request method take one argument, of
object having the following fields:
- request function argument:
-
path: {string} The URL to handle the requestmethod: {string} The HTTP request method to use. Default is GET.params: {Object} URL params in key-value pair formheaders: {Object} Additional HTTP request headersbody: {string} The HTTP request body (applies to PUT or POST).callback: {function(json, raw)} Request callback.
- {Object=} Options
- Backend service specific options.
- common fields:
-
baseUri: {string=} Base URI, such as https://api.yathit.com/rpc/metaStoreName: {string=} Store name for meta data, if it is stored saperately from record store.metaDataName: {string=} Meta data object field name, if it is stored inline with record value.
- S3 (and Google cloud storage) fields:
-
bucket: {string=} Blob store bucket nameprefix: {string=} URI prefix.