docs/Management/Development and Configuration/Datapack/Database.md
ehrumsey 819839a761 vault backup: 2025-03-30 01:02:10
Affected files:
Management/Development and Configuration/Datapack/Database.md
2025-03-30 01:02:10 -05:00

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[]
}
...
}
}
...
}
}
}
```