schema

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package schema provides DB-execution functions for managing table and column schema operations. It complements the github.com/dracory/sb SQL builder by executing DDL statements (CREATE, DROP, ALTER) against a live database.

Usage:

import (
    "github.com/dracory/sb"
    "github.com/dracory/sb/schema"
)

err := schema.TableColumnAdd(ctx, "users", sb.Column{Name: "email", Type: sb.COLUMN_TYPE_STRING, Length: 255})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TableColumnAdd

func TableColumnAdd(ctx database.QueryableContext, tableName string, column sb.Column) error

TableColumnAdd adds a column to a table.

func TableColumnAddIfNotExists

func TableColumnAddIfNotExists(ctx database.QueryableContext, tableName string, column sb.Column) error

TableColumnAddIfNotExists adds a column to a table only if it does not already exist. Handles TOCTOU race condition by swallowing duplicate column errors.

func TableColumnDrop

func TableColumnDrop(ctx database.QueryableContext, tableName string, columnName string) error

TableColumnDrop drops a column from a table.

func TableColumnDropIfExists

func TableColumnDropIfExists(ctx database.QueryableContext, tableName string, columnName string) error

TableColumnDropIfExists drops a column from a table only if it exists. Handles TOCTOU race condition by swallowing column-not-found errors.

func TableColumnExists

func TableColumnExists(ctx database.QueryableContext, tableName string, columnName string) (bool, error)

TableColumnExists checks if a column exists in a table.

func TableColumnRename

func TableColumnRename(ctx database.QueryableContext, tableName string, oldColumnName string, newColumnName string) error

TableColumnRename renames a column in a table.

func TableColumns

func TableColumns(ctx database.QueryableContext, tableName string, commonize bool) (columns []sb.Column, err error)

TableColumns returns a list of columns for a given table name.

func TableCreate

func TableCreate(ctx context.Context, db *sql.DB, tableName string, columns []sb.Column) error

TableCreate creates a table with the given columns.

func TableDrop

func TableDrop(ctx database.QueryableContext, tableName string) error

TableDrop drops a table from the database.

func TableDropIfExists

func TableDropIfExists(ctx database.QueryableContext, tableName string) error

TableDropIfExists drops a table from the database if it exists.

Types

This section is empty.

Jump to

Keyboard shortcuts

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