postgres

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: BSD-2-Clause Imports: 7 Imported by: 1

Documentation

Overview

Example (GenerateWithSchema)
package main

import (
	"context"
	"fmt"
	"github.com/Jumpaku/schenerate/files"
	"github.com/Jumpaku/schenerate/postgres"
)

func main() {
	ctx := context.Background()
	q, err := postgres.Open("postgres://<user>:<password>@<host>:<port>/<dbname>")
	if err != nil {
		panic(err)
	}
	defer q.Close()

	err = postgres.GenerateWithSchema(ctx, q,
		[]string{"Table"},
		func(w *files.Writer, schemas postgres.Schemas) error {
			for _, schema := range schemas {
				// do something with schemas
				w.Add(schema.Name)
				fmt.Fprintf(w, "%+v\n", schema.Name)
			}
			return nil
		},
	)
	if err != nil {
		panic(err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateWithQuery added in v0.0.5

func GenerateWithQuery[RecordStruct any](ctx context.Context, q queryer, stmt string, params []any, generator GeneratorWithQuery[RecordStruct]) error

func GenerateWithSchema

func GenerateWithSchema(ctx context.Context, q queryer, tables []string, generator Generator) error

func Open

func Open(connStr string) (queryer, error)

func QueryRows added in v0.0.5

func QueryRows[RecordStruct any](ctx context.Context, q queryer, stmt string, params []any) (records []RecordStruct, err error)

Types

type Column

type Column struct {
	Name     string
	Type     string
	Nullable bool
}

type ForeignKey

type ForeignKey struct {
	Name      string
	Key       []string
	Reference ForeignKeyReference
}

type ForeignKeyReference

type ForeignKeyReference struct {
	Schema string
	Table  string
	Key    []string
}

type Generator

type Generator func(out *files.Writer, schemas Schemas) error

type GeneratorWithQuery added in v0.0.5

type GeneratorWithQuery[RecordStruct any] func(out *files.Writer, rows []RecordStruct) error

type Index

type Index struct {
	Name   string
	Unique bool
	Key    []string
}

type IndexKeyElem

type IndexKeyElem struct {
	Name string
	Desc bool
}

type Schema

type Schema struct {
	Schema      string
	Name        string
	Type        string
	Columns     []Column
	PrimaryKey  []string
	ForeignKeys []ForeignKey
	UniqueKeys  []UniqueKey
	Indexes     []Index
}

func ListSchemas added in v0.0.4

func ListSchemas(ctx context.Context, q queryer, tables []string) (schemas []Schema, err error)

type Schemas

type Schemas []Schema

type Table

type Table struct {
	Catalog string
	Schema  string
	Name    string
}

func ListTables

func ListTables(ctx context.Context, q queryer) ([]Table, error)

type UniqueKey

type UniqueKey struct {
	Name string
	Key  []string
}

Jump to

Keyboard shortcuts

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