{"id":18449260,"url":"https://github.com/sqldef/node-sqldef","last_synced_at":"2025-10-07T04:34:45.944Z","repository":{"id":35807500,"uuid":"219107438","full_name":"sqldef/node-sqldef","owner":"sqldef","description":"Simple wrapper around sqldef for easy use with node","archived":false,"fork":false,"pushed_at":"2025-01-26T23:53:55.000Z","size":83,"stargazers_count":4,"open_issues_count":5,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-15T18:50:22.862Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://sqldef.github.io/","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sqldef.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-11-02T05:18:43.000Z","updated_at":"2025-01-26T23:53:58.000Z","dependencies_parsed_at":"2025-04-15T11:49:22.235Z","dependency_job_id":null,"html_url":"https://github.com/sqldef/node-sqldef","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sqldef/node-sqldef","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqldef%2Fnode-sqldef","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqldef%2Fnode-sqldef/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqldef%2Fnode-sqldef/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqldef%2Fnode-sqldef/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sqldef","download_url":"https://codeload.github.com/sqldef/node-sqldef/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqldef%2Fnode-sqldef/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260288827,"owners_count":22986743,"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-06T07:19:24.854Z","updated_at":"2025-10-07T04:34:40.912Z","avatar_url":"https://github.com/sqldef.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-sqldef\n\nSimple node wrapper around [sqldef](https://github.com/k0kubun/sqldef) for easy use with node.\n\nThis is a super-simple wrapper around [sqldef](https://github.com/k0kubun/sqldef) that will download the appropriate (for your platform/arch) CLI from [sqldef releases](https://github.com/k0kubun/sqldef/releases) and run it. It works with mysql \u0026 postgres.\n\nIf it's unclear how this might be usful in your workflow, just checkout [this live demo](https://sqldef.github.io/).\n\n## usage\n\nInstall it in your project as a dev-dependency, or use it standalone in [npx](https://www.npmjs.com/package/npx):\n\n```bash\nnpm i -D sqldef\n\n# or\n\nnpx sqldef --help\n```\n\n### Code\n\nYou can use it in your own code (like for migration scripts or whatever)\n\n```js\nimport sqldef from 'sqldef'\n\nconst main = async () =\u003e {\n  const output = await (sqldef({\n    type,         // the type of your database (\"mysql\" or \"postgres\")\n    database,     // the name of your database\n    user,         // the username of your database\n    password,     // the password of your database\n    host,         // the hostname of your database\n    port,         // the port of your database\n    socket,       // the unix socket (for mysql)\n    file,         // the schema file to read/write\n    dry: true,    // dry run - don't do anything to the database\n    get: true     // get the current definition from database\n  }))\n}\nmain()\n\n```\n\n### CLI\n\nUse it in your [npm scripts](https://docs.npmjs.com/cli/run-script).\n\n```\nUsage: sqldef \u003ccommand\u003e [options]\n\nCommands:\n  sqldef export  Export your database to a file\n  sqldef import  Import your database from a file\n\nOptions:\n  -?, --help        Show help                                          [boolean]\n  -f, --file        The schema file to import/export     [default: \"schema.sql\"]\n  -t, --type        The type of the database                  [default: \"mysql\"]\n  -h, --host        The host of the database              [default: \"localhost\"]\n  -d, --database    The name of the database                   [default: \"test\"]\n  -u, --user        The user of the database                   [default: \"root\"]\n  -P, --password    The password for the database                  [default: \"\"]\n  -p, --port        The port of the database\n  -s, --socket      The socket of the database (only for mysql)\n  -x, --no-confirm  Don't confirm before running the import/export     [boolean]\n  -v, --version     Show version number                                [boolean]\n\nExamples:\n  sqldef export --user=cool                 Save your current schema, from your\n  --password=mysecret                       mysql database, in schema.sql\n  --database=mydatabase\n  sqldef import --user=cool                 Save the structure from your currnet\n  --password=mysecret                       database in schema.sql\n  --database=mydatabase\n```\n\n#### configuration\n\nThis uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig), which gives us a lot of options for configuration, and your settings will be merged from all the things you setup.\n\n- a `sqldef` property in `package.json`\n- a `.sqldefrc` file in JSON or YAML format\n- a `.sqldefrc.json` file\n- a `.sqldefrc.yaml`, `.sqldefrc.yml`, or `.sqldefrc.js` file\n- a `sqldef.config.js` file exporting a JS object\n\n#### ideas\n\nHere are some cool ways to use this tool in your project.\n\n**development**\n\nMake a file called `schema.sql`, and make a `.sqldefrc` file with your settings. Make sure `.sqldefrc` is in your `.gitignore`, so you don't accidentally check-in your database secrets.\n\n**.sqldefrc**\n```yaml\ntype: mysql\nhost: localhost\ndatabase: test\nuser: root\npassword: root\nfile: schema.sql\n```\n\nMaybe also make a `.sqldefrc.example` to help your users set stuff up.\n\nNow you can run `npx sqldef import` to apply the schema in `schema.sql`, and `npx sqldef export` to put the current structure in the database from your `schema.sql`.\n\n**CI**\n\nLet's say you want to run it in CI with the schema in `schema.sql`. I recommend you use environment-variables to keep all the config in your CI settings:\n\n```sh\nDB_TYPE=mysql\nDB_HOST=mysqlhost.com\nDB_PWD=mysecretpassword\nDB_USER=root\n```\n\nNow, install as a dev-dependency in your project with `npm i -D sqldef`, and make a script in `package.json` for doing schema migration:\n\n```json\n{\n  \"scripts\": {\n    \"migrate\": \"sqldef import --file=schema.sql --type=$DB_TYPE --host=$DB_HOST --password=$DB_PWD --user=$DB_USER --no-confirm\",\n    \"schema\": \"sqldef export --file=schema.sql --type=$DB_TYPE --host=$DB_HOST --password=$DB_PWD --user=$DB_USER\"\n  }\n}\n```\n\nNow, configure your CI to execute `npm run migrate` when code gets checked in. You might want to keep the above `.sqldefrc` method (from above) for development. The configuration you setup there will override the `DB_` environment vars, so it should work pretty well together. If you are using environment variables for other things, you could also just use your environment, and set it all in once place (like `.env` using [dotenv](https://www.npmjs.com/package/dotenv).)\n\n## Releasing\n\n```\nnpm adduser\nnpm publish --access public\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsqldef%2Fnode-sqldef","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsqldef%2Fnode-sqldef","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsqldef%2Fnode-sqldef/lists"}