postgres

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package postgres provides functionality for parsing and generating PostgreSQL database schemas. It implements the Parser interface for handling PostgreSQL specific SQL syntax and schema structures.

Index

Constants

This section is empty.

Variables

View Source
var (
	// PostgreSQLToMySQL PostgreSQL'den MySQL'e veri tipi dönüşümleri
	PostgreSQLToMySQL = map[string]string{
		"smallint":         "smallint",
		"integer":          "int",
		"bigint":           "bigint",
		"real":             "float",
		"double precision": "double",
		"decimal":          "decimal",
		"numeric":          "decimal",
		"char":             "char",
		"varchar":          "varchar",
		"text":             "text",
		"jsonb":            "json",
		"json":             "json",
		"timestamp":        "datetime",
		"date":             "date",
		"time":             "time",
		"bytea":            "blob",
		"boolean":          "boolean",
		"uuid":             "varchar(36)",
		"inet":             "varchar(45)",
		"cidr":             "varchar(45)",
		"macaddr":          "varchar(17)",
		"point":            "point",
		"line":             "linestring",
		"lseg":             "linestring",
		"box":              "polygon",
		"path":             "linestring",
		"polygon":          "polygon",
		"circle":           "polygon",
		"interval":         "varchar(255)",
	}

	// PostgreSQLToSQLServer PostgreSQL'den SQL Server'a veri tipi dönüşümleri
	PostgreSQLToSQLServer = map[string]string{
		"smallint":         "smallint",
		"integer":          "int",
		"bigint":           "bigint",
		"real":             "real",
		"double precision": "float",
		"decimal":          "decimal",
		"numeric":          "decimal",
		"char":             "char",
		"varchar":          "varchar",
		"text":             "varchar(max)",
		"jsonb":            "nvarchar(max)",
		"json":             "nvarchar(max)",
		"timestamp":        "datetime2",
		"date":             "date",
		"time":             "time",
		"bytea":            "varbinary(max)",
		"boolean":          "bit",
		"uuid":             "uniqueidentifier",
		"inet":             "varchar(45)",
		"cidr":             "varchar(45)",
		"macaddr":          "varchar(17)",
		"point":            "geometry",
		"line":             "geometry",
		"lseg":             "geometry",
		"box":              "geometry",
		"path":             "geometry",
		"polygon":          "geometry",
		"circle":           "geometry",
		"interval":         "varchar(255)",
	}

	// PostgreSQLToOracle PostgreSQL'den Oracle'a veri tipi dönüşümleri
	PostgreSQLToOracle = map[string]string{
		"smallint":         "NUMBER(5)",
		"integer":          "NUMBER(10)",
		"bigint":           "NUMBER(19)",
		"real":             "BINARY_FLOAT",
		"double precision": "BINARY_DOUBLE",
		"decimal":          "NUMBER",
		"numeric":          "NUMBER",
		"char":             "CHAR",
		"varchar":          "VARCHAR2",
		"text":             "CLOB",
		"jsonb":            "CLOB",
		"json":             "CLOB",
		"timestamp":        "TIMESTAMP",
		"date":             "DATE",
		"time":             "TIMESTAMP",
		"bytea":            "BLOB",
		"boolean":          "NUMBER(1)",
		"uuid":             "VARCHAR2(36)",
		"inet":             "VARCHAR2(45)",
		"cidr":             "VARCHAR2(45)",
		"macaddr":          "VARCHAR2(17)",
		"point":            "SDO_GEOMETRY",
		"line":             "SDO_GEOMETRY",
		"lseg":             "SDO_GEOMETRY",
		"box":              "SDO_GEOMETRY",
		"path":             "SDO_GEOMETRY",
		"polygon":          "SDO_GEOMETRY",
		"circle":           "SDO_GEOMETRY",
		"interval":         "INTERVAL DAY TO SECOND",
	}

	// PostgreSQLToSQLite PostgreSQL'den SQLite'a veri tipi dönüşümleri
	PostgreSQLToSQLite = map[string]string{
		"smallint":         "INTEGER",
		"integer":          "INTEGER",
		"bigint":           "INTEGER",
		"real":             "REAL",
		"double precision": "REAL",
		"decimal":          "REAL",
		"numeric":          "REAL",
		"char":             "TEXT",
		"varchar":          "TEXT",
		"text":             "TEXT",
		"jsonb":            "TEXT",
		"json":             "TEXT",
		"timestamp":        "TEXT",
		"date":             "TEXT",
		"time":             "TEXT",
		"bytea":            "BLOB",
		"boolean":          "INTEGER",
		"uuid":             "TEXT",
		"inet":             "TEXT",
		"cidr":             "TEXT",
		"macaddr":          "TEXT",
		"point":            "TEXT",
		"line":             "TEXT",
		"lseg":             "TEXT",
		"box":              "TEXT",
		"path":             "TEXT",
		"polygon":          "TEXT",
		"circle":           "TEXT",
		"interval":         "TEXT",
	}
)

PostgreSQL'den diğer veritabanı tiplerine veri tipi dönüşüm haritaları

Functions

This section is empty.

Types

type PostgreSQL

type PostgreSQL struct {
	// contains filtered or unexported fields
}

PostgreSQL represents a PostgreSQL parser implementation that handles parsing and generating PostgreSQL database schemas. It maintains an internal schema representation and provides methods for converting between PostgreSQL SQL and the common schema format.

func NewPostgreSQL

func NewPostgreSQL() *PostgreSQL

NewPostgreSQL creates and initializes a new PostgreSQL parser instance. It returns a parser that can handle PostgreSQL specific SQL syntax and schema structures.

func (*PostgreSQL) Generate

func (p *PostgreSQL) Generate(schema *sqlmapper.Schema) (string, error)

Generate creates a PostgreSQL SQL dump from a schema structure. It generates SQL statements for all database objects in the schema, including: - Tables with columns and constraints - Indexes - Views - Functions and procedures - Triggers - Permissions

Parameters:

  • schema: The schema structure to convert to PostgreSQL SQL

Returns:

  • string: The generated PostgreSQL SQL statements
  • error: An error if generation fails

func (*PostgreSQL) Parse

func (p *PostgreSQL) Parse(content string) (*sqlmapper.Schema, error)

Parse takes a PostgreSQL SQL dump content and parses it into a common schema structure. It processes various PostgreSQL objects including: - Schemas and databases - Custom types (ENUM, COMPOSITE) - Extensions - Sequences - Tables with columns and constraints - Indexes - Views (regular and materialized) - Functions and procedures - Triggers - Permissions (GRANT/REVOKE)

Parameters:

  • content: The PostgreSQL SQL dump content to parse

Returns:

  • *sqlmapper.Schema: The parsed schema structure
  • error: An error if parsing fails

Jump to

Keyboard shortcuts

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