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 ¶
- type Client
- func (c *Client) CountTableColumns(tableName string) (int, error)
- func (c *Client) CountTableRows(tableName string) (int, error)
- func (c *Client) ExportToCSV(tableName string) (string, error)
- func (c *Client) ExportToCSVFile(tableName string) (int, error)
- func (c *Client) ExportToJson(tableName string) ([]byte, error)
- func (c *Client) ExportToJsonFile(tableName string) (int, error)
- func (c *Client) GetColumns(tableName string) ([]Column, error)
- func (c *Client) GetColumnsData(tableName string) (ColumnData, error)
- func (c *Client) GetSchemaNames() ([]string, error)
- func (c *Client) GetSchemaSize(name string) (SchemaSize, error)
- func (c *Client) GetTable(tableName string, page, perPage int) (*Table, error)
- func (c *Client) GetTableNames() ([]string, error)
- func (c *Client) GetTableSize(table string) (TableSize, error)
- func (c *Client) GetTablesSize() ([]TableSize, error)
- func (c *Client) ShowCreateTable() (string, error)
- func (c *Client) ShowCreateTableFile() (int, error)
- func (c *Client) ShowCreateTableMySQL(tables []string, seperator string) (string, error)
- func (c *Client) ShowCreateTablePostgreSQL(tables []string, seperator string) (string, error)
- func (c *Client) ShowCreateTableSQLite(tables []string, seperator string) (string, error)
- type Column
- type ColumnData
- type Row
- type Schema
- type SchemaSize
- type Table
- type TableSize
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 (*Client) GetColumnsData ¶
func (c *Client) GetColumnsData(tableName string) (ColumnData, error)
func (*Client) GetSchemaNames ¶
func (*Client) GetSchemaSize ¶
func (c *Client) GetSchemaSize(name string) (SchemaSize, error)
func (*Client) GetTableNames ¶
func (*Client) GetTablesSize ¶
func (*Client) ShowCreateTable ¶
func (*Client) ShowCreateTableFile ¶
func (*Client) ShowCreateTableMySQL ¶
func (*Client) ShowCreateTablePostgreSQL ¶
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 ¶
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 ¶
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