{"id":13600231,"url":"https://github.com/mylxsw/heimdall","last_synced_at":"2025-10-15T19:49:34.411Z","repository":{"id":62682614,"uuid":"321250759","full_name":"mylxsw/heimdall","owner":"mylxsw","description":"Heimdall is a tool to perform import, export, direct SQL query and format conversion on excel files. Currently supports json, yaml, markdown, csv, xlsx, html, sql ...","archived":false,"fork":false,"pushed_at":"2023-03-06T02:19:58.000Z","size":135,"stargazers_count":72,"open_issues_count":0,"forks_count":14,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-30T09:12:26.430Z","etag":null,"topics":["csv","export","sql","xlsx"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"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/mylxsw.png","metadata":{"files":{"readme":"README.en.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}},"created_at":"2020-12-14T06:09:16.000Z","updated_at":"2025-04-07T17:34:52.000Z","dependencies_parsed_at":"2023-07-13T06:11:05.819Z","dependency_job_id":null,"html_url":"https://github.com/mylxsw/heimdall","commit_stats":{"total_commits":76,"total_committers":1,"mean_commits":76.0,"dds":0.0,"last_synced_commit":"9e0d71d03a85a27079d83577e232950d5757c487"},"previous_names":["mylxsw/db-exporter","mylxsw/mysql-querier"],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/mylxsw/heimdall","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mylxsw%2Fheimdall","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mylxsw%2Fheimdall/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mylxsw%2Fheimdall/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mylxsw%2Fheimdall/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mylxsw","download_url":"https://codeload.github.com/mylxsw/heimdall/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mylxsw%2Fheimdall/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261397372,"owners_count":23152491,"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":["csv","export","sql","xlsx"],"created_at":"2024-08-01T18:00:32.966Z","updated_at":"2025-10-15T19:49:29.385Z","avatar_url":"https://github.com/mylxsw.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Heimdall [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n![MariaDB](https://img.shields.io/badge/MariaDB-003545?style=for-the-badge\u0026logo=mariadb\u0026logoColor=white) ![MySQL](https://img.shields.io/badge/mysql-%2300f.svg?style=for-the-badge\u0026logo=mysql\u0026logoColor=white) ![Go](https://img.shields.io/badge/go-%2300ADD8.svg?style=for-the-badge\u0026logo=go\u0026logoColor=white) \n\n[中文文档](./README.md)\n\nHeimdall is a tool to perform import, export, direct SQL query and format conversion on Excel files. Currently supports directly writing SQL to query and export Excel files, export data in MySQL database to files in various formats such as json, yaml, markdown, csv, xlsx, html, sql, etc., import xlsx or csv files to MySQL database and Xlsx, csv file format conversion, file splitting and other functions.\n\n## Command Line Options\n\n**heimdall** support below commands\n\n- **fly** (aka **query-file**) query data from input file using sql directly\n- **import** (aka **load**) data from xlsx or csv file to database table\n- **export** (aka **query**) SQL query results to various file formats\n- **convert** convert data from xlsx/csv to other formats: csv, json, yaml, xml, table, html, markdown, xlsx, plain, sql\n- **split** split a large Excel file into multiple small files, each containing a specified number of rows at most \n\n\n### fly/query-file\n\nUsing **fly/query-file** command, you can query data from input file using sql directly.\n\nEach input file is used as a table, and the naming format is **table_[serial number]**, starting from the first file, table_0, table_1, table_2 and so on.\n\n```bash\nheimdall fly --file data.csv --file data2.csv \\\n    --sql \"SELECT table_0.id 'ID', table_0.name '名称', table_0.created_at '创建时间', count(*) as '字段数量' FROM table_0 LEFT JOIN table_1 ON table_0.id = table_1.ref_id WHERE table_1.deleted_at = '' GROUP BY table_0.id ORDER BY count(*) DESC LIMIT 10\" \\\n    -f table\n```\n\nThe following command line options are supported：\n\n- **--sql value**, **-s value**, **--query value** SQL statement(if not set, read from STDIN, end with ';')\n- **--file value**, **-i value**, **--input value** *[ --file value, -i value, --input value ]* input excel or csv file path, you can use the form TABLE:FILE to specify the table name corresponding to the file, this flag can be specified multiple times for importing multiple files at the same time\n- **--csv-sepertor value** csv file sepertor, default is ',' (default: \",\")\n- **--format value**, **-f value** output format, support csv, json, yaml, xml, table, html, markdown, xlsx, plain, sql (default: \"table\")\n- **--output value**, **-o value** write output to a file, default output directly to STDOUT\n- **--no-header**, **-n** do not write table header (default: false)\n- **--query-timeout value**, **-t value** query timeout, when the stream option is specified, this option is invalid (default: 2m0s)\n- **--xlsx-max-row value** the maximum number of rows per sheet in an Excel file, including the row where the header is located (default: 1048576)\n- **--table value** when the format is sql, specify the table name\n- **--use-column-num** use column number as column name, start from 1, for example: col_1, col_2... (default: false)\n- **--show-tables** show all tables in the database (default: false)\n- **--temp-ds value** the temporary database uri, such as file:data.db?cache=shared, more options: https://www.sqlite.org/c3ref/open.html (default: \":memory:\")\n- **--slient** do not print warning log (default: false)\n- **--debug**, **-D** Debug mode (default: false)\n- **--beta** enable beta feature, when this flag is set, the loading performance for large excel file will be improved, may be unstable, use at your own risk\n\n### import/load\n\nUsing **import/load** command, you can import data from xlsx or csv file to a table.\n\n```bash\nheimdall import --tx --database example --table users \\\n    --file users.csv --file users.xlsx \\\n    --field 姓名:name \\\n    --field 年龄:age\n```\n\nThe following command line options are supported：\n\n- **--host value**, **-H value** MySQL host (default: \"127.0.0.1\")\n- **--port value**, **-P value** MySQL port (default: 3306)\n- **--user value**, **-u value** MySQL user (default: \"root\")\n- **--password value**, **-p value** MySQL password\n- **--database value**, **-d value** MySQL database\n- **--connect-timeout value** database connect timeout (default: 3s)\n- **--debug**, **-D** Debug mode (default: false)\n- **--file value**, **-i value**, **--input value** *[ --file value, -i value, --input value ]* input excel or csv file path, this flag can be specified multiple times for importing multiple files at the same time\n- **--table value**, **-t value** target table name\n- **--field value**, **-f value** *[ --field value, -f value ]* field map, eg: excel_field:db_field, this flag can be specified multiple times\n- **--include value**, **-I value** *[ --include value, -I value ]* include fields, if set, only these fields will be imported, this flag can be specified multiple times\n- **--exclude value**, **-E value** *[ --exclude value, -E value ]* exclude fields, if set, these fields will be ignored, this flag can be specified multiple times\n- **--csv-sepertor value** csv file sepertor, default is ',' (default: \",\")\n- **--tx**, **-T** import data using transaction, all success or all failure, only work with InnoDB or other engines that support transaction (default: false)\n- **--dry-run** perform import tests to verify correctness of imported files, but do not commit transactions, only work with InnoDB or other engines that support transaction (default: false)\n- **--create-table** automatically create table structure\n- **--use-column-num** Use column numbers as column names, starting from 1, such as col_1, col_2...\n- **--with-ts** When creating the table structure, automatically add the created_at field to identify the time of import\n- **--table-structure-format value** When this option is specified, the table structure information will be output after the import is complete, supporting `table`, `json`, `yaml`, `markdown`, `html`, `csv`, `xml` \n\n### export/query\n\nUsing **export/query** command, you can export SQL query results to various file formats. Currently, it supports JSON/YAML/Markdown/CSV/XLSX/HTML/text, etc. \n\n```bash\nheimdall export --database example --format json --sql 'select * from users'\n```\n\nThe following command line options are supported：\n\n- **--host value**, **-H value** MySQL host (default: \"127.0.0.1\")\n- **--port value**, **-P value** MySQL port (default: 3306)\n- **--user value**, **-u value** MySQL user (default: \"root\")\n- **--password value**, **-p value** MySQL password\n- **--database value**, **-d value** MySQL database\n- **--connect-timeout value** database connect timeout (default: 3s)\n- **--debug**, **-D** Debug mode (default: false)\n- **--sql value**, **-s value** SQL statement\n- **--format value**, **-f value** output format, support csv, json, yaml, xml, table, html, markdown, xlsx, plain, sql (default: \"csv\")\n- **--output value**, **-o value** write output to a file, default output directly to STDOUT\n- **--streaming**, **-S** whether to use streaming output, if using streaming output, it will not wait for the query to complete, but output line by line during the query process. The output format only supports csv/xlsx/json/plain/sql (default: false)\n- **--no-header**, **-n** do not write table header (default: false)\n- **--query-timeout value**, **-t value** query timeout, when the stream option is specified, this option is invalid (default: 2m0s)\n- **--xlsx-max-row value** the maximum number of rows per sheet in an Excel file, including the row where the header is located (default: 1048576)\n- **--table value** when the format is sql, specify the table name\n- **--help**, **-h** show help (default: false)\n\n### convert\n\nUsing **convert** command, you can convert data from xlsx/csv to other formats: csv, json, yaml, xml, table, html, markdown, xlsx, plain, sql.\n\n```bash\nheimdall convert --file data.csv --format json --include id --include name --include updated_at\n```\n\nThe following command line options are supported：\n\n- **--file value**, **-i value**, **--input value** input excel or csv file path\n- **--csv-sepertor value** csv file sepertor, default is ',' (default: \",\")\n- **--format value**, **-f value** output format, support csv, json, yaml, xml, table, html, markdown, xlsx, plain, sql (default: \"table\")\n- **--output value**, **-o value** write output to a file, default output directly to STDOUT\n- **--no-header, -n** do not write table header (default: false)\n- **--xlsx-max-row value** the maximum number of rows per sheet in an Excel file, including the row where the header is located (default: 1048576)\n- **--table value** when the format is sql, specify the table name\n- **--slient** do not print warning log (default: false)\n- **--debug, -D** Debug mode (default: false)\n- **--include value**, **-I value** *[ --include value, -I value ]* include fields, if set, only these fields will be output, this flag can be specified multiple times\n- **--exclude value**, **-E value** *[ --exclude value, -E value ]* exclude fields, if set, these fields will be ignored, this flag can be specified multiple times\n\n### split\n\nUsing **split** command, you can split a large Excel file into multiple small files, each containing a specified number of rows at most.\n\n```bash\nheimdall split --file data.xlsx --perfile-limit 1000 --header-row-num 2\n```\n\nThe following command line options are supported：\n\n- **--file value**, **-i value**, **--input value** input excel file path, currently only support xlsx format\n- **--slient** do not print warning log (default: false)\n- **--debug**, **-D** debug mode (default: false)\n- **--perfile-limit value**, **-p value** the maximum number of records per file, only valid when mode=row (default: 1000)\n- **--header-row-num value**, **-r value** table header row maximum row number, only valid when mode=row or mode=column (default: 1)\n- **--mode value**, **-m value** split method: row, column, sheet (default: \"row\")\n- **--column-index value**, **-c value** specifies the index of the column to split, such as 'A', 'AA', only valid when mode=column\n\n## Examples\n\nImport a xlsx file to database table \n\n```bash\nheimdall import --host 127.0.0.1 --port 3306 --database example --user root --password root \\\n    --table people \\\n    --field 区域:area \\ \n    --field 姓名:name \\\n    --field 身份证号码:idcard \\\n    --file ~/Downloads/data.xlsx\n```\n\nExport new businesses in the last 30 days to an Excel file\n\n```bash\nheimdall export --database example --host 127.0.0.1 --user root --password root \\\n      --sql \"SELECT id, name AS '企业名称', address AS '企业地址', city_name AS '城市', district_name AS '区县', DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') AS '创建时间' FROM enterprise WHERE created_at \u003e DATE_SUB(NOW(), INTERVAL 30 DAY) ORDER BY id DESC\" \\\n      --streaming \\\n      --format xlsx \\\n      --output 最近30天新增企业列表.xlsx\n```\n\nCompare two Excel files containing population data, traverse the person information in file-1.csv in file-2.xlsx according to the ID number, find the existing person, and output the information of these person\n\n```bash\nheimdall fly --beta \\\n    -i ./file-1.csv \\\n    -i ./file-2.xlsx  \\\n    --sql \"select xingming as '姓名', shenfenzhenghaoma as '身份证号码', shengri as '生日', xingbie as '性别', dizhi as '地址', lianxidianhua as '联系电话' from table_0 where table_0.shenfenzhenghaoma NOT IN (select IDCARDNO from table_1)\" \\\n    --format xlsx \\\n    --output diff.xlsx\n```\n\nThe exported data is deduplicated according to the ID number, and only one piece of data with the same ID number is kept\n\n```bash\nheimdall fly --beta \\\n    -i ./diff.xlsx \\\n    --sql \"select xingming as '姓名', shenfenzhenghaoma as '身份证号码', shengri as '生日', xingbie as '性别', dizhi as '地址', lianxidianhua as '联系电话' from table_0 where __rowid IN (SELECT max(__rowid) FROM table_0 GROUP BY shenfenzhenghaoma)\" \\\n    --format xlsx \\\n    --output diff-no-repeat.xlsx\n```\n\nSplit the Excel file into multiple Excel files according to the dimension of the first column A\n\n```bash\nheimdall split -i ./data.xlsx -m column -c A\n```\n\nSplit an Excel file into multiple files with up to 1000 rows of data each\n\n```bash\nheimdall split -m row --file data.xlsx --perfile-limit 1000 --header-row-num 2\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmylxsw%2Fheimdall","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmylxsw%2Fheimdall","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmylxsw%2Fheimdall/lists"}