All skills
gogf avatar

/goframe-v2

@911705d
by GoFramegogf/skills81 stars
3

GoFrame v2 development skill. Use only when the target Go project uses or is explicitly adopting GoFrame v2: the nearest go.mod requires github.com/gogf/gf/v2, existing Go files import github.com/gogf/gf/v2 or any github.com/gogf/gf/v2/... component package, or the user asks to scaffold, migrate, or build with GoFrame. Trigger for GoFrame-backed Go work such as APIs/controllers/services, middleware, routing/config, ORM/DAO/DO/entity/database operations, gf CLI/codegen, HTTP/gRPC services, and microservice conventions. Do not trigger for generic Go projects without GoFrame evidence, frontend-only work, shell scripts, or unrelated infrastructure tasks.

Use this Skill: https://skilld.dev/gh/gogf/skills/goframe-v2

This session only. Nothing lands on disk.

references核心组件数据库ORMORM链式操作ORM链式操作-数据库切换.md

我们知道数据库的配置中有支持对默认数据库的配置,因此 DB 对象及 Model 对象在初始化的时候已经绑定到了特定的数据库上。运行时切换数据库有几种方案(假如我们的数据库有 user 用户数据库和 order 订单数据库):

  1. 通过不同的配置分组来实现。这需要在配置文件中配置不同的分组配置,随后在程序中可以通过 g.DB("分组名称") 来获取特定数据库的单例对象。

  2. 通过运行时 DB.SetSchema 方法切换单例对象的数据库,需要注意的是由于修改的是单例对象的数据库配置,因此影响是全局的:

    g.DB().SetSchema("user-schema")
    g.DB().SetSchema("order-schema")
  3. 通过链式操作 Schema 方法创建 Schema 数据库对象,并通过该数据库对象创建模型对象并执行后续链式操作:

    g.DB().Schema("user-schema").Model("user").All()
    g.DB().Schema("order-schema").Model("order").All()
  4. 也可以通过链式操作 Model.Schema 方法设置当前链式操作对应的数据库,没有设置的情况下使用的是其 DB 或者 TX 默认连接的数据库:

    g.Model("user").Schema("user-schema").All()
    g.Model("order").Schema("order-schema").All()

    :::tip 注意两种使用方式的差别,前一种方式来自于 Schema 对象创建 Model 对象后执行操作;后一种方式是通过修改当前 Model 对象操作的数据库名称达到切换数据库的目的。 :::

  5. 此外,假如当前数据库操作配置的用户有权限,那么可以直接通过表名中带数据库名称实现跨域操作,甚至跨域关联查询:

    // SELECT * FROM `order`.`order` o LEFT JOIN `user`.`user` u ON (o.uid=u.id) WHERE u.id=1 LIMIT 1
    g.Model("order.order o").LeftJoin("user.user u", "o.uid=u.id").Where("u.id", 1).One()

Source: SKILL.md on GitHub

1 alert16d5 checks · Risk MEDIUM
  • Gen Agent Trust Hub16d

    The skill provides a comprehensive development guide and code examples for the GoFrame v2 framework. While highly informative for Go developers, it contains several examples with hardcoded placeholder secrets, tokens, and specific local file paths to sensitive configuration files (like Kubernetes credentials). These elements are provided for demonstration purposes but represent insecure practices if used in production without modification.

  • Socket16d

    5 alerts: gptSecurity, gptAnomaly

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    227/949 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 911705d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 months ago.

Steadyupdated 4 months ago
  • Go
  • Database
  • goframe
  • orm
  • http
  • grpc
  • microservices
  • crud
  • scaffolding
  • middleware

README badge

README badge for gogf/skills

Provides instruction and conventions for developing with GoFrame v2, a modular Go framework for building HTTP and gRPC services, microservices, and database operations using its ORM, CLI tooling, and project scaffolding. Use this skill when the target project has GoFrame v2 as a dependency or when the user requests scaffolding, migrations, or service development with GoFrame conventions.

Generated from the current SKILL.md.

When should I use this skill?
Use this skill only when your Go project uses GoFrame v2, indicated by github.com/gogf/gf/v2 in go.mod or imports. Do not use for generic Go projects, frontend work, or infrastructure tasks unrelated to GoFrame.
Should I manually set created_at and updated_at fields?
No. GoFrame automatically writes created_at on insert and updated_at on insert/update/save. Manually setting these fields is redundant and violates project conventions.
What should I use for database operations instead of g.Map?
Always use DO objects from internal/model/do/. DO struct fields are interface{}, unset fields remain nil and are automatically ignored by the ORM.
How does soft delete work in GoFrame?
Call Delete() on the DAO; GoFrame automatically converts it to UPDATE SET deleted_at = NOW(). Queries automatically filter out soft-deleted rows without requiring manual WhereNull conditions.
Where should I implement business logic?
Implement business logic directly in the service/ directory. Do not use the logic/ directory unless explicitly requested.

Generated from the current SKILL.md. These answers refresh after source changes.