sql-to-go

Convert MySQL CREATE TABLE statements to Go structs with form, json, and xorm tags. Use when converting SQL DDL to Go struct definitions, generating ORM models from database schemas, or creating Go types from MySQL tables. Supports MySQL data type mapping, snake_case to CamelCase conversion, and automatic tag generation.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "sql-to-go" with this command: npx skills add weirubo/sql-to-go

SQL to Go Struct

Quick Start

Convert a MySQL CREATE TABLE statement to a Go struct with tags:

  1. Parse the CREATE TABLE statement to extract table name, columns, and constraints
  2. Map each MySQL column type to corresponding Go type
  3. Convert snake_case column names to CamelCase field names
  4. Generate struct with form, json, and xorm tags

Type Mapping

For complete MySQL to Go type mappings, see type_mappings.md.

Quick Reference

MySQLGoNotes
INTint
BIGINTint64
VARCHARstring
TEXTstring
DATETIMEtime.Time
TIMESTAMPtime.Time
BOOL / BIT(1)bool
DECIMALfloat64Or custom type

Column Name Conversion

Convert snake_case to CamelCase:

user_name    → UserName
created_at   → CreatedAt
user_id      → UserID
api_key      → APIKey
is_active    → IsActive

Special cases - acronyms remain uppercase:

  • idID
  • urlURL
  • uriURI

Tag Generation

Generate three tags for each field:

  • form: HTTP form parameter name (snake_case)
  • json: JSON field name (snake_case)
  • xorm: XORM ORM column name and constraints

XORM Tag Patterns

ConstraintTag
Primary keyxorm:"pk"
Auto incrementxorm:"autoincr"
Not nullxorm:"not null"
Uniquexorm:"unique"
Default valuexorm:"default 'value'"
Nullablexorm:"nullable"
Indexxorm:"index"
Commentxorm:"comment 'text'"

Combine constraints: xorm:"'user_id' pk autoincr"

Example

Input

CREATE TABLE users (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL UNIQUE,
    email VARCHAR(100) NOT NULL,
    age INT DEFAULT 0,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    is_active BOOLEAN DEFAULT TRUE,
    bio TEXT
) COMMENT='User table';

Output

package models

import "time"

// User represents the users table
type User struct {
    ID        uint64    `form:"id" json:"id" xorm:"'id' pk autoincr"`
    Username  string    `form:"username" json:"username" xorm:"'username' unique not null"`
    Email     string    `form:"email" json:"email" xorm:"'email' not null"`
    Age       int       `form:"age" json:"age" xorm:"'age' default 0"`
    CreatedAt time.Time `form:"created_at" json:"created_at" xorm:"'created_at'"`
    IsActive  bool      `form:"is_active" json:"is_active" xorm:"'is_active' default true"`
    Bio       string    `form:"bio" json:"bio" xorm:"'bio'"`
}

Workflow

  1. Extract table info: Get table name, column definitions, constraints
  2. Apply type mappings: See type_mappings.md for reference
  3. Generate field name: Convert snake_case column to CamelCase
  4. Add tags: Generate form/json/xorm tags based on column attributes
  5. Handle special cases: Primary keys, indexes, defaults, comments

Nullable Columns

For nullable columns (allows NULL), use pointer types:

// MySQL: phone VARCHAR(20) NULL
Phone *string `form:"phone" json:"phone" xorm:"'phone' nullable"`

Struct Comment

Use table comment as struct comment, or generate from table name:

// User represents the users table

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Web3

Element Nft Tracker

Element Market API integration. Requires 'ELEMENT_API_KEY' configured in OpenClaw secrets. Strictly requires explicit user consent before accessing personal...

Registry SourceRecently Updated
930Profile unavailable
Web3

Onchain Analyzer

Analyze wallet addresses and on-chain activity — transaction history, token holdings, DeFi positions, and trading patterns across EVM chains and Solana. Use...

Registry SourceRecently Updated
1390Profile unavailable
Web3

Crypto Tracker Cn

Track cryptocurrency markets in real-time. 加密货币行情追踪、比特币价格、以太坊ETH、市值排行、DeFi数据、恐惧贪婪指数、趋势币种、空投信息、RSI技术分析、均线分析、金叉死叉、DeFi收益率对比、Gas费查询。Use when checking crypto pri...

Registry SourceRecently Updated
2030Profile unavailable
Web3

Crypto Whale Tracker

Track large cryptocurrency transfers (whale movements) using public APIs like Whale Alert and Etherscan. Set thresholds, monitor wallets, and generate format...

Registry SourceRecently Updated
1740Profile unavailable