-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
1,039 additions
and
589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# koishi-database-memory | ||
|
||
[![Status](https://img.shields.io/github/workflow/status/koishijs/koishi/CI/master?style=flat-square)](https://github.com/koishijs/koishi/actions?query=workflow:CI) | ||
[![npm](https://img.shields.io/npm/v/koishi-database-memory?style=flat-square)](https://www.npmjs.com/package/koishi-database-memory) | ||
|
||
An in-memory database for Koishi. | ||
|
||
## Usage | ||
|
||
- [Using Database with Koishi](https://koishi.js.org/guide/using-database.html) | ||
- [Full API Reference](https://koishi.js.org/api/database.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "koishi-database-memory", | ||
"description": "An in-memory database implementation for Koishi", | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"author": "Shigma <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"lint": "eslint src --ext .ts", | ||
"prepack": "tsc -b" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/koishijs/koishi.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/koishijs/koishi/issues" | ||
}, | ||
"homepage": "https://github.com/koishijs/koishi/tree/master/packages/database-memory#readme", | ||
"dependencies": { | ||
"koishi-core": "^1.5.0", | ||
"koishi-utils": "^1.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { testDatabase } from 'koishi-test-utils' | ||
import { injectMethods } from 'koishi-core' | ||
import '../src' | ||
|
||
declare module 'koishi-core/dist/database' { | ||
interface TableMethods { | ||
foo: FooMethods | ||
} | ||
|
||
interface TableData { | ||
foo: FooData | ||
} | ||
} | ||
|
||
interface FooMethods { | ||
createFoo (data?: Partial<FooData>): Promise<FooData> | ||
removeFoo (id: number): Promise<void> | ||
getFooCount (): Promise<number> | ||
} | ||
|
||
interface FooData { | ||
id: number | ||
bar: string | ||
} | ||
|
||
injectMethods('memory', 'foo', { | ||
async createFoo (data: Partial<FooData> = {}) { | ||
return await this.create('foo', data) as FooData | ||
}, | ||
|
||
removeFoo (id: number) { | ||
return this.remove('foo', id) | ||
}, | ||
|
||
getFooCount () { | ||
return this.count('foo') | ||
} | ||
}) | ||
|
||
const app = testDatabase({ | ||
memory: {}, | ||
}, { | ||
beforeEachUser: app => app.database.memory.store.user = [], | ||
beforeEachGroup: app => app.database.memory.store.group = [], | ||
}) | ||
|
||
describe('other methods', () => { | ||
const { database: db } = app | ||
beforeAll(() => db.memory.store.foo = []) | ||
|
||
test('create & remove', async () => { | ||
await expect(db.getFooCount()).resolves.toBe(0) | ||
await expect(db.createFoo()).resolves.toMatchObject({ id: 1 }) | ||
await expect(db.getFooCount()).resolves.toBe(1) | ||
await expect(db.createFoo()).resolves.toMatchObject({ id: 2 }) | ||
await expect(db.getFooCount()).resolves.toBe(2) | ||
await expect(db.removeFoo(1)).resolves.toBeUndefined() | ||
await expect(db.getFooCount()).resolves.toBe(1) | ||
await expect(db.createFoo()).resolves.toMatchObject({ id: 1 }) | ||
await expect(db.getFooCount()).resolves.toBe(2) | ||
await expect(db.createFoo({ id: 100 })).resolves.toMatchObject({ id: 100 }) | ||
await expect(db.getFooCount()).resolves.toBe(3) | ||
await expect(db.removeFoo(1)).resolves.toBeUndefined() | ||
await expect(db.getFooCount()).resolves.toBe(2) | ||
await expect(db.createFoo()).resolves.toMatchObject({ id: 1 }) | ||
await expect(db.getFooCount()).resolves.toBe(3) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../tsconfig.base", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
}, | ||
"include": [ | ||
"src", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.