{"id":20932888,"url":"https://github.com/jferrl/yowrap","last_synced_at":"2026-04-29T03:35:37.189Z","repository":{"id":236474881,"uuid":"792684091","full_name":"jferrl/yowrap","owner":"jferrl","description":"Lightweight Go package designed to effortlessly wrap the Spanner Ecosystem Yo package for enhanced functionality","archived":false,"fork":false,"pushed_at":"2024-04-28T09:57:30.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-19T19:26:04.271Z","etag":null,"topics":[],"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/jferrl.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":"2024-04-27T09:15:47.000Z","updated_at":"2024-04-27T15:58:05.000Z","dependencies_parsed_at":"2024-04-27T10:25:44.028Z","dependency_job_id":"ecb8bfbb-1824-49d4-9a1f-768d5b57436f","html_url":"https://github.com/jferrl/yowrap","commit_stats":null,"previous_names":["jferrl/yowrap"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferrl%2Fyowrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferrl%2Fyowrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferrl%2Fyowrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jferrl%2Fyowrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jferrl","download_url":"https://codeload.github.com/jferrl/yowrap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243325361,"owners_count":20273271,"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":[],"created_at":"2024-11-18T21:53:40.501Z","updated_at":"2025-12-30T04:30:42.647Z","avatar_url":"https://github.com/jferrl.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌮 yowrap 🌮\n\n[![GoDoc](https://img.shields.io/static/v1?label=godoc\u0026message=reference\u0026color=blue)](https://pkg.go.dev/github.com/jferrl/yowrap)\n[![Test Status](https://github.com/jferrl/yowrap/workflows/tests/badge.svg)](https://github.com/jferrl/yowrap/actions?query=workflow%3Atests)\n[![codecov](https://codecov.io/gh/jferrl/yowrap/branch/main/graph/badge.svg?token=68I4BZF235)](https://codecov.io/gh/jferrl/yowrap)\n[![Go Report Card](https://goreportcard.com/badge/github.com/jferrl/yowrap)](https://goreportcard.com/report/github.com/jferrl/yowrap)\n\nLightweight Go package designed to effortlessly wrap the [Yo](https://github.com/cloudspannerecosystem/yo) package for enhanced functionality.\n\n## Context\n\n[Yo](https://github.com/cloudspannerecosystem/yo) is a command-line tool that generates Go code from SQL DDL files. The generated code is used to interact with Google Cloud Spanner databases, representing the table and a set of methods to interact with the table.\n\nYo is a great tool to generate the boilerplate code needed to interact with a Google Cloud Spanner database. However, the generated code is not intended to be modified by the user, as it is overwritten every time the `yo` tool is executed. This pkg is designed to extend the generated code functionality creating a more capable model.\n\nThis package is designed to be used in conjunction with the `yo` tool, not as a replacement.\n\nSee [Yo](https://github.com/cloudspannerecosystem/yo) for more information about the `yo` tool.\n\n## Features\n\n- **Commit transaction**: This feature allows the client to commit a model transaction directly from the model instance without using the spanner.Mutation outside the model. Now, the model has the responsibility of writing the changes to the database.\n- **Custom model hooks**: This feature allows the client to define custom hooks that will be executed before or after a specific method is called. This is useful for adding custom logic to the model methods.\n- **Inheric model methods**: All the method signatures from the generated code are inherited by the model. This allows the client to call the generated methods directly from the model instance.\n\n## Usage\n\nUse `yowrap` as a wrapper for the generated model but committing the transaction outside the model. This mantains the ability to use the generated methods-\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"log\"\n\n    \"cloud.google.com/go/spanner\"\n    \"github.com/jferrl/yowrap\"\n)\n\n\nfunc main() {\n    spannerClient, err := spanner.NewClient(ctx, \"projects/my-project/instances/my-instance/databases/my-database\")\n    if err != nil {\n        log.Fatalf(\"Failed to create a Spanner client: %v\", err)\n    }\n    defer spannerClient.Close()\n\n    // Go struct generated by the yo tool\n    user := \u0026User{\n        ID:    1,\n        Name:  \"John Doe\",\n        Email: \" [email protected]\",\n    }\n\n    // Create a new user model\n    user := yowrap.NewModel(user)\n\n    mut := user.Insert(ctx)\n\n    _, err = spannerClient.Apply(ctx, []*spanner.Mutation{mut})\n    if err != nil {\n        log.Fatalf(\"Failed to apply the mutation: %v\", err)\n    }\n}\n```\n\nUse `yowrap` as a wrapper for the generated model and commit the transaction directly from the model.\n\n```go\n\npackage main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"log\"\n\n    \"cloud.google.com/go/spanner\"\n    \"github.com/jferrl/yowrap\"\n)\n\nfunc main() {\n    spannerClient, err := spanner.NewClient(ctx, \"projects/my-project/instances/my-instance/databases/my-database\")\n    if err != nil {\n        log.Fatalf(\"Failed to create a Spanner client: %v\", err)\n    }\n    defer spannerClient.Close()\n\n    // Go struct generated by the yo tool\n    user := \u0026User{\n        ID:    1,\n        Name:  \"John Doe\",\n        Email: \" [email protected]\",\n    }\n\n    // Create a new user model\n    user := yowrap.NewModel(user, yowrap.WithSpannerClientOption(spannerClient))\n\n    // Commit the transaction\n    _, err = user.Apply(ctx, yowrap.Insert)\n    if err != nil {\n        log.Fatalf(\"Failed to insert and commit the user: %v\", err)\n    }\n}\n```\n\nUse `yowrap` with a custom hook.\n\n```go\n\npackage main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"log\"\n\n    \"cloud.google.com/go/spanner\"\n    \"github.com/jferrl/yowrap\"\n)\n\nfunc main() {\n    spannerClient, err := spanner.NewClient(ctx, \"projects/my-project/instances/my-instance/databases/my-database\")\n    if err != nil {\n        log.Fatalf(\"Failed to create a Spanner client: %v\", err)\n    }\n    defer spannerClient.Close()\n\n    // Go struct generated by the yo tool\n    user := \u0026User{\n        ID:    1,\n        Name:  \"John Doe\",\n        Email: \" [email protected]\",\n    }\n\n    // Create a new user model\n    user := yowrap.NewModel(user, yowrap.WithSpannerClientOption(spannerClient))\n\n    // Add a custom hook\n    user.On(yowrap.BeforeInsert, func(_ context.Context, m *yowrap.Model[*user.User], _ *spanner.ReadWriteTransaction) error {\n        log.Println(\"Before insert\")\n        return nil\n    })\n\n    // Commit the transaction\n    _, err = user.Apply(ctx, yowrap.Insert)\n    if err != nil {\n        log.Fatalf(\"Failed to insert and commit the user: %v\", err)\n    }\n}\n```\n\n## License\n\nCopyright 2024, jferrl\n\nyowrap is released under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjferrl%2Fyowrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjferrl%2Fyowrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjferrl%2Fyowrap/lists"}