dumpdata

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 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, where string) ([]map[string]any, []string, error)

FetchRows queries rows from the given table, optionally filtered by a WHERE clause. The where parameter should contain just the condition (e.g. "status = 'active'"), not the WHERE keyword itself. Pass an empty string to fetch all rows.

Note: the where clause is appended to the query as-is. The caller is responsible for ensuring it is valid SQL. This is safe because the where value originates from the CLI operator (the person running the tool), not from untrusted external input.

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