{"id":18770052,"url":"https://github.com/yaroslaff/sql-export","last_synced_at":"2026-04-07T18:31:59.758Z","repository":{"id":62973628,"uuid":"561399949","full_name":"yaroslaff/sql-export","owner":"yaroslaff","description":"Export SQL tables or queries to files in JSON or Markdown / YAML format. Mainly to use with static site generators like Hugo to generate content from database","archived":false,"fork":false,"pushed_at":"2024-01-25T13:44:35.000Z","size":36,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-03T14:35:49.065Z","etag":null,"topics":["content","export","file","files","frontmatter","generate","gohugo","hugo","json","mariadb","markdown","md","mysql","postgresql","save","sql","sqlite","sqlite3","static","yaml"],"latest_commit_sha":null,"homepage":"","language":"Go","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/yaroslaff.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-03T15:55:33.000Z","updated_at":"2025-12-28T04:48:06.000Z","dependencies_parsed_at":"2024-01-25T14:46:54.816Z","dependency_job_id":"c586bd1a-316a-4d1f-820c-70473d97912b","html_url":"https://github.com/yaroslaff/sql-export","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"6978d57a4bfd499ce7b13605d78b0e947cd81ce8"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/yaroslaff/sql-export","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Fsql-export","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Fsql-export/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Fsql-export/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Fsql-export/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yaroslaff","download_url":"https://codeload.github.com/yaroslaff/sql-export/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Fsql-export/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31524525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T16:28:08.000Z","status":"ssl_error","status_checked_at":"2026-04-07T16:28:06.951Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["content","export","file","files","frontmatter","generate","gohugo","hugo","json","mariadb","markdown","md","mysql","postgresql","save","sql","sqlite","sqlite3","static","yaml"],"created_at":"2024-11-07T19:17:55.996Z","updated_at":"2026-04-07T18:31:59.736Z","avatar_url":"https://github.com/yaroslaff.png","language":"Go","readme":"# SQL Export\nExport SQL tables or queries to file(s) in JSON/Markdown format. Mainly to use with static site generators like [Hugo](https://gohugo.io/).\n\n`sql-export` can generate thousands .md files with YAML frontmatter based on content from mysql database in few seconds.\n\nMySQL/MariaDB (default), PostgreSQL and SQLite3 databases are supported. For sqlite3 use filename as DBNAME.\n\n## Usage\n\n### Export SQL query to one JSON list or file\nFor brevity, we omit [database credentials](#database-credentials) in examples, assume it comes from environment or .env file\n\n~~~\n$ ./sql-export -q 'SELECT title, price FROM libro LIMIT 2'  \n[\n    {\n        \"price\": 170,\n        \"title\": \"GLI ARMAROLI MILANESI - I MISSAGLIA E LA LORO CASA. Notizie, documenti, ricordi. - Gelli J., Moretti G. - Hoepli, - 1903\"\n    },\n    {\n        \"price\": 38,\n        \"title\": \"LES FUSILS D\\u0026#039;INFANTERIE EUROPEENS A LA FIN DU XIX SIECLE. - Sor Daniel. - Crepin-Leblond, - 1972\"\n    }\n]\n~~~\n\nSurely, you can redirect to file:\n~~~\n$ ./sql-export -q 'SELECT title, price FROM libro LIMIT 2' \u003e /tmp/books.json\n~~~\n\n### Export SQL to many (one file per record) JSON files \nUse `-f json` and provide template to output filename `-o '/tmp/libro/{{.id}}.json'`.\n\n~~~\n$ ./sql-export -q 'SELECT id, title, price FROM libro' -f json -o '/tmp/libro/{{.id}}.json'\n$ cat /tmp/libro/123.json \n{\n    \"id\": 123,\n    \"price\": 45,\n    \"title\": \"ALLGEMEINE GESCHICHTE DER HANDFEUERWAFFEN. Eine Übersicht ihrer Entwickelung. Mit 123 Abbildungen und 4 Ubersichtstafeln. - Günther Reinhold. - Reprint Verlag, - 2001\"\n}\n~~~\n\n### Export SQL to many markdown files with YAML frontmatter \nUse `-f md` and provide template to output filename `-o '/tmp/libro/{{.id}}.md'`.\n\n~~~\n$ ./sql-export -q 'SELECT id, title, price FROM libro' -f md -o '/tmp/libro/{{.id}}.md'\n$ cat /tmp/libro/123.md \n---\nid: 123\nprice: 45\ntitle: ALLGEMEINE GESCHICHTE DER HANDFEUERWAFFEN. Eine Übersicht ihrer Entwickelung.\n    Mit 123 Abbildungen und 4 Ubersichtstafeln. - Günther Reinhold. - Reprint Verlag,\n    - 2001\n\n---\n~~~\n\n### Export SQL to many files with any custom template \nProvide output filename template (`-o`) and template (`--tpl`)\n\n~~~\n$ cat out-template.html \nid: {{.id}}\ntitle: {{.title}}\nprice: {{.price}}\n$ ./sql-export -q 'SELECT id, title, price FROM libro' -o '/tmp/libro/{{.id}}.txt' --tpl out-template.html \n$ cat /tmp/libro/123.txt \nid: 123\ntitle: ALLGEMEINE GESCHICHTE DER HANDFEUERWAFFEN. Eine Übersicht ihrer Entwickelung. Mit 123 Abbildungen und 4 Ubersichtstafeln. - Günther Reinhold. - Reprint Verlag, - 2001\nprice: 45\n~~~\n\n### Use JSON as input source (generate markdown files based on json)\n\nTo read dataset from JSON, just pass filename as `-q` parameter.\n\n~~~\n./sql-export -q libro.json -o '/tmp/libro/{{.id}}.md' -f md\n~~~\n\n\n## Options\n~~~\n$ ./sql-export --help\nUsage of ./sql-export:\n  -d string\n    \t$DBTYPE (default \"mysql\")\n  -f string\n    \tFormat: json or md (markdown with frontmatter) or template (default \"template\")\n  -h string\n    \t$DBHOST (default \"localhost\")\n  -n string\n    \t$DBNAME (default \"XXXXXX\")\n  -o string\n    \tOutput filename\n  -p string\n    \t$DBPASS (default \"XXXXXX\")\n  -port int\n    \t$DBPORT (default 3306)\n  -q string\n    \tSQL query or table name\n  -tpl string\n    \tTemplate input file\n  -u string\n    \t$DBUSER (default \"XXXXXX\")\n  -v\tverbose mode\n~~~\n\nYou may use table name as value to `-q`. `-q tableName` equals to `-q SELECT * FROM tableName`\n\n### Database credentials\n\n|value         |key      |environment |default value|\n|---           |---      |---         |---|\n|database type | `-d`    |`$DBTYPE`   | `mysql`|\n|database host | `-h`    |`$DBHOST`   | `localhost`|\n|database port | `-port` |`$DBPORT`   | 3306 or 5432 |\n|database user | `-u`    |`$DBUSER`   | current system user name |\n|database name | `-p`    |`$DBPASS`   |   |\n\nYou can use `.env` file:\n~~~\nDBUSER=xenon\nDBPASS=YouWillNotSeeMyRealPasswordHere\nDBHOST=localhost\nDBNAME=books\n~~~\n\n## Install/build\n\nThree different methods.\n\n### Releases\ndownload precompiled binary from https://github.com/yaroslaff/sql-export from [latest release](https://github.com/yaroslaff/sql-export/releases/latest) (if your arch is x86_64).\n\n### go install\nIf you have modern golang installed:\n~~~\ngo install github.com/yaroslaff/sql-export@latest\n~~~\n\nInstalled (default) to ~/go/bin/sql-export\n\n\n### clone and build from sources\n~~~\ngit clone https://github.com/yaroslaff/sql-export\ncd sql-export\ngo build\ncp sql-export /usr/local/bin\n~~~\n\n### Post-install test\nOptional quick post-install test with sqlite3 db from sample [Chinook database](https://github.com/lerocha/chinook-database):\n\n~~~\nwget https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite\nsql-export -n Chinook_Sqlite.sqlite -d sqlite3 -q Customer\n~~~\n\n## Benchmarking\nsql-export is written in Go, so it's very fast. I test on database with 57000+ records.\n\n|Test                                                            |time     |\n|---                                                             |---      |\n| Export 3 fields of 57k+ records to one (11Mb) json list        | 0.336s  |\n| Export all (40) fields of 57k+ records to one (92Mb) json list | 3.102s  |\n| Export 3 fields to 57k+ JSON files                             | 5.573s  |\n| Export 3 fields to 57k+ md/yaml files                          | 10.869s |\n| Export 3 fields to 57k+ custom template files                  | 4.321s  |\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaroslaff%2Fsql-export","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyaroslaff%2Fsql-export","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaroslaff%2Fsql-export/lists"}