Files
Database/docs/ru/api-schema.md
2026-01-15 22:38:46 +03:00

36 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Schema API (RU)
Помощники для создания и обновления таблиц.
## Пример: create table
```java
import com.andrewkydev.database.schema.ColumnSpec;
import com.andrewkydev.database.schema.IndexSpec;
import com.andrewkydev.database.schema.TableSpec;
TableSpec table = TableSpec.builder("players")
.column(ColumnSpec.builder("id", "BIGINT").primaryKey(true).autoIncrement(true).nullable(false).build())
.column(ColumnSpec.builder("name", "VARCHAR(32)").nullable(false).build())
.index(new IndexSpec("players_name_idx", java.util.Arrays.asList("name"), false))
.build();
api.schema().createTable(table);
```
## Методы
```java
api.schema().createDatabase("primalix");
api.schema().dropDatabase("primalix");
api.schema().createTable(spec);
api.schema().dropTable("players");
api.schema().addColumn("players", ColumnSpec.builder("level", "INT").build());
api.schema().updateColumn("players", ColumnSpec.builder("level", "INT").nullable(false).build());
api.schema().dropColumn("players", "level");
api.schema().addIndex("players", new IndexSpec("players_name_idx", java.util.Arrays.asList("name"), false));
api.schema().dropIndex("players", "players_name_idx");
```
У всех методов есть async версии с `CompletableFuture`.