/* * Copyright 2026 Safronov Grigorii * * Licensed under the CDDL, Version 1.0 (the "License"); * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * https://opensource.org/licenses/CDDL-1.0 */ // Файл: internal/commands/commands.go // Назначение: Реализация MongoDB-подобных команд CRUD и команд управления кластером. // Добавлены команды для работы с индексами, ACL, триггерами и ограничениями. package commands import ( "futriis/pkg/utils" ) // ShowHelp отображает справку по всем доступным командам func ShowHelp() { helpText := ` === FUTRIIS DATABASE COMMANDS === DATABASE MANAGEMENT: use - Switch to database show dbs - List all databases show collections - List collections in current database COLLECTION OPERATIONS: db.createCollection("") - Create new collection db..insert({...}) - Insert document into collection db..find({_id: "..."}) - Find document by ID db..find() - Find all documents in collection db..findByIndex("", "") - Find by secondary index db..update({_id: "..."}, {...}) - Update document db..remove({_id: "..."}) - Delete document INDEX MANAGEMENT: db..createIndex("", ["field1", "field2"], true|false) - Create index (last param = unique) db..dropIndex("") - Drop index db..listIndexes() - List all indexes CONSTRAINTS: db..addRequired("") - Add required field constraint db..addUnique("") - Add unique constraint db..addMin("", ) - Add minimum value constraint db..addMax("", ) - Add maximum value constraint db..addEnum("", [values]) - Add enum constraint TRIGGERS (MongoDB-like syntax): db..createTrigger("", "", { condition: { field: "", operator: "", value: }, action: "", operations: [ { type: "set", field: "", value: "" }, { type: "inc", field: "", value: }, { type: "currentDate", field: "" } ] }) Events: BEFORE_INSERT, AFTER_INSERT, BEFORE_UPDATE, AFTER_UPDATE, BEFORE_DELETE, AFTER_DELETE Actions: abort (cancel operation), skip (skip operation), modify (modify document), log (write to log), notify (send notification) Special values: $$NOW (current timestamp), $$USER (current user), $$ROLE (current role) db..dropTrigger("") - Drop trigger db..listTriggers() - List all triggers on collection db..enableTrigger("") - Enable trigger db..disableTrigger("") - Disable trigger db.getTriggerLog() - Show trigger execution log TRIGGER EXAMPLES: // Auto-set updated_at timestamp on every update db.users.createTrigger("update_timestamp", "BEFORE_UPDATE", { action: "modify", operations: [{ type: "set", field: "updated_at", value: "$$NOW" }] }) // Prevent deletion of active users db.users.createTrigger("protect_active", "BEFORE_DELETE", { condition: { field: "status", operator: "eq", value: "active" }, action: "abort" }) // Log all inserts db.orders.createTrigger("audit_log", "AFTER_INSERT", { action: "log", description: "Log all order creations" }) // Increment counter on document insert db.stats.createTrigger("inc_counter", "AFTER_INSERT", { action: "modify", operations: [{ type: "inc", field: "counter", value: 1 }] }) ACL MANAGEMENT: acl createUser "" "" [roles] - Create new user acl createRole "" - Create new role acl grant "" "" - Grant permission to role acl addUserRole "" "" - Add role to user acl login "" "" - 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 - Add node to cluster cluster remove - Remove node from cluster cluster sync - 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/, /api/trigger/ UTILITIES: help - Show this help message exit / quit - Exit database ` utils.Println(helpText) }