{"id":15156342,"url":"https://github.com/lempiy/sqlite3createtableparser","last_synced_at":"2025-07-23T23:42:07.506Z","repository":{"id":40424757,"uuid":"137077077","full_name":"lempiy/Sqlite3CreateTableParser","owner":"lempiy","description":":scroll: Advanced PRAGMA table_info through DDL parsing","archived":false,"fork":false,"pushed_at":"2022-05-10T08:43:33.000Z","size":10,"stargazers_count":6,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-09-27T19:04:06.849Z","etag":null,"topics":["create","golang","parser","sqlite","table"],"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/lempiy.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}},"created_at":"2018-06-12T13:38:24.000Z","updated_at":"2023-10-08T09:17:15.000Z","dependencies_parsed_at":"2022-08-09T20:10:10.734Z","dependency_job_id":null,"html_url":"https://github.com/lempiy/Sqlite3CreateTableParser","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lempiy%2FSqlite3CreateTableParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lempiy%2FSqlite3CreateTableParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lempiy%2FSqlite3CreateTableParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lempiy%2FSqlite3CreateTableParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lempiy","download_url":"https://codeload.github.com/lempiy/Sqlite3CreateTableParser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219868598,"owners_count":16555871,"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":["create","golang","parser","sqlite","table"],"created_at":"2024-09-26T19:04:08.269Z","updated_at":"2024-10-10T07:40:28.938Z","avatar_url":"https://github.com/lempiy.png","language":"Go","readme":"# Sqlite3CreateTableParser\n:scroll: Advanced ~~PRAGMA~~ table_info through DDL parsing\n\n\n## GOLANG port of [C library](https://github.com/marcobambini/sqlite-createtable-parser) done by\n[@marcobambini](https://github.com/marcobambini).\n\n\n## SQLite CREATE TABLE parser\nA parser for sqlite create table sql statements.\n\nSQLite is a very powerful software but it lacks an easy way to extract complete information about table and columns constraints. The built-in sql pragma:\n```c\nPRAGMA schema.table_info(table-name);\nPRAGMA foreign_key_list(table-name);\n```\nprovide incomplete information and a manual parsing is required in order to extract more useful information.\n\nCREATE TABLE syntax diagrams can be found on the official [sqlite website](http://www.sqlite.org/lang_createtable.html).\n\n\n## Usage\n\n```go\npackage main\n\nimport \"github.com/lempiy/Sqlite3CreateTableParser/parser\"\n\n//some fancy DDL\nconst ddl = `\nCREATE TABLE contact_groups (\n contact_id integer,\n group_id integer,\n PRIMARY KEY (contact_id, group_id),\n FOREIGN KEY (contact_id) REFERENCES contacts (contact_id)\n ON DELETE CASCADE ON UPDATE NO ACTION,\n FOREIGN KEY (group_id) REFERENCES groups (group_id)\n ON DELETE CASCADE ON UPDATE NO ACTION\n);\n`\n\nfunc main() {\n    table, errCode := parser.ParseTable(sql, 0)\n    if errCode != parser.ERROR_NONE {\n        panic(\"Error during parsing sql\")\n    }\n    // do stuff with received data\n    fmt.Printf(\"%+v\\n\", table)\n}\n```\n\n\n## Table info structs\n```go\ntype Table struct {\n\tName           string\n\tSchema         string\n\tIsTemporary    bool\n\tIsIfNotExists  bool\n\tIsWithoutRowid bool\n\tNumColumns     int\n\tColumns        []Column\n\tNumConstraint  int\n\tConstraints    []TableConstraint\n}\n\ntype Column struct {\n\tName                  string\n\tType                  string\n\tLength                string\n\tConstraintName        string\n\tIsPrimaryKey          bool\n\tIsAutoincrement       bool\n\tIsNotnull             bool\n\tIsUnique              bool\n\tPkOrder               OrderClause\n\tPkConflictClause      ConflictClause\n\tNotNullConflictClause ConflictClause\n\tUniqueConflictClause  ConflictClause\n\tCheckExpr             string\n\tDefaultExpr           string\n\tCollateName           string\n\tForeignKeyClause      *ForeignKey\n}\n\ntype TableConstraint struct {\n\tType             ConstraintType\n\tName             string\n\tNumIndexed       int\n\tIndexedColumns   []IdxColumn\n\tConflictClause   ConflictClause\n\tCheckExpr        string\n\tForeignKeyNum    int\n\tForeignKeyName   []string\n\tForeignKeyClause *ForeignKey\n}\n\ntype ForeignKey struct {\n\tTable      string\n\tNumColumns int\n\tColumnName []string\n\tOnDelete   FkAction\n\tOnUpdate   FkAction\n\tMatch      string\n\tDeferrable FkDefType\n}\n\ntype IdxColumn struct {\n\tName        string\n\tCollateName string\n\tOrder       OrderClause\n}\n```\n\n\n## Limitations\n- CREATE TABLE AS select-stmt syntax is not supported (SQL3ERROR_UNSUPPORTEDSQL is returned).\n- EXPRESSIONS in column constraints (CHECK and DEFAULT constraint) and table constraint (CHECK constraint) are not supported (SQL3ERROR_UNSUPPORTEDSQL is returned).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flempiy%2Fsqlite3createtableparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flempiy%2Fsqlite3createtableparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flempiy%2Fsqlite3createtableparser/lists"}