Home Reference Source
import IndexedFTS from 'indexedfts/lib/IndexedFTS.js'
public class | source

IndexedFTS

The database of IndexedFTS.

Almost methods are the same interface as IDBTransaction and IFTSArrayPromise.

Static Method Summary

Static Public Methods
public static

delete(name: string, scope: object): Promise<undefined>

Delete database.

Constructor Summary

Public Constructor
public

constructor(name: string, version: number, schema: object | IFTSSchema, options: object)

Create or open IndexedFTS.

Member Summary

Public Members
public

db: IDBDatabase

public
public
public
public
public

Method Summary

Public Methods
public

between(column: object, lower: object, upper: object): IFTSArrayPromise

Get contents that have property is between argument values.

public

close()

Close database.

public

Delete contents from database.

public

equals(column: object, value: object): IFTSArrayPromise

Get contents that have fully matched property.

public

filter(fun: function(content: object, index: Number): object): IFTSArrayPromise

Filtering elements by function and returns IFTSArrayPromise.

public

Get content by primary key.

public

Get all contents.

public

getNGrams(column: string, options: object): Promise<Map<string, number>>

Get N-Gram set from index.

public

getWords(column: string, options: object): Promise<Map<string, number>>

Get word set from index.

public

Get contents that have property greater than value.

public

Get contents that have property greater than value or equals value.

public

lower(column: object, value: object): IFTSArrayPromise

Get contents that have property lower than value.

public

Get contents that have property lower than value or equals value.

public

map(fun: function(content: object, index: Number): object): IFTSArrayPromise

Do something process for each elements and returns IFTSArrayPromise.

public

Open database.

public

put(contents: object): Promise<IndexedFTS>

Put contents into database.

public

search(columns: object | object[], query: string, options: object): IFTSArrayPromise

Get contents that have matched property by full-text search.

public

searchWord(columns: object | object[], query: string, options: object): IFTSArrayPromise

Find contents that have fully matched word in property.

public

sort(column: object, order: 'asc' | 'desc', offset: Number, limit: Number): IFTSArrayPromise

Sort and get all contents.

public

transaction(mode: "readonly" | "readwrite", target: string[] | null): IFTSTransaction

Make new IFTSTransaction.

Static Public Methods

public static delete(name: string, scope: object): Promise<undefined> source

Delete database.

Must be close all IndexedFTS before delete database.

Params:

NameTypeAttributeDescription
name string

name of target database. this method will success even if no such database.

scope object
  • optional

endpoints for IndexedDB API.

Return:

Promise<undefined>

Public Constructors

public constructor(name: string, version: number, schema: object | IFTSSchema, options: object) source

Create or open IndexedFTS.

Database has name and schema's version. The name is a name of the database in the storage.

The schema is an object that key is column name and value is a definition of indexes. Schema can't change in same version database. If you want change schema of database, please change version number. Please be careful, all contents will remove when changing the version number.

Index types are 'primary', 'unique', 'fulltext', 'ngram', 'word', or 'normal'.

'primary' is a primary key of the database. 'primary' can't set to multiple columns. 'unique' is columns that have a unique value in the database. The 'normal' will enable when not primary and not unique. 'primary', 'unique' and 'normal' column can numeric search (eg. IndexedFTS#lower or IndexedFTS#between).

If set 'ngram' IndexedFTS will make 2-gram index table for full-text search. 'fulltext' is alias to 'ngram'.

'word' is word based index. The word index will split text with whitespaces and store those. Word index is faster than the 'ngram' index but can't find a partial match in the word.

If you want to set some index types, please use object like {unique: true, fulltext: true, normal: false}.

Params:

NameTypeAttributeDescription
name string

name of new (or open) database.

version number

schema's version of database.

schema object | IFTSSchema

database schema.

options object
  • optional

other options.

options.index_prefix string
  • optional
  • default: 'indexedfts_'

prefix of indexes for full-text search.

options.scope object
  • optional
  • default: window

endpoints for IndexedDB API.

Throw:

InvalidSchemaError

Public Members

public db: IDBDatabase source

public index_prefix: string source

public name: string source

public schema: IFTSSchema source

public scope: object source

public version: number source

Public Methods

public between(column: object, lower: object, upper: object): IFTSArrayPromise source

Get contents that have property is between argument values.

Params:

NameTypeAttributeDescription
column object

column name for search.

lower object

minimal value.

upper object

maximum value.

Return:

IFTSArrayPromise

matched contents. may reject with NoSuchColumnError.

public close() source

Close database.

public delete(keys: object): Promise<IndexedFTS> source

Delete contents from database.

Params:

NameTypeAttributeDescription
keys object

key of contents.

Return:

Promise<IndexedFTS>

returns self for chain. Will reject with InvalidKeyError if keys included null or undefined.

public equals(column: object, value: object): IFTSArrayPromise source

Get contents that have fully matched property.

Params:

NameTypeAttributeDescription
column object

column name for search.

value object

value for search.

Return:

IFTSArrayPromise

matched contents. may reject with NoSuchColumnError.

public filter(fun: function(content: object, index: Number): object): IFTSArrayPromise source

Filtering elements by function and returns IFTSArrayPromise.

WARNING: This method won't use the index. Other methods(eg. {@link IFTSTransaction#equals or @link IFTSTransaction#lower} may faster than this.

Params:

NameTypeAttributeDescription
fun function(content: object, index: Number): object

function for filtering element.

public get(key: object): Promise<object|undefined> source

Get content by primary key.

Params:

NameTypeAttributeDescription
key object

the key of content.

Return:

Promise<object|undefined>

content. promise will reject with InvalidKeyError if keys included null or undefined. result value will be undefined if not found.

public getAll(): IFTSArrayPromise source

Get all contents.

Return:

IFTSArrayPromise

contents.

public getNGrams(column: string, options: object): Promise<Map<string, number>> source

Get N-Gram set from index.

Params:

NameTypeAttributeDescription
column string

name of column.

options object
  • optional

optional arguments.

options.ignoreCase boolean
  • optional
  • default: false

ignore case when make result.

Return:

Promise<Map<string, number>>

public getWords(column: string, options: object): Promise<Map<string, number>> source

Get word set from index.

Params:

NameTypeAttributeDescription
column string

name of column.

options object
  • optional

optional arguments.

options.ignoreCase boolean
  • optional
  • default: false

ignore case when make result.

Return:

Promise<Map<string, number>>

public greater(column: object, value: object): IFTSArrayPromise source

Get contents that have property greater than value.

Params:

NameTypeAttributeDescription
column object

column name for search.

value object

value for search.

Return:

IFTSArrayPromise

matched contents. may reject with NoSuchColumnError.

public greaterOrEquals(column: object, value: object): IFTSArrayPromise source

Get contents that have property greater than value or equals value.

Params:

NameTypeAttributeDescription
column object

column name for search.

value object

value for search.

Return:

IFTSArrayPromise

matched contents. may reject with NoSuchColumnError.

public lower(column: object, value: object): IFTSArrayPromise source

Get contents that have property lower than value.

Params:

NameTypeAttributeDescription
column object

column name for search.

value object

value for search.

Return:

IFTSArrayPromise

matched contents. may reject with NoSuchColumnError.

public lowerOrEquals(column: object, value: object): IFTSArrayPromise source

Get contents that have property lower than value or equals value.

Params:

NameTypeAttributeDescription
column object

column name for search.

value object

value for search.

Return:

IFTSArrayPromise

matched contents. may reject with NoSuchColumnError.

public map(fun: function(content: object, index: Number): object): IFTSArrayPromise source

Do something process for each elements and returns IFTSArrayPromise.

NOTE: This method doesn't fast. May better do filtering before doing map if need filtering.

Params:

NameTypeAttributeDescription
fun function(content: object, index: Number): object

function for processing element.

public open(): Promise<undefined> source

Open database.

Return:

Promise<undefined>

public put(contents: object): Promise<IndexedFTS> source

Put contents into database.

Params:

NameTypeAttributeDescription
contents object

contents for save. allowed multiple arguments.

Return:

Promise<IndexedFTS>

returns self for chain.

Get contents that have matched property by full-text search.

All target columns have to made ngram index when created database. If you didn't made ngram index, you can use IFTSArrayPromise#search (but this way is very slow).

Params:

NameTypeAttributeDescription
columns object | object[]

column names for search.

query string

query for search.

options object
  • optional

optional arguments.

options.ignoreCase boolean
  • optional
  • default: false

ignore case if true. default is false.

Return:

IFTSArrayPromise

matched contents. may reject with NoSuchColumnError.

public searchWord(columns: object | object[], query: string, options: object): IFTSArrayPromise source

Find contents that have fully matched word in property.

All target columns have to made word index when created database. If you didn't made word index, you can use IFTSArrayPromise#searchWord (but this way is very slow).

Params:

NameTypeAttributeDescription
columns object | object[]

column names for search.

query string

query for search.

options object
  • optional

optional arguments.

options.ignoreCase boolean
  • optional
  • default: false

ignore case if true. default is false.

Return:

IFTSArrayPromise

matched contents. may reject with NoSuchColumnError.

public sort(column: object, order: 'asc' | 'desc', offset: Number, limit: Number): IFTSArrayPromise source

Sort and get all contents.

Params:

NameTypeAttributeDescription
column object

the column for sorting.

order 'asc' | 'desc'
  • optional
  • default: 'asc'

sort order.

offset Number
  • optional
  • default: 0

starting offset of the result.

limit Number
  • optional

maximum number of result length. will unlimited if omitted.

Return:

IFTSArrayPromise

sorted contents.

public transaction(mode: "readonly" | "readwrite", target: string[] | null): IFTSTransaction source

Make new IFTSTransaction.

Params:

NameTypeAttributeDescription
mode "readonly" | "readwrite"

mode of transaction.

target string[] | null

open index targets. open for all if null.

Return:

IFTSTransaction