{"id":22972772,"url":"https://github.com/uh-zz/sqload","last_synced_at":"2025-09-12T18:19:32.525Z","repository":{"id":65833501,"uuid":"600310026","full_name":"uh-zz/sqload","owner":"uh-zz","description":"https://pkg.go.dev/github.com/uh-zz/sqload","archived":false,"fork":false,"pushed_at":"2023-02-12T13:39:31.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T06:44:26.641Z","etag":null,"topics":["go","mysqli","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uh-zz.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}},"created_at":"2023-02-11T04:48:52.000Z","updated_at":"2023-02-11T12:36:34.000Z","dependencies_parsed_at":"2023-02-20T21:00:59.553Z","dependency_job_id":null,"html_url":"https://github.com/uh-zz/sqload","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.052631578947368474","last_synced_commit":"9456d18fa8c8ae92d33e4f009e1b0be1ce9d8730"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/uh-zz/sqload","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uh-zz%2Fsqload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uh-zz%2Fsqload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uh-zz%2Fsqload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uh-zz%2Fsqload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uh-zz","download_url":"https://codeload.github.com/uh-zz/sqload/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uh-zz%2Fsqload/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265218750,"owners_count":23729528,"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":["go","mysqli","sql"],"created_at":"2024-12-14T23:19:23.109Z","updated_at":"2025-07-13T23:09:08.357Z","avatar_url":"https://github.com/uh-zz.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sqload\n\nsqload reads the SQL file embedded in the Go binary and converts the statements into a string slice.\n\nIt also checks that the statements it reads are valid.\n\n## Features\n\n- [x] Parse statment in MySQL\n- [x] Parse statment in PostgreSQL\n\n## Install\n\n```\ngo get github.com/uh-zz/sqload@latest\n```\n\n## Getting started\n\n### Pattern 1: Reading from a single file\n\n```\n.\n├── go.mod\n├── go.sum\n├── main.go\n└── sql\n    └── test.sql\n```\n\n`sql/test.sql`\n\n```sql\nINSERT INTO table001 (name,age) VALUES ('alice', 10);\n```\n\nYou can also add multiple sqls in the same file.\n\n```sql\nINSERT INTO table001 (name,age) VALUES ('alice', 10);\nINSERT INTO table001 (name,age) VALUES ('bob', 10);\n```\n\n`main.go`\n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"embed\"\n\t\"fmt\"\n\n\t\"github.com/uh-zz/sqload\"\n\t\"github.com/uh-zz/sqload/driver/mysql\"\n)\n\n//go:embed sql/*\nvar content embed.FS\n\nfunc main() {\n\tvar (\n\t\tbuf  bytes.Buffer // sql which read from file\n\t\tsqls []string // sql after parse\n\t)\n\n\tloader := sqload.New(mysql.Dialector{}) // for PostgreSQL: postgresql.Dialector{}\n\n\tif err := loader.Load(\u0026content, \u0026buf); err != nil {\n\t\tfmt.Printf(\"Load error: %s\", err.Error())\n\t}\n\n\tif err := loader.Parse(buf.String(), \u0026sqls); err != nil {\n\t\tfmt.Printf(\"Parse error: %s\", err.Error())\n\t}\n\n\tfmt.Printf(\"%+v\", sqls)\n    // [INSERT INTO table001 (name,age) VALUES ('alice', 10);]\n}\n```\n\n### Pattern 2: Reading from a multiple files\n\n```\n.\n├── go.mod\n├── go.sum\n├── main.go\n└── sql\n    ├── test.sql\n    └── test_other.sql\n```\n\n`sql/test.sql`\n\n```sql\nINSERT INTO table001 (name,age) VALUES ('alice', 10);\n```\n\n`sql/test_other.sql`\n\n```sql\nINSERT INTO table001 (name,age) VALUES ('bob', 10);\n```\n\n`main.go`\n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"embed\"\n\t\"fmt\"\n\n\t\"github.com/uh-zz/sqload\"\n\t\"github.com/uh-zz/sqload/driver/mysql\"\n)\n\n//go:embed sql/*\nvar content embed.FS\n\nfunc main() {\n\tvar (\n\t\tbuf  bytes.Buffer // sql which read from file\n\t\tsqls []string // sql after parse\n\t)\n\n\tloader := sqload.New(mysql.Dialector{}) // for PostgreSQL: postgresql.Dialector{}\n\n\tif err := loader.Load(\u0026content, \u0026buf); err != nil {\n\t\tfmt.Printf(\"Load error: %s\", err.Error())\n\t}\n\n\tif err := loader.Parse(buf.String(), \u0026sqls); err != nil {\n\t\tfmt.Printf(\"Parse error: %s\", err.Error())\n\t}\n\n\tfmt.Printf(\"%+v\", sqls)\n    // [INSERT INTO table001 (name,age) VALUES ('alice', 10); INSERT INTO table001 (name,age) VALUES ('bob', 20);]\n}\n```\n\nOr you can choose to load a file.\n\n`main.go`\n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"embed\"\n\t\"fmt\"\n\n\t\"github.com/uh-zz/sqload\"\n\t\"github.com/uh-zz/sqload/driver/mysql\"\n)\n\n//go:embed sql/*\nvar content embed.FS\n\nfunc main() {\n\tvar (\n\t\tbuf  bytes.Buffer // sql which read from file\n\t\tsqls []string // sql after parse\n\t)\n\n\tloader := sqload.New(mysql.Dialector{}) // for PostgreSQL: postgresql.Dialector{}\n\n\tif err := loader.LoadFrom(\u0026content, \u0026buf, \"sql/test.sql\"); err != nil {\n\t\tfmt.Printf(\"Load error: %s\", err.Error())\n\t}\n\n\tif err := loader.Parse(buf.String(), \u0026sqls); err != nil {\n\t\tfmt.Printf(\"Parse error: %s\", err.Error())\n\t}\n\n\tfmt.Printf(\"%+v\", sqls)\n    // [INSERT INTO table001 (name,age) VALUES ('alice', 10);]\n}\n```\n\n## Contributing\n\nGuidelines are being prepared, but Contributions are welcomed and greatly appreciated.\n\n## Todo\n\n- [ ] other dialect\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuh-zz%2Fsqload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuh-zz%2Fsqload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuh-zz%2Fsqload/lists"}