unibe
v1.0.7
Published
A universal database interaction library with Koa.js integration.
Readme
Unibe Database Toolkit
A universal database interaction library with Koa.js integration.
Features
- Support for multiple database types: MySQL, PostgreSQL, MSSQL, Oracle
- Unified query/mutation/meta operations interface
- Built-in pagination and security controls
- TypeScript support with comprehensive type definitions
- Koa.js middleware integration
Installation
npm install unibeBasic Usage
Query Example
import { Query } from 'unibe'
const response = await Query('datasource_name', 'trigger_name', {
// request data
})Mutation Example
import { Mutation } from 'unibe'
const response = await Mutation(
'datasource_name',
'insert', // or 'update', 'delete'
'entity_name',
{
// data to insert/update
}
)Server Setup
import { S } from 'unibe'
const routers = [
[
'/api/query',
async (ctx, next) => {
// your route handler
}
]
]
const middlewares = [
// your Koa middlewares
]
S(routers, middlewares, 3000) // Start server on port 3000Type Definitions
Database Types
Supported database types:
mysqlpostgresqlmssqloracle
Response Structure
interface RESPONSE_CONTENT {
result: 'success' | 'fail' | string
code: number
message?: string
data?: Array<Record<string, string | number>>
length?: number
}Extensions
The library extends native JavaScript types with useful methods:
String Extensions
'text'.md5() // Generate MD5 hash
'text'.json() // Parse as JSON
'text'.send(data) // HTTP requestNumber Extensions
;(1000).thou() // "1,000"
;(1000).price() // Formatted as price stringFor full type definitions, see src/index.d.ts
