# ts-database

> 这是基于typesciprt的indexedDB的数据库的操作函数

Latest version **0.0.4** (published 2023-03-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install ts-database
pnpm add ts-database
yarn add ts-database
bun add ts-database
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2023-03-08 |
| First published | 2022-05-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 23.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | xygengcn |
| Maintainers | xygengcn |
| Keywords | typescript, indexedDB, ts-database, Promise, js-store, orm |

## Links

- npm: https://www.npmjs.com/package/ts-database
- Repository: https://github.com/xygengcn/ts-database
- Homepage: https://github.com/xygengcn/ts-database#readme
- Issues: https://github.com/xygengcn/ts-database/issues
- npm.io page: https://npm.io/package/ts-database

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.4 (latest) — 2023-03-08
- 0.0.3 — 2022-05-28
- 0.0.2 — 2022-05-28
- 0.0.1 — 2022-05-28

## README

## 这是基于 typesciprt 的 indexedDB 的数据库的操作函数

本项目基于 typescript 封装了 indexedDB 基本操作函数，并返回 Promise 操作

### 实例

```ts
import Database from 'ts-database';

// 创建数据库,并创建一个用户表，设置主键为id
const database = new Database({
    name: 'TS_STORE',
    version: 1,
    modules: [{ name: 'users', primary: 'id', columns: [] }]
});

// 造数据
const user = {
    id: 'user0001',
    name: 'XY笔记',
    updatedAt: new Date().getTime()
};

// 创建用户
const createUser = () => {
    console.log('创建用户');
    return database.module('users').then((model) => {
        return model.bulkCreate([user]).then((result) => {
            console.error('创建成功', result);
        });
    });
};

createUser();
```

### 接口文档

#### 1、批量保存，存在更新

```js
moduel.bulkCreate();
```

#### 2、数据更新

```js
moduel.update();
```

#### 3、批量数据拉取

```js
moduel.findAll();
```

#### 4、根据主键拉取

```js
moduel.findByPk();
```

#### 5、 关键词搜索

```js
moduel.findAllLike();
```

#### 6、 删除

```js
moduel.destory();
```

#### 7、 表长度

```js
moduel.count();
```

#### 8、 清表

```js
moduel.clear();
```

#### 9、 数据库备份

```js
database.backup();
```

#### 10、 数据库恢复

```js
database.recovery();
```

---
_Source: https://npm.io/package/ts-database · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
