/rx-sqlite

A wrapper library that adds RxJS 5 API to sqlite3

Primary LanguageJavaScriptApache License 2.0Apache-2.0

Rx-SQLite

A wrapper library that adds RxJS 5 API to sqlite3

Installation

npm install rx-sqlite --save

or

yarn add rx-sqlite

Usage

import RxDatabase from "rx-sqlite";
import "rxjs";

let sql = `create table users (name text);
    insert into users values ("john");
    insert into users values ("bob");`;

let db = new RxDatabase(":memory:");

db.exec(sql)
  .switchMap(() => db.each("select rowid, name from users"))
  .subscribe(u => console.log(u));

API

RxDatabase

src/database.js:12-131

Database Wrapper Object that adds RxJS 5 API to sqlite3

constructor

src/database.js:20-22

make new RxDatabase object and open Database.

Parameters

  • filename string ":memory:" or filepath
  • mode Mode (Optional) one or combination value of Mode

prepare

src/database.js:29-40

prepare SQL and bind parameters.

Parameters

Returns RxStatement

run

src/database.js:47-49

Binds parameters and executes the query.

Parameters

Returns Observable<T>

get

src/database.js:56-58

Binds parameters and executes the query and retrieves a row.

Parameters

Returns Observable<T>

all

src/database.js:65-67

Binds parameters and executes the query and retrieves all rows at one time.

Parameters

Returns Observable<Array<T>>

each

src/database.js:74-91

Binds parameters and executes the query and retrieves all rows.

Parameters

Returns Observable<T>

exec

src/database.js:96-98

executes the multiple query.

Parameters

Returns Observable<void>

events

src/database.js:103-111

make new specified event stream.

Parameters

Returns Observable<Event>

busyTimeout

src/database.js:117-121

Set A Busy Timeout

Parameters

  • timeout number milliseconds of sleeping time

close

src/database.js:128-130

close the Database.

you should call this method when you work done

verbose

src/index.js:9-11

see node-sqlite3/Debugging

OPEN_READONLY

src/index.js:16-16

The database is opened in read-only mode.

OPEN_READWRITE

src/index.js:21-21

The database is opened for reading and writing if possible.

OPEN_CREATE

src/index.js:26-26

The database is opened for reading and writing, and is created if it does not already exist.

Mode

src/index.js:31-31

supported database opening flags

Type: (OPEN_READONLY | OPEN_READWRITE | OPEN_CREATE)

EventName

src/index.js:36-36

supported event names

Type: ("error" | "open" | "close" | "profile" | "trace")

RxStatement

src/statement.js:10-104

Statement Wrapper Object that adds RxJS 5 API to sqlite3

errors

src/statement.js:20-29

make new error event stream.

Returns Observable<{error: Error}>

run

src/statement.js:35-37

Binds parameters and executes the statement.

Parameters

Returns Observable<T>

get

src/statement.js:43-45

Binds parameters and executes the statement and retrieves a row.

Parameters

Returns Observable<T>

all

src/statement.js:51-53

Binds parameters and executes the statement and retrieves all rows at one time.

Parameters

Returns Observable<Array<T>>

each

src/statement.js:59-78

Binds parameters and executes the statement and retrieves all rows.

Parameters

Returns Observable<T>

bind

src/statement.js:84-88

Binds parameters to the prepared statement

Parameters

Returns Observable<RxStatement>

reset

src/statement.js:93-97

Returns Observable<RxStatement>

Development

Setup

git clone https://github.com/taichi/rx-sqlite
yarn install
yarn setup

Build

yarn build

License

Copyright 2017 taichi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.