{"id":20663570,"url":"https://github.com/yanun0323/sutando","last_synced_at":"2025-04-19T15:55:24.454Z","repository":{"id":59043530,"uuid":"527800837","full_name":"yanun0323/sutando","owner":"yanun0323","description":"A simple go ORM framework for mongoDB.","archived":false,"fork":false,"pushed_at":"2024-12-03T12:44:56.000Z","size":1250,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T09:41:55.657Z","etag":null,"topics":["go","golang","golang-library","golang-package","mongo","mongodb","orm","orm-framework"],"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/yanun0323.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}},"created_at":"2022-08-23T02:14:57.000Z","updated_at":"2024-12-03T12:45:00.000Z","dependencies_parsed_at":"2023-12-12T13:44:48.207Z","dependency_job_id":"7307c241-1f24-4f4c-8d5f-49c4f01adb61","html_url":"https://github.com/yanun0323/sutando","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanun0323%2Fsutando","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanun0323%2Fsutando/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanun0323%2Fsutando/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanun0323%2Fsutando/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanun0323","download_url":"https://codeload.github.com/yanun0323/sutando/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249731218,"owners_count":21317341,"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","golang","golang-library","golang-package","mongo","mongodb","orm","orm-framework"],"created_at":"2024-11-16T19:18:42.484Z","updated_at":"2025-04-19T15:55:24.448Z","avatar_url":"https://github.com/yanun0323.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca href=\".\"\u003e\u003cimg height=\"200\" src=\"./document/sutando.png\"\u003e\u003c/a\u003e\n\n## Requirement\n\n_Required go 1.18 up_\n\n## Query Parameters\n\n- Exists\n- And\n- Equal\n- NotEqual\n- Greater\n- GreaterOrEqual\n- Less\n- LessOrEqual\n- Contain\n- In\n- NotIn\n- Sort\n- Limit\n- Skip\n- Count\n- Regex\n\n## Guide\n\n### Installation\n\n```shell\n$ go get -u github.com/yanun0323/sutando@latest\n```\n\n### Example\n\n#### Connect To MongoDB\n\n- Create a new connection\n\n```go\n    // connect through host and port.\n    db, err := sutando.NewDB(ctx, sutando.Conn{\n    \tUsername:  \"example\",\n    \tPassword:  \"example\",\n    \tHost:      \"example\",\n    \tPort:      27017,\n    \tDB:        \"example\",\n    \tAdminAuth: true,\n    \tPem:       \"\",\n    \tClientOptionsHandler: func(opts *options.ClientOptions) {\n    \t\topts.SetConnectTimeout(5 * time.Second)\n    \t\topts.SetTimeout(15 * time.Second)\n    \t},\n    })\n\n    // connect through SRV.\n    db, err := sutando.NewDB(ctx, sutando.ConnSrv{\n    \tUsername:  \"example\",\n    \tPassword:  \"example\",\n    \tHost:      \"example.mongo.net\",\n    \tDB:        \"example\",\n    \tAdminAuth: true,\n    \tPem:       \"\",\n    \tClientOptionsHandler: func(opts *options.ClientOptions) {\n    \t\topts.SetConnectTimeout(5 * time.Second)\n    \t\topts.SetTimeout(15 * time.Second)\n    \t},\n    })\n```\n\n- Model Declaration\n\n```go\n    // Supported\n    type Element struct {\n        FirstName string                                // 'firstName' as mongo db field key\n        lastName string                                 // 'lastName' as mongo db field key\n        Nickname bool               `bson:\"nick_name\"`  // using `bson:\"xxx\"` tag to assign field key to 'xxx'\n        Healthy bool                `bson:\"-\"`          // using `bson:\"-\"` tag to ignore this field\n        Children []string           `bson:\",omitempty\"` // using `bson:\",omitempty\"` tag to ignore this field when it's empty\n        CareerPlan CustomStruct                         // 'careerPlan' as mongo db field key  works\n        Hobbies map[string]string\n        Live time.Time\n        Salary decimal.Decimal\n    }\n```\n\n- Use an exist connection\n\n```go\n    var client *mongo.Client\n    ...\n    database := \"example\"\n    db := sutando.NewDBFromMongo(ctx, client, database)\n\n```\n\n#### Disconnect\n\n```go\n    err := db.Disconnect(ctx)\n```\n\n#### Drop\n\n```go\n    err := db.Collection(\"Collection\").Drop(ctx)\n```\n\n#### Scalar\n\n```go\n    // Count\n    count, err := db.Collection(\"Collection\").Find().Equal(\"Name\", \"sutando\").Greater(\"Number\", 300).Count(ctx, \"_index_id_\")\n```\n\n#### Find\n\n```go\n    resultOne := struct{}\n    err := db.Collection(\"Collection\").Find().Equal(\"Name\", \"sutando\").Greater(\"Number\", 300).First().Exec(ctx, \u0026resultOne)\n\n    resultMany := []struct{}\n    err := db.Collection(\"Collection\").Find().Equal(\"Name\", \"sutando\").Greater(\"Number\", 300).Exec(ctx, \u0026resultMany)\n```\n\n#### Create\n\n```go\n    resultOne, _, err := db.Collection(\"Collection\").Insert(\u0026obj).Exec(ctx)\n\n    _, resultMany, err := db.Collection(\"Collection\").Insert(\u0026obj1, \u0026obj2, \u0026obj3).Exec(ctx)\n```\n\n#### Update with Model (Will update all fields including empty fields)\n\n```go\n    resultOne, err := db.Collection(\"Collection\").UpdateWith(\u0026data).Equal(\"Field\", \"sutando\").First().Exec(su.ctx, false)\n\n    resultMany, err := db.Collection(\"Collection\").UpdateWith(\u0026data).Equal(\"Field\", \"sutando\").Exec(su.ctx, false)\n```\n\n#### Update with Set\n\n```go\n    resultOne, err := db.Collection(\"Collection\").Update().Equal(\"Field\", \"sutando\").First().Set(\"Field\", \"hello\").Exec(su.ctx, false)\n\n    resultMany, err := db.Collection(\"Collection\").Update().Equal(\"Field\", \"sutando\").Set(\"Field\", \"hello\").Exec(su.ctx, false)\n```\n\n#### Delete\n\n```go\n    resultOne, err := db.Collection(\"Collection\").Delete().Equal(\"Field\", \"sutando\").First().Exec(su.ctx)\n\n    resultMany, err := db.Collection(\"Collection\").Delete().Equal(\"Field\", \"sutando\").Exec(su.ctx)\n```\n\n#### Use original mongo-driver instance\n\n```go\n    client := db.RawClient()\n    database := db.RawDatabase()\n```\n\n## Changelog\n\n| Version | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |\n| :-----: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n|  1.4.2  | - Added method `Bson` into `Update` `Find` `Delete` `Scalar`                                                                                                                                                                                                                                                                                                                                                                                                                                     |\n|  1.4.1  | - Completed comment for all struct, interface, function                                                                                                                                                                                                                                                                                                                                                                                                                                          |\n|  1.4.0  | - Remove all db execute functions \u003cbr\u003e - Removed `Query` \u003cbr\u003e - Removed method `Bitwise` \u003cbr\u003e - Added `ConnSrv` connection structure \u003cbr\u003e - Added method `Drop` into `Collection()` method chain \u003cbr\u003e - Added comment for all methods \u003cbr\u003e - Added `option` parameter into `Regex` method \u003cbr\u003e - Rewrite the structure fo filters \u003cbr\u003e - Renamed `GetDriver` to `RawClient` \u003cbr\u003e - Renamed `GetDriverDB` to `RawDatabase` \u003cbr\u003e - Fixed after invoking `Find`, didn't call `defer cursor.Close()` |\n|  1.3.7  | - Added `Scalar` \u003cbr\u003e - Moved method `Count` from `Query` to `Scalar`                                                                                                                                                                                                                                                                                                                                                                                                                            |\n|  1.3.6  | - Added method `Regex` into `Update` `Find` `Delete` `Query`                                                                                                                                                                                                                                                                                                                                                                                                                                     |\n|  1.3.5  | - Fixed `Find` no document mismatch error                                                                                                                                                                                                                                                                                                                                                                                                                                                        |\n|  1.3.4  | - Added method `Count` into `Query`                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n|  1.3.3  | - Added methods `Sort` `Limit` `Skip` into `Find`                                                                                                                                                                                                                                                                                                                                                                                                                                                |\n|  1.3.2  | - Added deprecated comment for `DB`                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n|  1.3.1  | - Renamed `OptionHandler` to `ClientOptionsHandler` \u003cbr\u003e - Renamed `SetupOption` to `SetupClientOptions`                                                                                                                                                                                                                                                                                                                                                                                         |\n|  1.3.0  | - Added `Execute Chain` \u003cbr\u003e - Fixed error when input only one slice in insert function \u003cbr\u003e - Fixed error when input only one param/slice in In/NotIn function \u003cbr\u003e - Fixed `bson` `omitempty` supported \u003cbr\u003e - Fixed embed structure lowercase Name issue \u003cbr\u003e - Fixed map structure value lowercase Name issue \u003cbr\u003e - Fixed array structure value lowercase Name issue \u003cbr\u003e - Plan to remove db execute function in version 1.4.X                                                             |\n|  1.2.1  | - Support `mongodb-srv` \u003cbr\u003e - Fixed `Conn` `ClientOptionsHandler` nill pointer issue                                                                                                                                                                                                                                                                                                                                                                                                            |\n|  1.2.0  | - Added `ClientOptionsHandler` into `Conn` Interface                                                                                                                                                                                                                                                                                                                                                                                                                                             |\n|  1.1.2  | - Fixed testing structure tag issue \u003cbr\u003e - Fixed error wrapping issue                                                                                                                                                                                                                                                                                                                                                                                                                            |\n|  1.1.1  | - Added `Disconnect` function                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |\n|  1.0.4  | - Fixed some testing mistakes                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |\n|  1.0.3  | - Added `NewDBFromMongo` function                                                                                                                                                                                                                                                                                                                                                                                                                                                                |\n|  1.0.2  | - Added MIT License \u003cbr\u003e - Removed Makefile                                                                                                                                                                                                                                                                                                                                                                                                                                                      |\n|  1.0.1  | - Fixed some testing mistakes                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |\n|  1.0.0  | - Release                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |\n\n## License\n\n[MIT](https://github.com/yanun0323/sutando/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanun0323%2Fsutando","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanun0323%2Fsutando","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanun0323%2Fsutando/lists"}