sqldump

package module
v0.0.0-...-7751445 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2025 License: BSD-3-Clause Imports: 5 Imported by: 1

README

sqldump

Go Reference

Purpose

The sqldump package provides utilities for dumping SQL query results in a structured format for testing and debugging purposes. It allows developers to easily capture and validate database query outputs, making database tests more readable and maintainable.

Example Usage

package main

import (
	"context"
	"database/sql"
	"log"
	
	"github.com/alextanhongpin/testdump/sqldump"
	"github.com/alextanhongpin/testdump/yamldump"
)

func TestQuery(t *testing.T) {
	// Setup your database connection
	db, err := sql.Open("mysql", "user:password@/dbname")
	if err != nil {
		t.Fatal(err)
	}
	defer db.Close()
	
	// Dump the results of a SQL query
	results, err := sqldump.Dump(context.Background(), db, `SELECT id, name, email FROM users`)
	if err != nil {
		t.Fatal(err)
	}
	
	// Use yamldump to format and verify the results
	// You can ignore time-based fields that might change between runs
	yamldump.Dump(t, results, yamldump.IgnoreFields("created_at"))
}

Benefits

  • Simplified Testing: Makes it easy to capture and verify database query results
  • Readable Output: Structures query results in an easily readable format
  • Integration with yamldump: Works seamlessly with the yamldump package for better test output formatting
  • Debugging Aid: Helps to quickly inspect database state during development
  • Reproducible Tests: Creates consistent test output that can be validated across test runs
  • Customization: Allows ignoring specific fields (like timestamps) that might change between test runs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Query

func Query(ctx context.Context, db *sql.DB, query string, args ...any) ([]map[string]any, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL