Files

83 lines
3.4 KiB
Go
Raw Permalink Normal View History

2026-04-08 21:43:35 +03:00
// Файл: internal/commands/commands.go
// Назначение: Реализация MongoDB-подобных команд CRUD и команд управления кластером.
// Добавлены команды для работы с индексами, ACL и ограничениями.
package commands
import (
"futriis/pkg/utils"
)
// ShowHelp отображает справку по всем доступным командам
func ShowHelp() {
helpText := `
=== FUTRIIS DATABASE COMMANDS ===
DATABASE MANAGEMENT:
use <db> - Switch to database
show dbs - List all databases
show collections - List collections in current database
COLLECTION OPERATIONS:
db.createCollection("<name>") - Create new collection
db.<collection>.insert({...}) - Insert document into collection
db.<collection>.find({_id: "..."}) - Find document by ID
db.<collection>.find() - Find all documents in collection
db.<collection>.findByIndex("<index>", "<value>") - Find by secondary index
db.<collection>.update({_id: "..."}, {...}) - Update document
db.<collection>.remove({_id: "..."}) - Delete document
INDEX MANAGEMENT:
db.<collection>.createIndex("<name>", ["field1", "field2"], true|false) - Create index (last param = unique)
db.<collection>.dropIndex("<name>") - Drop index
db.<collection>.listIndexes() - List all indexes
CONSTRAINTS:
db.<collection>.addRequired("<field>") - Add required field constraint
db.<collection>.addUnique("<field>") - Add unique constraint
db.<collection>.addMin("<field>", <value>) - Add minimum value constraint
db.<collection>.addMax("<field>", <value>) - Add maximum value constraint
db.<collection>.addEnum("<field>", [values]) - Add enum constraint
ACL MANAGEMENT:
acl createUser "<username>" "<password>" [roles] - Create new user
acl createRole "<rolename>" - Create new role
acl grant "<rolename>" "<permission>" - Grant permission to role
acl addUserRole "<username>" "<rolename>" - Add role to user
acl login "<username>" "<password>" - Login (returns session token)
acl logout - Logout current session
acl listUsers - List all users
acl listRoles - List all roles
TRANSACTIONS (MongoDB-like syntax):
session = db.startSession() - Start a new session
session.startTransaction() - Begin a transaction
session.commitTransaction() - Commit current transaction
session.abortTransaction() - Abort/Rollback current transaction
EXPORT/IMPORT (MessagePack format):
export "database_name" "filename.msgpack" - Export entire database
import "database_name" "filename.msgpack" - Import database from .msgpack file
CLUSTER MANAGEMENT:
cluster status - Show cluster status
cluster nodes - List all cluster nodes
cluster add <ip> <port> - Add node to cluster
cluster remove <node_id> - Remove node from cluster
cluster sync <db> <coll> - Sync collection across cluster
cluster replication-factor [n] - Get or set replication factor
cluster leader - Show cluster leader
cluster health - Check cluster health
HTTP API:
The database also exposes HTTP RESTful API on port 8080 (configurable)
See documentation for endpoints: /api/db/, /api/index/, /api/acl/, /api/constraint/
UTILITIES:
help - Show this help message
exit / quit - Exit database
`
utils.Println(helpText)
}