Documentation
¶
Overview ¶
Package meta is what the database says about SQL queries and tables, as is: no settings, no type-map, no DTO fields. It mirrors IDbMetadata of the Java plug-in one to one, so that the generator output can be compared byte for byte (cli/metadump against MetaDump.java).
Types are named by Java names (java.lang.Integer, java.util.Date, ...): the keys <type detected=...> in settings.xml of existing projects depend on them.
RawType is the same in the driver's words: the second vocabulary of type-map keys, on a par with Java names.
Index ¶
- Constants
- func IsQuotedName(s string) bool
- func QuoteName(name, quote string) string
- func SplitTableRef(ref string) ([]string, bool)
- func UnquoteName(s string) string
- func UnquoteTableRef(ref string) string
- type Catalog
- type Column
- type ImportedKey
- type Metadata
- type Params
- type Table
- type TableColumn
Constants ¶
const ( JavaObject = "java.lang.Object" // RawUnknown is the raw name of a type the driver said nothing about (a type-map key) RawUnknown = "unknown" )
Variables ¶
This section is empty.
Functions ¶
func IsQuotedName ¶ added in v1.1.2
IsQuotedName reports whether s is a name in square brackets, double quotes or backticks.
func QuoteName ¶ added in v1.1.2
QuoteName is a table or a schema name for XML: as it is if it is a plain name, otherwise quoted by quote, the identifier quote of the database ("[" means [] of SQL Server, "" means no quoting).
func SplitTableRef ¶ added in v1.1.2
SplitTableRef returns the parts of "schema.table" split by the dots outside of quotes; false if a quote is not closed.
func UnquoteName ¶ added in v1.1.2
UnquoteName strips the quotes of a quoted name: [Order Details] -> Order Details.
func UnquoteTableRef ¶ added in v1.1.2
UnquoteTableRef is the name for the catalog: [dbo].[Order Details] -> dbo.Order Details.
Types ¶
type Catalog ¶
type Catalog interface {
// Tables lists the tables and, if includeViews, the views of the database, as
// getTables(null, "%", TABLE, VIEW) sorts them: tables first, then views, by name.
Tables(includeViews bool) ([]string, error)
// ImportedKeys lists the foreign key columns of table: by PK table, then key order.
ImportedKeys(table string) ([]ImportedKey, error)
// IdentifierQuote is getIdentifierQuoteString: the quote of the names the assistants write
// quoted when they are not plain names (QuoteName).
IdentifierQuote() string
}
Catalog is what the XML assistants read from the database (SdmUtils of the Java plug-in): getTables and getImportedKeys.
type Column ¶
type Column struct {
Name string
JavaType string // JavaObject if not determined
RawType string // the type in the driver's words (pg: int4, MySQL: INT, SQLite: INTEGER); "" means not reported
IsAI bool
Scale int
Precision int
DisplaySize int
}
Column is a result column (ResultSetMetaData).
type ImportedKey ¶
ImportedKey is a row of getImportedKeys: PKTABLE_NAME and FKCOLUMN_NAME.
type Metadata ¶
type Metadata interface {
// SQLColumns returns the result columns of jdbcSQL (SQL with '?').
SQLColumns(jdbcSQL string) ([]Column, error)
// Table runs 'select * from tableRef' and adds what the catalog says about the columns.
Table(tableRef string) (*Table, error)
// PKColNames returns the names of the PK columns in key order.
PKColNames(tableRef string) ([]string, error)
// SQLParams returns the parameters of jdbcSQL; types are read for indexes 0..typeCount-1.
SQLParams(jdbcSQL string, typeCount int) (*Params, error)
// RawOfJava returns a Java type name from the plug-in XML (java.lang.Integer) in the words of this database's driver
// (pg: int4, MySQL: INT, SQLite: INTEGER); "" means unknown.
RawOfJava(javaType string) string
Close() error
}
Metadata has one implementation per dialect (pg, mysql, sqlite, mssql).
func Cached ¶
Cached remembers the answers of md for one generation run: the schema does not change meanwhile, and the same table or SQL is asked for many times (the model, its <crud>, the DTO and the DAO passes of the Java plug-in), each time a few round trips to a remote database. Errors are remembered too: the same question gets the same answer. Every call returns its own copy of the slices.
type Table ¶
type Table struct {
Columns []Column // 'select * from table'
// in getColumns order; the same column may come several times (tables of the same
// name in different schemas), and then each row refines it once more
TableColumns []TableColumn
}
type TableColumn ¶
type TableColumn struct {
Name string
DataType *int // java.sql.Types
RawType string // the type in the driver's words; needed where the result column does not know it (SQLite)
ColumnSize *int
DecimalDigits *int
IsAI *bool
IsNullable *bool
FK string // "pk_table.pk_column" or ""
IsIndexed bool
IsUnique bool
}
TableColumn is a row of DatabaseMetaData.getColumns. nil means the driver could not report it.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package metadump prints meta.Metadata in the text format of MetaDump.java (sdm-plugins/src_harness), to compare the output with the Java plug-in by plain diff.
|
Package metadump prints meta.Metadata in the text format of MetaDump.java (sdm-plugins/src_harness), to compare the output with the Java plug-in by plain diff. |
|
Package mssql is meta.Metadata on top of microsoft/go-mssqldb.
|
Package mssql is meta.Metadata on top of microsoft/go-mssqldb. |
|
Package mysql is meta.Metadata on top of MySQL 8 (go-mysql-org/go-mysql: pure Go and the protocol fields in full: flags, charset, length, which database/sql does not expose).
|
Package mysql is meta.Metadata on top of MySQL 8 (go-mysql-org/go-mysql: pure Go and the protocol fields in full: flags, charset, length, which database/sql does not expose). |
|
Package pg is meta.Metadata on top of pgx.
|
Package pg is meta.Metadata on top of pgx. |
|
Package sqlite is meta.Metadata on top of SQLite (ncruces/go-sqlite3: pure Go, no cgo).
|
Package sqlite is meta.Metadata on top of SQLite (ncruces/go-sqlite3: pure Go, no cgo). |