DK-db
DK database - library for working with database.
Examples
| Used code: TypeScript
db_new
Connect in server and make / update record
Ex_1
;;;;; const main = { // make pointer DB connection (create the database manually) const db: Db_s = ; // DB connected true - 80 ms (mysql://root:***@localhost/test) // make pointer Table const table: Db_table = ; // create all tables const err: Err_s = ; if err !== undefined ; // record create const rec_1 = ; // check error if ; // throw // record update const rec_2 = ; // check error if ; // Print id records console; // rec_1.id = 1, rec_2.id = 1}; ;
Api
Types
Db
Db_o
Field | Type | Default | Desc |
---|---|---|---|
type | Str_s | DB_CONNECT_TYPE | Type server |
host | Str_s | DB_CONNECT_HOST | Server host |
port | Num_s | DB_CONNECT_PORT | Server port |
name | Str_s | DB_CONNECT_NAME | Database name |
user | Str_s | DB_CONNECT_USER | Database user |
password | Str_s | DB_CONNECT_PASSWORD | Database password |
timeout | Num_s | DB_CONNECT_TIMEOUT | Max connection timeout |
findRecords | Num_s | DB_FIND_LIMIT | Limit list |
findTimeout | Time_s | DB_FIND_TIMEOUT | Max get find timeout |
recTimeout | Time_s | DB_REC_TIMEOUT | Max get record timeout |
tableTimeout | Time_s | DB_TABLE_TIMEOUT | Max timeout creating table |
Db_s
Field | Type | Value |
---|---|---|
type | Str_s | Db_o.type |
host | Str_s | Db_o.host |
port | Num_s | Db_o.port |
name | Str_s | Db_o.name |
user | Str_s | Db_o.user |
password | Str_s | Db_o.password |
timeout | Time_s | Db_o.timeout |
findRecords | Num_s | Db_o.findRecords |
findTimeout | Time_s | Db_o.findTimeout |
recTimeout | Time_s | Db_o.recTimeout |
tableTimeout | Time_s | Db_o.tableTimeout |
orm | any | Db_o.orm |
Table
Db_table_opt
Field | Type | Desc |
---|---|---|
name | Str_s | Table name |
fields | Db_fields | Fields list |
uniqueLs | Db_table_ls_unique | Unique list (name field) |
Db_table
Field | Type | Desc |
---|---|---|
db | Db_s | Pointer on DB |
orm | any | Orm table object |
name | Str_s | Db_table_opt.name |
fields | Db_fields | Db_table_opt.fields |
uniqueLs | Str_s | Db_table_opt.uniqueLs |
Db_table_ls_unique => Array<Str_s>
List unique group (Str_s)
Db_tables => Array<Db_table>
List Db_table
Field
Db_field
Field | Type | Desc |
---|---|---|
name | Str_s | Name |
type | Str_s | Type: integer, text |
size | Num_s | Size 1-65555 |
val | Str_s | Value |
Db_fields => Array<Db_field>
Constants
Default library
Name | Type | Value | Desc |
---|---|---|---|
DB_NAME | Str_std | DK-db | Name library |
DB_KEY | Str_std | db | Key library |
DB_ID | Any_id | 0 | Id library |
DB_VER | Str_std | 0.1.3 | Version library |
Connection default
Name | Type | Value | Desc |
---|---|---|---|
DB_CONNECT_TYPE | Str_std | mysql | Server type |
DB_CONNECT_HOST | Str_std | localhost | Server host |
DB_CONNECT_PORT | Num_std | 3306 | Server port |
DB_CONNECT_USER | Str_std | root | User name |
DB_CONNECT_NAME | Str_std | db | Database name |
DB_CONNECT_PASSWORD | Str_std | "" | User password |
DB_CONNECT_TIMEOUT | Num_std | 10 | Timeout connection |
Record default
Name | Type | Value | Desc |
---|---|---|---|
DB_REC_TIMEOUT | Num_std | 3 | Timeout get record |
Find default
Name | Type | Value | Desc |
---|---|---|---|
DB_FIND_TIMEOUT | Num_std | 5 | Timeout find |
DB_FIND_LIMIT | Num_std | 100 | Limit list |
Fields
Name | Type | Value | Desc |
---|---|---|---|
DB_FIELD_ID | Str_std | id | Primary (AUTO_INCREMENT) |
DB_FIELD_CREATED | Str_std | _created | Created record |
DB_FIELD_UPDATED | Str_std | _updated | Updated record |
Table
Name | Type | Value | Desc |
---|---|---|---|
DB_TABLE_FIELD_CREATED | boolean | true | Make field "_created" |
DB_TABLE_FIELD_UPDATED | boolean | true | Make field "_updated" |
Functions
db_new(opt: Db_o): Db_s
Create new structure Db_s and connection with server
db_table(db: Db_s, opt: Db_table_opt): Db_table
Create new table model by fields
db_tables(db: Db_s):void
Create tables if they do not exist
db_table_rec(table: Db_table, data: Db_fields)
Get / make record in table
db_table_find(table: Db_table, filter: any, offset: Num_s):Array
Search records in table
| filter - orm filter (where)
About
Notes
- Start of development: 2018-10-18 07:50
- This project adheres to Semantic Versioning
- This project used Node-ORM