client

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: 12 Imported by: 0

Documentation

Overview

Package client provides a versatile client for interacting with various database types, abstracting away the complexities of database connections and queries. It simplifies the process of working with different database types, such as MySQL and PostgreSQL.

The central component of this package is the `Client` type, which represents an active database client connected to a specific database. It includes essential connection details like host, port, username, password, database name, database type (e.g., MySQL or PostgreSQL), and schema information.

The package also includes various methods for fetching schema names, schema sizes, table names, column details, table data, and more. These methods are designed to work seamlessly with different database types, providing a consistent and convenient API for database interactions.

Note that this package assumes an already established database connection, and it focuses on simplifying data retrieval and schema exploration tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host     string      `json:"host"`
	Port     int         `json:"port"`
	User     string      `json:"user"`
	Password string      `json:"password"`
	Name     string      `json:"database"`
	Type     _sql.DbType `json:"databaseType"`
	Schema   Schema      `json:"schema"`
	Database *sql.DB
}

Client represent the active client connected to the db

func (*Client) CountTableColumns

func (c *Client) CountTableColumns(tableName string) (int, error)

func (*Client) CountTableRows

func (c *Client) CountTableRows(tableName string) (int, error)

func (*Client) ExportToCSV

func (c *Client) ExportToCSV(tableName string) (string, error)

func (*Client) ExportToCSVFile

func (c *Client) ExportToCSVFile(tableName string) (int, error)

func (*Client) ExportToJson

func (c *Client) ExportToJson(tableName string) ([]byte, error)

func (*Client) ExportToJsonFile

func (c *Client) ExportToJsonFile(tableName string) (int, error)

func (*Client) GetColumns

func (c *Client) GetColumns(tableName string) ([]Column, error)

func (*Client) GetColumnsData

func (c *Client) GetColumnsData(tableName string) (ColumnData, error)

func (*Client) GetSchemaNames

func (c *Client) GetSchemaNames() ([]string, error)

func (*Client) GetSchemaSize

func (c *Client) GetSchemaSize(name string) (SchemaSize, error)

func (*Client) GetTable

func (c *Client) GetTable(tableName string, page, perPage int) (*Table, error)

func (*Client) GetTableNames

func (c *Client) GetTableNames() ([]string, error)

func (*Client) GetTableSize

func (c *Client) GetTableSize(table string) (TableSize, error)

func (*Client) GetTablesSize

func (c *Client) GetTablesSize() ([]TableSize, error)

func (*Client) ShowCreateTable

func (c *Client) ShowCreateTable() (string, error)

func (*Client) ShowCreateTableFile

func (c *Client) ShowCreateTableFile() (int, error)

func (*Client) ShowCreateTableMySQL

func (c *Client) ShowCreateTableMySQL(tables []string, seperator string) (string, error)

func (*Client) ShowCreateTablePostgreSQL

func (c *Client) ShowCreateTablePostgreSQL(tables []string, seperator string) (string, error)

func (*Client) ShowCreateTableSQLite added in v0.0.2

func (c *Client) ShowCreateTableSQLite(tables []string, seperator string) (string, error)

type Column

type Column struct {
	Field            string `json:"field"`
	Type             string `json:"type"`
	Key              string `json:"key"`
	ConstraintName   string `json:"constraint_name"`
	ReferencedTable  string `json:"refrenced_table"`
	ReferencedColumn string `json:"refrenced_column"`
}

Column represents a column within a table, including its field name, data type, key type (e.g., PRI KEY), constraint name, and references to other tables and columns.

type ColumnData

type ColumnData struct {
	TableName string   `json:"table_name"`
	Columns   []Column `json:"columns"`
}

ColumnData represents column-related data for a specific table

type Row

type Row map[string]interface{}

Row represents a row within the table, inclusive of its related columns

type Schema

type Schema struct {
	Name      string  `json:"name"`
	NumTables int     `json:"number_of_tables"`
	Size      float64 `json:"size_mb"`
	Tables    []Table `json:"tables"`
}

Schema represent the db schema connected to

type SchemaSize

type SchemaSize struct {
	Name string  `json:"name"`
	Size float64 `json:"size_mb"`
}

SchemaSize holds information about the size of a schema

type Table

type Table struct {
	Name      string   `json:"table_name"`
	Data      []Row    `json:"data"`
	Columns   []Column `json:"columns"`
	N_columns int      `json:"n_columns"`
	N_rows    int      `json:"n_rows"`
	Size      float64  `json:"size_mb"`
}

Table Represents a table along with its name, data rows, columns, number of columns, number of rows, and size in megabytes

type TableSize

type TableSize struct {
	Table  string  `json:"table_name"`
	SizeMB float64 `json:"size_mb"`
}

TableSize holds information about the size of a schema

Jump to

Keyboard shortcuts

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