sqlite3

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Overview

Example (GenerateWithSchema)
package main

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

func main() {
	q, err := sqlite3.Open("db.sqlite")
	if err != nil {
		panic(err)
	}
	defer q.Close()

	err = sqlite3.GenerateWithSchema(context.Background(), q,
		[]string{"Table"},
		func(w *files.Writer, schemas sqlite3.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)
	}
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateWithSchema

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

func Open

func Open(dsn string) (queryer, error)

Types

type Column

type Column struct {
	Name     string
	Type     string
	Nullable bool
}

type ForeignKey

type ForeignKey struct {
	Key       []string
	Reference ForeignKeyReference
}

type ForeignKeyReference

type ForeignKeyReference struct {
	Table string
	Key   []string
}

type Generator

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

type Index

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

type IndexKeyElem

type IndexKeyElem struct {
	Name string
	Desc bool
}

type IndexOrigin

type IndexOrigin string

IndexOrigin is a type for the origin of an index. https://www.sqlite.org/pragma.html#pragma_index_list > "c" if the index was created by a CREATE INDEX statement, "u" if the index was created by a UNIQUE constraint, or "pk" if the index was created by a PRIMARY KEY constraint.

const (
	IndexOriginPrimaryKey       IndexOrigin = "pk"
	IndexOriginCreateIndex      IndexOrigin = "c"
	IndexOriginUniqueConstraint IndexOrigin = "u"
)

type Schema

type Schema struct {
	Name        string
	Type        string
	Columns     []Column
	PrimaryKey  []string
	ForeignKeys []ForeignKey
	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 {
	Schema string
	Name   string
}

func ListTables

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

Jump to

Keyboard shortcuts

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