typing-db
v0.0.1
Published
[experimental] Another in-memory database using Remeda
Downloads
1
Readme
type-db
[experimental] Another in-memory database using Remeda
Features
⚠ The following will be implemented.
- Type-safe: Works nicely with TypeScript
- Extensible: Save data to anywhere with custom adaptors
- Portable: Similar to Knex
- Sensible: Adds
id
,createdAt
,updatedAt
by default - Null-safe: Checks null if configured
- Relational: Supports basic
join
- Asynchronous: No synchronous API
Usage
⚠ The following will be implemented.
Basic usage
import { FileAdaptor, TypeDB, R, types } from 'type-db'
const adaptor = new FileAdaptor({
fileName: 'db.json',
})
const db = new TypeDB({
adaptor,
schema: {
users: {
email: types.string.unique,
name: types.string.defaultTo(''),
bio: types.nullable.string,
},
posts: {
userId: types.string,
content: types.string.defaultTo(''),
},
},
})
async function run() {
await db.init()
await db
.table('users')
.insert({ email: '[email protected]' })
.then((user) =>
db.table('posts').insert({ userId: user.id, content: 'Hello World' }),
)
const user = db.table('users').whereNotNull('bio').join('posts').first()
console.log(user)
}
run()
Output:
{
name: '',
email: '[email protected]',
posts: [
{
userId: 'Oa83eVai3',
content: 'Hello World',
},
],
}