50 lines
950 B
Markdown
50 lines
950 B
Markdown
---
|
|
title: Database
|
|
draft: "false"
|
|
---
|
|
# Creating a Schema
|
|
```ts
|
|
@add(this.schema)
|
|
function tables.myTable() {
|
|
createTable(myTable, name);
|
|
|
|
createField(myTable, id, int, [pk, un]);
|
|
createField(myTable, name, string, [fk, un]);
|
|
createField(myTable, description, string, []);
|
|
|
|
finishTable(myTable); // Runs checks, such as existence of pk
|
|
}
|
|
```
|
|
# Data Structure
|
|
```json
|
|
{
|
|
database: {
|
|
tables: {
|
|
$table: {
|
|
lock: bool, // locked tables cannot be accessed by queries
|
|
name: string, // $name
|
|
fields: string[], // $field
|
|
pk: string, // $field
|
|
fk: string[], // $field (optional)
|
|
un: string[], // $field
|
|
rq: string[], // $filed (optional)
|
|
data: {
|
|
$field: {
|
|
name: string, // $field
|
|
type: string, // $type
|
|
props: { // these are parsed from props array
|
|
pk: bool,
|
|
fk: bool,
|
|
un: bool,
|
|
rq: bool,
|
|
},
|
|
content: any[]
|
|
}
|
|
...
|
|
}
|
|
}
|
|
...
|
|
}
|
|
}
|
|
}
|
|
``` |