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常见问题.md

ORM是否可以直接执行SQL文件

  1. 首先,ORM底层依赖的数据库driver从安全性考虑,通常默认不支持同时执行多条SQL语句。你可以读取SQL文件内容,将内容拆分为单条SQL语句(通过;分隔符号分隔多条SQL语句),然后调用ORM的Exec方法来执行。
  2. 其次,如果你想要允许底层driver一次性执行多条SQL语句,可以参考底层driver的配置,比如mysql的配置,可以设置multiStatements=true(参考mysql-driver配置),这样ORM的Exec方法就可以执行多条SQL语句了。配置项示例:
    database:
        default:
            link: "mysql:root:123456@tcp(127.0.0.1:3306)/test?charset=utf8mb4&parseTime=True&loc=Local&multiStatements=true"

driver: bad connection

如果数据库执行出现该错误,可能是由于本地数据库连接池的连接已经过期,可以检查一下客户端配置的 MaxLifeTime 配置是否超过数据库服务端设置的连接最大超时时间。更多客户端配置请参考章节: ORM使用配置

update/insert 操作不生效

使用 orm 时,配置文件中:

dryRun = "(可选)ORM空跑(只读不写)"

这行配置一定要删掉或者设置为0

否则出现 update insert 操作不生效的现象。

cannot find database driver for specified database type "xxx", did you misspell type name "xxx" or forget importing the database driver?

程序代码没有引入依赖的数据库驱动,需要注意从 GoFrame v2.1 版本开始,需要手动引入社区驱动,请参考:

数据库打开 DEBUG 日志后,查询的 SQL 语句中发现出现 WHERE 0=1 的语句

出现 WHERE 0=1 的情况是由于查询条件中存在数组条件,并且数组的长度为 0。这种情况 ORM 无法自动过滤这种空数组条件(这种条件过滤可能会引起业务异常),需要开发者根据业务场景,显示调用 OmitEmpty 或者 OmitEmptyWhere 来告诉 ORM 可以过滤这些空数组的条件。

MYSQL中的表情,用SQL查询后,乱码问题

解决办法:

config.toml 文件 数据库配置的 charset 设置为 utf8mb4 默认是 utf8

MySQL 存储表情时注意:

  • 数据库编码 utf8mb4
  • 表的编码是 utf8mb4
  • 表中内容字段是 utf8mb4

怎么让有UUID类型的数据库支持UUID处理

由于ORM类型转换在底层是使用的gconv实现的,所以我们可以自己添加新的converter就可以了。如以下示例,在你的程序初始化时调用就可以了。

    gconv.RegisterTypeConverterFunc(func(src uuid.UUID) (val *string, err error) {
		v := src.String()
		return &v, nil
	})

	gconv.RegisterTypeConverterFunc(func(src uuid.UUIDs) (val *[]string, err error) {
		v := src.Strings()
		return &v, nil
	})

	gconv.RegisterTypeConverterFunc(func(src string) (val *uuid.UUID, err error) {
		var v uuid.UUID
		val = &v
		src = gstr.Trim(src)
		if src == "" {
			return
		}
		v, err = uuid.Parse(src)
		return
	})

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.