dumpdata

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package dumpdata provides database introspection and row fetching utilities for the dump-data feature. It supports PostgreSQL, SQLite, MySQL, and TiDB for primary key detection, and generic row fetching for any SQL database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectPrimaryKeys

func DetectPrimaryKeys(db *sql.DB, dbType, table string) ([]string, error)

DetectPrimaryKeys introspects the database to find primary key columns for the given table. The dbType parameter determines which SQL dialect to use for the introspection query. Supported values are "postgresql", "postgres", "sqlite", "mysql", and "tidb". For unsupported database types, it returns nil, nil so the caller can fall back to a user-specified conflict key.

func FetchRows

func FetchRows(db *sql.DB, table string) ([]map[string]any, []string, error)

FetchRows queries all rows from the given table and returns them as a slice of maps (column name to value) along with the ordered column names. Values are normalized using NormalizeValue. It first tries ANSI SQL double-quoted table names and falls back to MySQL backtick quoting if the first attempt fails.

func NormalizeValue

func NormalizeValue(v any) any

NormalizeValue converts driver-specific types to clean Go types suitable for serialization. It handles nil, []byte, time.Time, int64, float64, bool, and falls back to fmt.Sprintf for any other type.

func OpenDB

func OpenDB(driverName, dsn string) (*sql.DB, error)

OpenDB opens a database connection using the given driver name and DSN, then verifies the connection is alive with a ping.

Types

This section is empty.

Jump to

Keyboard shortcuts

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