query

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package query provides a set of functions for interacting with SQL databases, including executing queries, updating rows, and performing various database operations.

This package includes functionalities for:

  • Executing SQL queries.
  • Updating rows in database tables.
  • Retrieving and handling column data types.
  • Wrapping values and primary keys for SQL update statements.
  • Performing database operations such as dropping tables, truncating tables, dropping databases, and creating databases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Query

type Query struct {
	SQLQuery string `json:"query"`
}

Query represents a SQL query

type Result

type Result struct {
	AffectedRows int64                    `json:"affected_rows"`
	Time         string                   `json:"time_taken"`
	Data         []map[string]interface{} `json:"data"`
	Msg          string                   `json:"message"`
}

Result represents the result of a database operation.

func CreateDatabase

func CreateDatabase(dbname string, db *sql.DB) (*Result, error)

func DropDatabase

func DropDatabase(dbname string, db *sql.DB) (*Result, error)

func DropTable

func DropTable(table, dbname string, db *sql.DB) (*Result, error)

func ExecuteQuery

func ExecuteQuery(q *Query, client *_client.Client) (*Result, error)

func TruncateTable

func TruncateTable(table, dbname string, db *sql.DB) (*Result, error)

func UpdateRow

func UpdateRow(table, parentCol, newVal, priKeyVal, priKeyCol string, client *_client.Client) (*Result, error)

UpdateRow constructs and executes an SQL UPDATE statement to modify a row in the specified table. The function handles checking the column data type, and wraps its value in single quotes if necessary. Returns the result of the update operation or any encountered errors.

Jump to

Keyboard shortcuts

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