d-gen-po-model-converter-from-sql

d-gen-po-model-converter-from-sql is a cursor rule for coding agents from xyzbit/AI-Coding. It costs 12 tokens per session (1,110 once invoked), scanned A, original, Apache-2.0.

A set of rules for generating Go model, persistence-object, and converter files from SQL CREATE TABLE statements. A persistence object is the database-facing version of a data structure.

In plain words
What is it for?
Use it to turn a SQL table definition into files under the project's domain and infrastructure or repository directories, after checking the Go module and folder layout.
Why use it?
It keeps database fields, JSON names, database tags, table names, and time fields mapped consistently across application layers.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/xyzbit/ai-coding/d-gen-po-model-converter-from-sql
Clone the repo
git clone --depth 1 https://github.com/xyzbit/AI-Coding

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for d-gen-po-model-converter-from-sql

README.md
[![agentmods](https://agentmods.dev/badge/rules/xyzbit/ai-coding/d-gen-po-model-converter-from-sql.svg)](https://agentmods.dev/rules/xyzbit/ai-coding/d-gen-po-model-converter-from-sql)
Your own site
<a href="https://agentmods.dev/rules/xyzbit/ai-coding/d-gen-po-model-converter-from-sql"><img src="https://agentmods.dev/badge/rules/xyzbit/ai-coding/d-gen-po-model-converter-from-sql.svg" alt="Measured on agentmods" height="20"></a>
Per session 12 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,110 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00012 $0.01110
Opus 5 $0.00006 $0.00555
Sonnet 5 $0.00002 $0.00222
Haiku 4.5 $0.00001 $0.00111

Measured 5d ago against content hash 0bfd04dab791, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

d-gen-po-model-converter-from-sql scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

cursor/rules/develop/d-gen-po-model-converter-from-sql.mdc · 151 lines

How it starts

The opening of the file, as written. The whole thing — 151 lines — stays where its author put it; the contents beside it link to each section on GitHub.

SQL to Go Code Generator Rules

概述

根据 SQL CREATE TABLE 语句生成三个 Go 文件:Model、PO(持久化对象)和 Converter。

前置检查

  1. 检查项目的 go.mod 文件以获取正确的模块名
  2. 确认目标目录结构是否存在

文件生成规则

1. Model 文件

位置: domain/model/{表名}.go

要求:

  • 结构体名称采用驼峰命名,如 UserAuth
  • 字段名采用驼峰命名
  • 必须包含 json 标签
  • 所有数据库字段都要映射,包括 created_time 和 updated_time
  • 时间类型字段必须导入 "time" 包

示例:

package model

import "time"

type Users struct {
    ID          int64     `json:"id"`
    Name        string    `json:"name"`
    CreatedTime time.Time `json:"created_time"`
    UpdatedTime time.Time `json:"updated_time"`
}

2. PO 文件

位置: infrastructure/po/{表名}.gorepository/adapter/po/{表名}.go

要求:

  • 结构体名称与 Model 保持一致
  • 必须包含 GORM 标签和 json 标签
  • 表名方法必须实现
  • 所有数据库字段都要映射,包括 created_time 和 updated_time
  • 时间类型字段必须导入 "time" 包

示例:

package po

import "time"

type Users struct {
    ID          int64     `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
    Name        string    `gorm:"column:name;not null" json:"name"`
    CreatedTime time.Time `gorm:"column:created_time;not null;default:CURRENT_TIMESTAMP" json:"created_time"`
    UpdatedTime time.Time `gorm:"column:updated_time;not null;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" json:"updated_time"`
}

func (u *Users) TableName() string {
    return "users"
}

3. Converter 文件

位置: infrastructure/converter/{表名}_converters.go

要求:

  • 必须使用正确的模块导入路径(从 go.mod 获取)
  • 必须实现四个转换函数:
    1. To{表名}PO: Model -> PO
    2. To{表名}Model: PO -> Model
    3. To{表名}POList: []Model -> []PO
    4. To{表名}ModelList: []PO -> []Model
  • 所有函数都必须包含 nil 检查
  • 必须转换所有字段,包括时间字段

示例:

package converter

import (
    "nebula/domain/model"
    "nebula/infrastructure/po"
)

func ToUsersPO(m *model.Users) *po.Users {
    if m == nil {
        return nil
    }
    return &po.Users{
        ID:          m.ID,
        Name:        m.Name,
        CreatedTime: m.CreatedTime,
        UpdatedTime: m.UpdatedTime,
    }
}

// 其他转换函数...

数据类型映射规则

SQL 类型 Go 类型 说明
BIGINT int64 包括 UNSIGNED
INT int 包括 UNSIGNED
VARCHAR string 所有字符串类型
TEXT string 所有文本类型
TIMESTAMP time.Time 时间戳类型
DATETIME time.Time 日期时间类型
DECIMAL float64 浮点数类型
BOOL bool 布尔类型

Read the full file on GitHub · 151 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 151 lines · 12 tokens per session scan A 0bfd04dab791

Subscribe to this mod's changes

d-gen-po-model-converter-from-sql is a cursor rule published in the GitHub repository xyzbit/AI-Coding (21 stars, last pushed 10mo ago), licensed Apache-2.0. It adds 12 tokens to every session and 1,110 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.