Defintion
1. Global
Example
import { setup } from 'oor';
import { logger } from './custom_loggers'
// Global Defintion
setup({
provider: () => ClientBase | Pool,
pageSize: 10,
showSQL: logger.debug;
strict: true,
})
Params
item |
type |
detail |
default |
provider |
() => ClientBase | Pool |
DataSource, Connection pool is suggested |
Required |
pageSize |
number |
Default number of data items per page |
10 |
showSQL |
(sql:string,param:any)=>void |
For debug, print sql and params |
null / console.debug |
strict |
boolean, Support specify single |
query : select ,entity : add/update true : Code will thorw Errors false : Code will ignore and log Errors |
false |
2. Table
Example
const User = new Table('public.user', UserSchema, {
key: 'id', // Primary key
sortOrder: 'lastModify', // default sort method
sortBy: 'desc'; // default sort filed
pageSize: 10, // Number of data items per page,Defult use Global
globalCondition: [ // Global Filter use in this Table
{ field: 'id', condition: '!=', 'value': 1 }
]
});
Params
item |
type |
detail |
detault |
key |
string |
Primary key of table |
"id" |
sort |
Sort |
default order by |
|
pageSize |
number |
Number of data items per page |
10 |
globalCondition |
WhereItem[] |
Global Filter use in this Table |
|
3. Field
Example
const UserSchema = UType.Table({
// Field Defined is Base on typebox
// The Schema can be used by typebox/value, fastify etc.
// See Detail : https://github.com/sinclairzx81/typebox
id: UType.Integer(),
// Use `UType` instead of `Type`, Only Provide 5 types :
// String, Number, Interger, Boolean, Boolean
// UType.Table is equeal to Parital<TObject>
name: UType.String({ maxLength: 32 }),
sex: UType.Boolean(),
// Define `ignore: true`, can avoid this column in SELECT {X}
profile: UType.String({ ignore: true }),
// Define `column : string` When filedName not equeal to Table Column Name.
phoneNo: UType.String({ column: 'phone_no' }),
// If this table use logical delete, use `delMark`
// define `delMark: {value}`, can effect:
// 1. `delete` will convert to `update` : set `columnName` = {value}
// 2. `query/update` will appen WHERE condition etc. `WHERE status != 999`
// delMark not support Date / Boolean
// One Table, One/Zero delMark
status: UType.Integer({ delMark: 999 }),
// If a date's value fixed at create time:
// Define `isCreate: true` , only in type : `Date`
registerDate: UType.Date({ column: 'register_date', isCreate: true }),
// If a date's value update each update:
// Define `isModify: true` , only in type : `Date`
lastModify: UType.Date({ column: 'last_modify', isModify: true })
});
Params
item |
type |
detail |
default |
ignore |
All |
Avoid this column in SELECT |
false |
column |
ALL |
Real data table column name |
Same as field name. |
delMark |
String, Number |
Use logical delete, mark this field fix value as DELETED |
|
isCreate |
Date |
Date's value fixed at create time if true |
false |
isModify |
Date |
Date's value update to time each update if true |
false |