sql

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package sql defines a series of SQL queries and SQL-related constants for interacting with databases, particularly MySQL and PostgreSQL. The code is organized into sections for MySQL and PostgreSQL, with each section containing relevant SQL queries and related constants.

Index

Constants

View Source
const (
	/*------------------------
	 === Common Constants ===
	--------------------------*/
	SQLSelectAll string = `SELECT * FROM %s.%s`
	SQLUpdateRow string = `UPDATE %s SET %s = %s WHERE %s = %s`

	/*------------------------
	 === MySQL Constants ===
	--------------------------*/
	MySQLShowCreateTable   string = `SHOW CREATE TABLE %s.%s`
	MySQLGetColumnDataType        = `` /* 168-byte string literal not displayed */

	MySQLSchemaSize string = `` /* 185-byte string literal not displayed */

	MySQLShowDatabases     string = `SHOW DATABASES`
	MySQLCountTableColumns string = `` /* 140-byte string literal not displayed */

	MySQLCountTableRows string = `SELECT COUNT(*) FROM %s.%s`
	MySQLShowTables     string = `SHOW TABLES`
	MySQLDropTable      string = `DROP TABLE %s`
	MySQLDropDatabase   string = `DROP DATABASE %s`
	MySQLCreateDatabase string = `CREATE DATABASE %s`
	MySQLTruncateTable  string = `TRUNCATE TABLE %s`
	MySQLUse            string = `USE %s`
	MySQLColumnsInfo    string = `` /* 545-byte string literal not displayed */

	MySQLSelectAllWithLimit string = `SELECT %s FROM %s.%s LIMIT %d OFFSET %d`
	MySQLGetTablesSize      string = `` /* 226-byte string literal not displayed */

	MySQLGetTableSize string = `` /* 200-byte string literal not displayed */

	/*---------------------------
	 === PostgreSQL Constants ===
	-----------------------------*/
	PostgreSQLShowDatabases string = `
		SELECT
			datname
		FROM
			pg_database
		WHERE NOT 
			datistemplate
	`
	PostgreSQLShowTables string = `
		SELECT 
			table_name 
		FROM 
			information_schema.tables 
		WHERE 
			table_schema = '%s'
	`
	PostgreSQLSelectAllWithLimit string = `SELECT %s FROM %s.%s LIMIT %d OFFSET %d`
	PostgreSQLSchemaSize         string = `
		SELECT 
			pg_size_pretty(pg_database_size(current_database())) 
		AS 
			"database size"
	`
	PostgreSQLCountTableColumns string = `` /* 153-byte string literal not displayed */

	PostgreSQLCountTableRows string = `
		SELECT 
			count(*) AS "Total_Rows" 
		FROM 
			%s.%s
	`
	PostgreSQLTableSize string = `` /* 317-byte string literal not displayed */

	PostgreSQLGetColumnDataType = `` /* 163-byte string literal not displayed */

	PostgreSQLTableSizes string = `` /* 313-byte string literal not displayed */

	PostgreSQLDropTable      string = `DROP TABLE IF EXISTS %s`
	PostgreSQLDropDatabase   string = `DROP DATABASE IF EXISTS %s`
	PostgreSQLCreateDatabase string = `CREATE DATABASE %s`
	PostgreSQLTruncateTable  string = `TRUNCATE TABLE %s`
	PostgreSQLColumnsInfo    string = `` /* 851-byte string literal not displayed */

	// PostgreSQLShowCreateFunction is function that attempts to resemble the behaviour of mysql's 'show create' statement
	// the code is taken from an old answer found in
	// https://stackoverflow.com/questions/2593803/how-to-generate-the-create-table-sql-statement-for-an-existing-table-in-postgr
	PostgreSQLShowCreateFunction = `` /* 3214-byte string literal not displayed */

	PostgreSQLShowCreate             = `SELECT * FROM public.show_create_table('%s', '%s');`
	PostgreSQLDropShowCreateFunction = `DROP FUNCTION public.show_create_table(varchar, varchar);`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DbType

type DbType int

DbType represents an enumerated type for various database types.

const (
	MySQL DbType = iota + 1
	PostgreSQL
	SQLite
	Unsupported
)

Constants representing different database types.

func (DbType) EnumIndex

func (t DbType) EnumIndex() int

EnumIndex returns the integer index of the DbType. The index corresponds to the position of the DbType constant in the iota sequence. For example, MySQL has an index of 1, PostgreSQL has an index of 2, and so on.

func (DbType) String

func (t DbType) String() string

String returns the string representation of the DbType. It converts the DbType constant to its corresponding string value. If the DbType is not recognized, it returns "Unsupported".

Jump to

Keyboard shortcuts

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