enpsql

package
v0.0.0-...-2935971 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: BSD-2-Clause Imports: 21 Imported by: 0

Documentation

Overview

Package enpsql .

Currently there is no automated schema management
so schema updates will have to be applied manually for each module

when making a module that makes use of this
please make a dedicated sql schema for each module as to avoid conflicts between modules
avoid using the public schema for anything in any modules

THIS PACKAGE DOES NOT ENFORCE SQL SCHEMA BOUNDRIES
you will need to ensure you manually specify the schema by namespacing table names

the public schema should only be used internally for this psql package

Index

Constants

This section is empty.

Variables

View Source
var Config = &localConfig{}

Config is the config that contains global config stuff, i mean it is named config so what else would it be

View Source
var Module = &module.Module{
	Name:        "enpsql",
	DgoHandlers: []interface{}{},

	Commands: []*drc.Command{},

	Config: Config,

	InitFunc: func(mod *module.Module) error {
		if !mod.ConfigFound {
			b := bytes.NewBuffer([]byte{})
			e := toml.NewEncoder(b)
			err := e.Encode(mod.Config)
			if err != nil {
				return err
			}

			fmt.Println(b.String())
			return fmt.Errorf("Config not found, database config data mandatory")
		}
		return nil
	},

	OpenFunc:  openFunc,
	CloseFunc: closeFunc,
}

Module contains the module, i mean what else would it contain being this is the database its probably a good idea to put this first in the module list

Functions

func GetSession

func GetSession() *dbr.Session

func Ping

func Ping() (time.Duration, error)

func RegisterSchema

func RegisterSchema(name string, updates []string)

RegisterSchema imports a list of schema updates to import from. keeps track of the schema versions currently in the database and will update it as new schemas updated are added. as mentioned in the package doc each package should also create its own SQL schema and avoid using the public schema or modifying schemas other than its own

Note that there is no gaurenteed order in which package schemas are updated an update in package A may be applied before or after package B even if they were pushed at the same time or have the same version number as such a schema update should not rely on another packages schema having recieved any particular schema update even if they are distributed together You may only rely on schema versions within a package being in the correct order, not the order of other packages (Eg, pkgA v3 will always happen before pkgA v4, but pkgB v3 may happen at any time relative to pkgA v3)

Schema versions should not be changed once they are in use, if a change is needed a new schema update should be added instead

the name should be treated as effectively static once in use, while theoretically possible to migrate doing such should be avoided if at all possible

func RegisterSchemaFS

func RegisterSchemaFS(name string, f fs.FS, dir string) error

RegisterSchemaFS is like RegisterSchema but it loads from a fs.FS (see RegisterSchema for more info). it expects the files to be formatted in the form of a decimal number followed by the .sql extension eg, 001.sql, 002.sql ... 015.sql ... They should be numbered starting from 1, and no numbers should be skipped, no files other than numbered sql files should be contained in the folder dir refers to the subdirectory in the fs.FS to load, as to make it easier to use things like embed.FS

Types

This section is empty.

Jump to

Keyboard shortcuts

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