cool-mysql

Guide developers on using cool-mysql for MySQL data access in Go.

3|Updated Oct 20, 2020
One-click install
npx skills add https://github.com/StirlingMarketingGroup/cool-mysql --skill cool-mysql
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cool-mysql
Source: https://github.com/StirlingMarketingGroup/cool-mysql/tree/main/.claude/skills/cool-mysql
Command: npx skills add https://github.com/StirlingMarketingGroup/cool-mysql --skill cool-mysql

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go applications frequently wrestle with verbose database access code and inconsistent handling of reads and writes. This Skill provides a comprehensive guide to using cool-mysql to simplify data access, enforce safe parameter usage, and implement robust caching, templating, and transactions.

Core Features & Use Cases

  • Dual connection pools: separate read and write pools for optimized performance and correctness.
  • Named parameters and templates: use @@param placeholders and Go templates for flexible, safe queries.
  • Caching strategies: configure Redis, Memcached, or in-memory caches to reduce DB load on SELECTs.
  • Automatic chunking and retries: handle large inserts and transient errors with minimal boilerplate.
  • Strong typing and mapping: map results into structs, maps, slices, or JSON with minimal code.
  • Transactional patterns: guidance for GetOrCreateTxFromContext, context management, and transactional work flows.

Quick Start

Install and import the library, then use the quick-start examples to connect and run basic queries. The Quick Start section in the repository demonstrates minimal code to create a dual-pool DB, perform a SELECT, and handle caching.

Frequently Asked Questions about cool-mysql

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I separate read and write connection pools for MySQL in Go?

You can configure dual read and write MySQL connection pools in Go to optimize query performance and enforce correctness. This approach separates traffic, directing SELECTs to read replicas and writes to the primary database for safer data access.

How do I use named parameters in Go MySQL queries?

You can use named parameters in Go MySQL queries by utilizing @@param placeholders and template-driven syntax. This method interpolates values safely into your SQL templates, preventing injection issues while keeping query code flexible and readable.

Can I cache MySQL SELECT query results in Go using Redis or Memcached?

Yes, you can cache MySQL SELECT query results in Go by configuring Redis, Memcached, or in-memory caches. This reduces database load by serving repeated read requests directly from the configured caching layer.

What is the best way to handle large batch inserts in Go without overwhelming the database?

The best way to handle large batch inserts in Go is using automatic chunking. This feature splits massive insert operations into smaller, manageable batches, preventing database timeouts and ensuring reliable data insertion with minimal boilerplate.

How do I map MySQL query results to Go structs automatically?

You can map MySQL query results to Go structs automatically using strong typing features. This functionality maps database rows directly into structs, maps, slices, or JSON formats, reducing manual data conversion code.

How do I manage database transactions with context in Go?

You can manage database transactions with context in Go using patterns like GetOrCreateTxFromContext. This handles context management and transactional workflows, ensuring safe commits or rollbacks during complex multi-step database operations.