sql

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package database is part of the Tarmac suite of Host Callback packages. This package provides users with the ability to provide WASM functions with a host callback interface that provides SQL database capabilities.

import (
	"github.com/madflojo/tarmac/pkg/callbacks"
	"github.com/madflojo/tarmac/pkg/callbacks/sql"
)

func main() {
	// Create instance of database to register for callback execution
	dBase := database.New(sql.Config{})

	// Create Callback router and register
	router := callbacks.New()
	router.RegisterCallback("sql", "query", dBase.Query)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DB is the user-provided SQL database instance using the standard "database/sql" interface. This package by
	// itself does not manage database connections but rather relies on the sql.DB interface. Users must
	// supply an initiated sql.DB to work with.
	DB *sql.DB
}

Config is provided to users to configure the Host Callback. All Tarmac Callbacks follow the same configuration format; each Config struct gives the specific Host Callback unique functionality.

type Database

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

Database provides access to Host Callbacks that interface with a SQL database within Tarmac. The callbacks within Database provide all the logic and error hangling of accessing and interacting with a SQL database. Users will send the specified JSON request to execute a query and receive an appropriate JSON response.

func New

func New(cfg Config) (*Database, error)

New will create and return a new Database instance that users can register as a Tarmac Host Callback function. Users can provide any custom Database configurations using the configuration options supplied.

func (*Database) Query

func (db *Database) Query(b []byte) ([]byte, error)

Query will execute the supplied query against the supplied database. Error handling, processing results, and base64 encoding of data are all handled via this function. Note, this function expects the SQLQueryJSON type as input and will return a SQLQueryResponse JSON.

Jump to

Keyboard shortcuts

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