{"id":25936079,"url":"https://github.com/jojiiofficial/godbhelper","last_synced_at":"2026-05-13T02:13:02.371Z","repository":{"id":57511652,"uuid":"239154309","full_name":"JojiiOfficial/GoDBHelper","owner":"JojiiOfficial","description":"A useful database management API for Golang","archived":false,"fork":false,"pushed_at":"2020-02-28T23:40:23.000Z","size":70,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-22T10:01:13.120Z","etag":null,"topics":["database","dbutils","golang","golang-library","helpers","helpers-library","utils-library"],"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/JojiiOfficial.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":"2020-02-08T15:27:02.000Z","updated_at":"2020-02-28T23:40:14.000Z","dependencies_parsed_at":"2022-08-29T05:21:39.717Z","dependency_job_id":null,"html_url":"https://github.com/JojiiOfficial/GoDBHelper","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JojiiOfficial%2FGoDBHelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JojiiOfficial%2FGoDBHelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JojiiOfficial%2FGoDBHelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JojiiOfficial%2FGoDBHelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JojiiOfficial","download_url":"https://codeload.github.com/JojiiOfficial/GoDBHelper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241768273,"owners_count":20017129,"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":["database","dbutils","golang","golang-library","helpers","helpers-library","utils-library"],"created_at":"2025-03-04T01:50:04.777Z","updated_at":"2026-05-13T02:13:02.320Z","avatar_url":"https://github.com/JojiiOfficial.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoDBHelper\nA simple and lightweight orm library for golang\n\n# Features\n\n- Database [versioning](https://github.com/JojiiOfficial/GoDBHelper#versioning)/migrating\n- Executing prepared/named/normal statements easily with formatting strings (queries)\n- Easily switching between Databases (see [Driver](https://github.com/JojiiOfficial/GoDBHelper#driver))\n- All [sqlx](https://github.com/jmoiron/sqlx) functions\n\n### Driver\n- [Sqlite3](https://github.com/mattn/go-sqlite3)\n- [Sqlite3Encrypt](https://github.com/CovenantSQL/go-sqlite3-encrypt)\n- [MySQL](https://github.com/go-sql-driver/mysql)\n- [Postgres](https://github.com/lib/pq) (not completely supported yet)\n\n\n\n# Usage\nUse one of the following imports matching the driver you want to use.\u003cbr\u003e\nSqlite: `github.com/mattn/go-sqlite3`\u003cbr\u003e\nSqlite encrypt: `github.com/CovenantSQL/go-sqlite3-encrypt`\u003cbr\u003e\nMySQL: `github.com/go-sql-driver/mysql`\u003cbr\u003e\nPostgreSQL: `github.com/lib/pq`\u003cbr\u003e\n\n# Example\n\n### Connections\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\tdbhelper \"github.com/JojiiOfficial/GoDBHelper/\"\n\n\t//_ \"github.com/go-sql-driver/mysql\"\n\t//_ \"github.com/mattn/go-sqlite3\"\n\t//_ \"github.com/lib/pq\"\n\t//_ \"github.com/CovenantSQL/go-sqlite3-encrypt\"\n)\n\ntype testUser struct {\n\tID       int    `db:\"id\" orm:\"pk,ai\"`\n\tUsername string `db:\"username\"`\n\tPass     string `db:\"password\"`\n}\n\nfunc sqliteExample() {\n\tdb := connectToSqlite()\n\tif db == nil {\n\t\treturn\n\t}\n\tdefer db.DB.Close()\n\n\tdb.Exec(\"CREATE TABLE user (id int, username text, password text)\")\n\tdb.Exec(\"INSERT INTO user (id, username, password) VALUES (1,'will', 'iamsafe')\")\n\n\tvar user testUser\n\tdb.QueryRow(\u0026user, \"SELECT * FROM user\")\n\tfmt.Println(user.ID, \":\", user.Username, user.Pass)\n}\n\n\n//TestStruct an example for MySQL\ntype TestStruct struct {\n\tPkid      uint32    `db:\"pk_id\" orm:\"pk,ai,nn\"`\n\tName      string    `db:\"name\" orm:\"nn\"`\n\tAge       uint8     `db:\"age\" orm:\"nn\" default:\"1\"`\n\tEmail     string    `db:\"email\" orm:\"nn\"`\n\tCreatedAt time.Time `db:\"createdAt\" orm:\"nn\" default:\"now()\"`\n}\n\n//An example using mysql as database\nfunc mysqlExample(){\n\tdb := connectToMysql()\n\tif db == nil {\n\t\treturn\n\t}\n\tdefer db.DB.Close()\n\t\n\t//Create a Table from a struct. (CreateOption is optional)\n\terr = db.CreateTable(TestStruct{}, \u0026godbhelper.CreateOption{\n\t\t//Create table if not exists\n\t\tIfNotExists: true,\n\t\t//Use a different name for the table than 'TestStruct'\n\t\tTableName: \"TestDB\",\n\t})\n\t\n\ts1 := TestStruct{\n\t\tEmail: \"email@test.com\",\n\t\tName:  \"goDbHelper\",\n\t}\n\n\t//Insert s1 into the Database. If you want to automatically set the PKid field, you have to pass the address of s1!\n\tresultSet, err = db.Insert(\u0026s1, \u0026godbhelper.InsertOption{\n\t\t//Ignore 'age' to let the DB insert the default value (otherwise it would be 0)\n\t\tIgnoreFields: []string{\"age\"},\n\t\t//Automatically fill the PKid field in s1. Only works if the 'orm'-Tag contains 'pk' and 'ai' and the reference to s1 is passed\n\t\tSetPK:        true,\n\t})\n\n\t//Load the new entry into s2. Note that you have to set parseTime=True to read 'createdAt' in a time.Time struct\n\tvar s2 TestStruct\n\terr = db.QueryRow(\u0026s2, \"SELECT * FROM TestDB WHERE pk_id=?\", s1.Pkid)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t} else {\n\t\tfmt.Println(s2)\n\t}\n}\n\n//Connect to Mysql and return a DBhelper pointer\nfunc connectToMysql() *dbhelper.DBhelper {\n\tuser := \"dbUser\"\n\tpass := \"pleaseMakeItSafe\"\n\thost := \"localhost\"\n\tport := \"3306\"\n\tdatabase := \"test\"\n\tdb, err := dbhelper.NewDBHelper(dbhelper.Mysql).Open(user, pass, host, port, database, \"parseTime=True\")\n\tif err != nil {\n\t\tfmt.Fatal(err.Error())\n\t\treturn nil\n\t}\n\treturn db\n}\n\nfunc connectToSqlite() *dbhelper.DBhelper {\n\tdb, err := dbhelper.NewDBHelper(dbhelper.Sqlite).Open(\"test.db\")\n\tif err != nil {\n\t\tfmt.Fatal(err.Error())\n\t\treturn nil\n\t}\n\treturn db\n}\n\nfunc connectToSqliteEncrypt() *dbhelper.DBhelper {\n\t//Opens the encrypted test.db using 'passKEY' to decrypt it \n\tdb, err := dbhelper.NewDBHelper(dbhelper.SqliteEncrypted).Open(\"test.db\", \"passKEY\")\n\tif err != nil {\n\t\tfmt.Fatal(err.Error())\n\t\treturn nil\n\t}\n\treturn db\n}\n\n```\n### Migrating\nThe following codesnippet demonstrates, how you can integrate database migration to your applications\u003cbr\u003e\n\n```go\n//db is an instance of dbhelper.DBhelper\n\n//load sql queries from a .sql file\n//Queries loaded from this function (LoadQueries) are always version 0. The last argument ('0') specifies the order of the chains.\ndb.LoadQueries(\"chain1\", \"./test.sql\", 0)\n\n//Add sql queries manually\n//The order specifies the execution order of the queries. So in this case, chain1 would be loaded before chain2\ndb.AddQueryChain(dbhelper.QueryChain{\n\tOrder: 1,\n\tName: \"chain2\",\n\tQueries: []dbhelper.SQLQuery{\n\t\tdbhelper.SQLQuery{\n\t\t\tVersionAdded: 0,\n\t\t\tQueryString:  \"CREATE TABLE user (id int, username text, password text)\",\n\t\t},\n\t\tdbhelper.SQLQuery{\n\t\t\tVersionAdded: 0,\n\t\t\tQueryString:  \"INSERT INTO user (id, username, password) VALUES (?,?,?)\",\n\t\t\tParams:       []string{\"0\", \"admin\", \"lol123\"},\n\t\t},\n\t\t//added in a later version (version 0.1)\n\t\tdbhelper.SQLQuery{\n\t\t\tVersionAdded: 0.1,\n\t\t\tQueryString:  \"CREATE TABLE test1 (id int)\",\n\t\t},\n\t\t//added in a later version (version 0.21)\n\t\tdbhelper.SQLQuery{\n\t\t\tVersionAdded: 0.21,\n\t\t\tQueryString:  \"INSERT INTO test1 (id) VALUES (?),(?)\",\n\t\t\tParams:       []string{\"29\", \"1\"},\n\t\t},\n\t},\n})\n\n//runs the update\nerr := db.RunUpdate()\nif err != nil {\n\tfmt.Println(\"Err updating\", err.Error())\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjojiiofficial%2Fgodbhelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjojiiofficial%2Fgodbhelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjojiiofficial%2Fgodbhelper/lists"}