/
uzer_007
/
Rixea
Обзор
Документация
Войти
/
uzer_007
/
Rixea
Код
Запросы
0
Задачи
Вики
Пакеты
5
Релизы
2
CI/CD
Аналитика
Безопасность
master
modules/setting/database.go
100 строк
3 KB
uzer_007
feat: первая версия Rixea
02 авг 2026, 22:16
02 авг 2026, 22:16
d4f7504
Код
Авторство
О чём код?
// Copyright 2026 Uzer_007. All rights reserved. // SPDX-License-Identifier: MIT package setting import ( "time" ) var ( unsupportedSQLDatabaseSettings = []string{ "AUTO_MIGRATION", "CHARSET_COLLATION", "CONN_MAX_LIFETIME", "ITERATE_BUFFER_SIZE", "LOG_SQL", "MAX_IDLE_CONNS", "MAX_OPEN_CONNS", "PATH", "SCHEMA", "SLOW_QUERY_THRESHOLD", "SQLITE_JOURNAL_MODE", "SQLITE_TIMEOUT", } // SupportedDatabaseTypes contains production database backends supported by this fork. SupportedDatabaseTypes = []string{"reindexer"} // DatabaseTypeNames contains the friendly names for all database types DatabaseTypeNames = map[string]string{"reindexer": "Reindexer"} // Database holds the database settings Database = struct { Type DatabaseType Host string Name string User string Passwd string SSLMode string ReindexerPoolSize int ReindexerNetCompression bool ReindexerLoginTimeout time.Duration ReindexerRequestTimeout time.Duration ReindexerReadRetries int ReindexerWriteRetries int ReindexerCreateDatabase bool ReindexerObjectCacheBudget int ReindexerSchemaWorkers int ReindexerMutationBatchSize int DBConnectRetries int DBConnectBackoff time.Duration }{} ) // LoadDBSetting loads the database settings func LoadDBSetting() { loadDBSetting(CfgProvider) } func loadDBSetting(rootCfg ConfigProvider) { sec := rootCfg.Section("database") unsupportedSettings( rootCfg, "database", unsupportedSQLDatabaseSettings, "Используйте параметры REINDEXER_*; схема и миграции Reindexer применяются автоматически.", ) Database.Type = DatabaseType(sec.Key("DB_TYPE").String()) Database.Host = sec.Key("HOST").String() Database.Name = sec.Key("NAME").String() Database.User = sec.Key("USER").String() Database.Passwd = sec.Key("PASSWD").String() Database.SSLMode = sec.Key("SSL_MODE").MustString("disable") Database.ReindexerPoolSize = sec.Key("REINDEXER_POOL_SIZE").MustInt(0) Database.ReindexerNetCompression = sec.Key("REINDEXER_NET_COMPRESSION").MustBool(false) Database.ReindexerLoginTimeout = sec.Key("REINDEXER_LOGIN_TIMEOUT").MustDuration(5 * time.Second) Database.ReindexerRequestTimeout = sec.Key("REINDEXER_REQUEST_TIMEOUT").MustDuration(15 * time.Second) Database.ReindexerReadRetries = sec.Key("REINDEXER_READ_RETRIES").MustInt(2) Database.ReindexerWriteRetries = sec.Key("REINDEXER_WRITE_RETRIES").MustInt(0) Database.ReindexerCreateDatabase = sec.Key("REINDEXER_CREATE_DATABASE").MustBool(true) Database.ReindexerObjectCacheBudget = sec.Key("REINDEXER_OBJECT_CACHE_BUDGET").MustInt(2 * 1024 * 1024) Database.ReindexerSchemaWorkers = sec.Key("REINDEXER_SCHEMA_WORKERS").MustInt(0) Database.ReindexerMutationBatchSize = sec.Key("REINDEXER_MUTATION_BATCH_SIZE").MustInt(256) if Database.ReindexerMutationBatchSize <= 0 { Database.ReindexerMutationBatchSize = 256 } Database.DBConnectRetries = sec.Key("DB_RETRIES").MustInt(10) Database.DBConnectBackoff = sec.Key("DB_RETRY_BACKOFF").MustDuration(3 * time.Second) } type DatabaseType string const DatabaseTypeReindexer DatabaseType = "reindexer" func (t DatabaseType) IsReindexer() bool { return t == DatabaseTypeReindexer }