{"id":14974003,"url":"https://github.com/fonini/dsn-parser","last_synced_at":"2025-10-27T05:31:24.818Z","repository":{"id":57216749,"uuid":"85116678","full_name":"fonini/dsn-parser","owner":"fonini","description":"Parse and create database connection strings fluently.","archived":false,"fork":false,"pushed_at":"2020-04-23T11:21:09.000Z","size":9,"stargazers_count":3,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T02:41:22.974Z","etag":null,"topics":["database","dsn","mysql","parser","pgsql"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/fonini.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":"2017-03-15T20:15:13.000Z","updated_at":"2020-04-23T11:21:11.000Z","dependencies_parsed_at":"2022-08-28T21:00:53.660Z","dependency_job_id":null,"html_url":"https://github.com/fonini/dsn-parser","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fonini%2Fdsn-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fonini%2Fdsn-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fonini%2Fdsn-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fonini%2Fdsn-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fonini","download_url":"https://codeload.github.com/fonini/dsn-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238445830,"owners_count":19473820,"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":["database","dsn","mysql","parser","pgsql"],"created_at":"2024-09-24T13:49:48.564Z","updated_at":"2025-10-27T05:31:19.459Z","avatar_url":"https://github.com/fonini.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"DSN Parser for Node\n===================\n\nParse and create database connection strings fluently.\n\n## Use case\n\nI've setup a node app on [Heroku](https://www.heroku.com) and added a PostgreSQL database. Heroku provides the database credentials\nas an enviroment variable with the following form: `pgsql://user:pass@127.0.0.1:5432/my_db`. \n\nI needed to parse it to the following way, in order to use with [node-postgres](https://github.com/brianc/node-postgres) package:\n\n````js\nvar config = new DSNParser(process.env.HEROKU_POSTGRESQL_COPPER_URL).getParts();\n\nvar pool = new pg.Pool(config);\n````\n\n## Installation\n\n`npm install dsn-parser`\n\n## Usage\n\n### Parse Data Source Name\n\n````js\nvar DSNParser = require('dsn-parser');\n\nvar dsn = new DSNParser('pgsql://user:pass@127.0.0.1:5432/my_db?sslmode=verify-full\u0026application_name=myapp');\ndsn.getParts();\n\n/*\n{ \n  driver: 'pgsql',\n  user: 'user',\n  password: 'pass',\n  host: '127.0.0.1',\n  port: 5432,\n  database: 'my_db',\n  params: { sslmode: 'verify-full', application_name: 'myapp' } \n} */\n\ndsn.get('database'); // my_db\ndsn.get('host'); // 127.0.0.1\n\ndsn.set('driver', 'mysql');\ndsn.set('user', 'root');\ndsn.set('password', null);\ndsn.set('port', 3306);\ndsn.set('params', null);\n\ndsn.getDSN();\n// mysql://root@127.0.0.1:3306/my_db\n\n````\n\n### Build new DSN\n\n````js\nvar DSNParser = require('dsn-parser');\n\nvar dsn = new DSNParser();\n\ndsn.set('driver', 'mysql')\n\t.set('user', 'root')\n\t.set('password', 'mypass')\n\t.set('host', 'localhost')\n\t.set('port', 3306)\n\t.set('database', '7gh4d78sh2')\n\t.set('params', {\n\t\tcharset: 'utf8',\n\t\tstrict: true\n\t});\n\ndsn.getDSN();\n\n// mysql://root:mypass@localhost:3306/7gh4d78sh2?charset=utf8\u0026strict=true\n````\n\n## Run tests\n\n`npm test`\n\n## Author\n\n#### Jonnas Fonini\n\n- https://fonini.github.io\n\n## License\n[![Licensed under the WTFPL](http://www.wtfpl.net/wp-content/uploads/2012/12/wtfpl-badge-2.png \"Licensed under the WTFPL\")](http://www.wtfpl.net)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffonini%2Fdsn-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffonini%2Fdsn-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffonini%2Fdsn-parser/lists"}