{"id":13412198,"url":"https://github.com/lqs/sqlingo","last_synced_at":"2025-05-16T04:07:06.755Z","repository":{"id":33500322,"uuid":"158090599","full_name":"lqs/sqlingo","owner":"lqs","description":"💥 A lightweight DSL \u0026 ORM which helps you to write SQL in Go.","archived":false,"fork":false,"pushed_at":"2025-01-06T05:09:32.000Z","size":428,"stargazers_count":427,"open_issues_count":5,"forks_count":27,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-13T23:54:58.417Z","etag":null,"topics":["database","go","golang","mysql","orm","postgresql","sql-dsl","sqlbuilder","tidb"],"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/lqs.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":"2018-11-18T14:11:03.000Z","updated_at":"2025-05-08T11:20:53.000Z","dependencies_parsed_at":"2024-03-20T09:44:22.928Z","dependency_job_id":"457f5d3f-1264-477d-95d2-492660e5b03d","html_url":"https://github.com/lqs/sqlingo","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lqs%2Fsqlingo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lqs%2Fsqlingo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lqs%2Fsqlingo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lqs%2Fsqlingo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lqs","download_url":"https://codeload.github.com/lqs/sqlingo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254464897,"owners_count":22075571,"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","go","golang","mysql","orm","postgresql","sql-dsl","sqlbuilder","tidb"],"created_at":"2024-07-30T20:01:22.025Z","updated_at":"2025-05-16T04:07:01.745Z","avatar_url":"https://github.com/lqs.png","language":"Go","funding_links":[],"categories":["Database","Generators","数据库  `go语言实现的数据库`","Data Integration Frameworks","数据库","Uncategorized"],"sub_categories":["SQL Query Builders","Advanced Console UIs","SQL 查询语句构建库","SQL查询生成器"],"readme":"\u003cimg src=\"https://raw.githubusercontent.com/lqs/sqlingo/master/logo.png\" width=\"236\" height=\"106\"\u003e\n\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)\n[![go.dev](https://img.shields.io/badge/go.dev-reference-007d9c)](https://pkg.go.dev/github.com/lqs/sqlingo?tab=doc)\n[![Travis CI](https://api.travis-ci.com/lqs/sqlingo.svg?branch=master)](https://app.travis-ci.com/github/lqs/sqlingo)\n[![Go Report Card](https://goreportcard.com/badge/github.com/lqs/sqlingo)](https://goreportcard.com/report/github.com/lqs/sqlingo)\n[![codecov](https://codecov.io/gh/lqs/sqlingo/branch/master/graph/badge.svg)](https://codecov.io/gh/lqs/sqlingo)\n[![MIT license](http://img.shields.io/badge/license-MIT-9d1f14)](http://opensource.org/licenses/MIT)\n[![last commit](https://img.shields.io/github/last-commit/lqs/sqlingo.svg)](https://github.com/lqs/sqlingo/commits)\n\n**sqlingo** is a SQL DSL (a.k.a. SQL Builder or ORM) library in Go. It generates code from the database and lets you write SQL queries in an elegant way.\n\n\u003cimg src=\"https://lqs-public-us-west.oss-us-west-1.aliyuncs.com/sqlingo/demo2.gif\" width=\"443\" height=\"297\"\u003e\n\n## Features\n* Auto-generating DSL objects and model structs from the database so you don't need to manually keep things in sync\n* SQL DML (SELECT / INSERT / UPDATE / DELETE) with some advanced SQL query syntaxes\n* Many common errors could be detected at compile time\n* Your can use the features in your editor / IDE, such as autocompleting the fields and queries, or finding the usage of a field or a table\n* Context support\n* Transaction support\n* Interceptor support\n* Golang time.Time is supported now, but you can still use the string type by adding `-timeAsString` when generating the model\n\n## Database Support Status\n| Database    | Status       |\n------------- | --------------\n| MySQL       | stable       |\n| PostgreSQL  | experimental |\n| SQLite      | experimental |\n\n## Tutorial\n\n### Install and use sqlingo code generator\nThe first step is to generate code from the database. In order to generate code, sqlingo requires your tables are already created in the database.\n\n```\n$ go install github.com/lqs/sqlingo/sqlingo-gen-mysql@latest\n$ mkdir -p generated/sqlingo\n$ sqlingo-gen-mysql root:123456@/database_name \u003egenerated/sqlingo/database_name.dsl.go\n```\n\n\n### Write your application\nHere's a demonstration of some simple \u0026 advanced usage of sqlingo.\n```go\npackage main\n\nimport (\n    \"github.com/lqs/sqlingo\"\n    . \"./generated/sqlingo\"\n)\n\nfunc main() {\n    db, err := sqlingo.Open(\"mysql\", \"root:123456@/database_name\")\n    if err != nil {\n        panic(err)\n    }\n\n    // a simple query\n    var customers []*CustomerModel\n    db.SelectFrom(Customer).\n        Where(Customer.Id.In(1, 2)).\n    \tOrderBy(Customer.Name.Desc()).\n        FetchAll(\u0026customers)\n\n    // query from multiple tables\n    var customerId int64\n    var orderId int64\n    err = db.Select(Customer.Id, Order.Id).\n        From(Customer, Order).\n        Where(Customer.Id.Equals(Order.CustomerId), Order.Id.Equals(1)).\n        FetchFirst(\u0026customerId, \u0026orderId)\n    \n    // subquery and count\n    count, err := db.SelectFrom(Order)\n        Where(Order.CustomerId.In(db.Select(Customer.Id).\n            From(Customer).\n            Where(Customer.Name.Equals(\"Customer One\")))).\n    \tCount()\n        \n    // group-by with auto conversion to map\n    var customerIdToOrderCount map[int64]int64\n    err = db.Select(Order.CustomerId, f.Count(1)).\n    \tFrom(Order).\n    \tGroupBy(Order.CustomerId).\n    \tFetchAll(\u0026customerIdToOrderCount)\n    if err != nil {\n    \tprintln(err)\n    }\n    \n    // insert some rows\n    customer1 := \u0026CustomerModel{name: \"Customer One\"}\n    customer2 := \u0026CustomerModel{name: \"Customer Two\"}\n    _, err = db.InsertInto(Customer).\n        Models(customer1, customer2).\n        Execute()\n    \n    // insert with on-duplicate-key-update\n    _, err = db.InsertInto(Customer).\n    \tFields(Customer.Id, Customer.Name).\n    \tValues(42, \"Universe\").\n    \tOnDuplicateKeyUpdate().\n    \tSet(Customer.Name, Customer.Name.Concat(\" 2\")).\n    \tExecute()\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flqs%2Fsqlingo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flqs%2Fsqlingo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flqs%2Fsqlingo/lists"}