{"id":21961833,"url":"https://github.com/trapcodeio/xpresser-db-config","last_synced_at":"2025-10-16T16:35:17.256Z","repository":{"id":57402166,"uuid":"418448743","full_name":"trapcodeio/xpresser-db-config","owner":"trapcodeio","description":"A database config plugin for xpresserjs","archived":false,"fork":false,"pushed_at":"2023-08-24T09:33:29.000Z","size":280,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-17T13:08:47.342Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trapcodeio.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-18T10:20:17.000Z","updated_at":"2023-09-03T09:00:32.000Z","dependencies_parsed_at":"2023-01-30T11:20:12.093Z","dependency_job_id":null,"html_url":"https://github.com/trapcodeio/xpresser-db-config","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trapcodeio%2Fxpresser-db-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trapcodeio%2Fxpresser-db-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trapcodeio%2Fxpresser-db-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trapcodeio%2Fxpresser-db-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trapcodeio","download_url":"https://codeload.github.com/trapcodeio/xpresser-db-config/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250506542,"owners_count":21441796,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-29T10:18:32.719Z","updated_at":"2025-10-16T16:35:12.224Z","avatar_url":"https://github.com/trapcodeio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Xpresser Db Config\n\n#### STILL IN DEVELOPMENT\n\nEvery app that connects to a database at some point saves some configuration data that should be modified by the\napplication.\n\nThis plugin makes that process easy for you.\n\n- Provide driver to use any Database.\n- Autoload configs in memory\n- AutoUpdate configs in realtime with changes.\n- Provide access functions to get configs.\n\n## Looks Like\n\nFile: db-config.js (Where default db configuration is defined)\n\n```javascript\nmodule.exports = [\n  // standalone configs\n  {\n    config: {\n      allowLogin: true,\n      backup: true,\n      cronjobs: false,\n    },\n    autoload: true,\n  },\n  // Grouped configs\n  {\n    group: 'app',\n    config: {\n      name: 'App Name',\n      slogan: 'App slogan',\n    },\n    autoload: true,\n  },\n];\n\n/// Will be saved to memory as.\n({\n  allowLogin: true,\n  backup: true,\n  cronjobs: false,\n  app: {\n    name: 'App Name',\n    slogan: 'App slogan',\n  },\n});\n\n/// Will be stored to your configured db as\n[\n  {key: 'allowLogin', value: true, type: 'boolean', autoload: true, ...},\n  {key: 'backup', value: true, type: 'boolean', autoload: true, ...},\n  {key: 'cronjobs', value: false, type: 'boolean', autoload: true, ...},\n  {group: 'app', key: 'key', value: 'App Name', type: 'string', autoload: true, ...},\n  {group: 'app', key: 'slogan', value: 'App Slogan', type: 'string', autoload: true, ...},\n];\n```\n\n### Getting/Setting configuration\n\n```javascript\nconst {getConfig, setConfig} = require(\"xpresser-db-config\");\n\nawait getConfig('app.name'); // App Name\nawait getConfig('app.slogan'); // App Slogan\n\nawait setConfig('app.name', \"New Name\");\n```\n\n\n##  Setup\nInstall `xpresser-db-config`\n\n```bash\nnpm i xpresser-db-config\n# or\nyarn add xpresser-db-config\n```\n\nAdd to your `plugins.json` before other plugins.\n**Note:** If you have a plugin that initializes database connection used by the db-config, add this plugin after it.\n\n```json\n{\n  \"npm://xpresser-db-config\": true\n}\n```\n\nAdd to your xpresser `config`.\n\n```js\n({\n    paths: {\n        // db-config declaration file\n        dbConfig: \"backend://db-config\",\n        // db-config driver\n        dbConfigClass: \"npm://xpresser-db-config/drivers/xpress-mongo/XpressMongoDbConfig\",\n        // db-config backup folder\n        dbConfigBackupFolder: \"base://storage/db-config-backup\",\n    }\n})\n```\n\nCreate `db-config.(js|ts)` file in your `backend` folder.\n\n```ts\nimport { defineDbConfig } from \"xpresser-db-config/src/functions\";\n\ntype Meta = {\n    title: string;\n    desc: string;\n    example?: any;\n    options?: Record\u003cany, any\u003e;\n};\n\nexport = defineDbConfig\u003cMeta\u003e(({ v }) =\u003e {\n    return [\n        {\n            // Active Providers Config\n            group: \"app\",\n            autoload: true,\n            config: {\n                name: \"My App Name\",\n\n                // Value with meta\n                slogan: v(\"We are the best\", {\n                    title: \"Slogan\",\n                    desc: \"This is the slogan of our app\"\n                })\n            }\n        }\n    ];\n});\n```\n\nAdd `extensions` to your `use-xjs-cli.json` file.\n\n```json\n{\n  \"extensions\": [\n    \"npm://xpresser-db-config\"\n  ]\n}\n```\n\nThe setup is complete!. \nNext, we need to migrate our configs to the database.\nRun the command below to migrate configs.\n\n```bash\nnpx xjs dbc:migrate\n```\n\nOther commands are below.\n\n## Commands\n\n```bash\n# Migrate configs to database\nnpx xjs dbc:migrate\n\n# Find config\nnpx dbc:find \u003cquery\u003e [format] \n\n# Set config\nnpx dbc:set \u003ckey\u003e \u003cvalue\u003e\n\n# Reset config\nnpx dbc:reset\n\n# Backup configs\nnpx dbc:backup\n\n# Restore configs\nnpx dbc:restore \u003cfile\u003e\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrapcodeio%2Fxpresser-db-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrapcodeio%2Fxpresser-db-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrapcodeio%2Fxpresser-db-config/lists"}