tinydriver

package module
v0.0.0-...-7c1c343 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2022 License: BSD-3-Clause Imports: 16 Imported by: 0

README

Tiny-driver

Yet another PostgreSQL driver.

The driver was written for educational purposes for my article on the Medium

A minimum of functionality has been implemented which should be enough to explain the principle of work.

Do not use in production 💀

Was inspired by:

Example
import (
    "database/sql"
    _ "github.com/ihippik/tiny-driver"
)

func main() {
    dsn := "postgres://postgres:postgrespw@localhost:55000/postgres?sslmode=disable"
    db, err := sql.Open("tiny", dsn)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

func (*Buffer) CalculateSize

func (b *Buffer) CalculateSize(prefix int)

func (*Buffer) Data

func (b *Buffer) Data() []byte

func (*Buffer) WriteBytes

func (b *Buffer) WriteBytes(data []byte)

func (*Buffer) WriteInt32

func (b *Buffer) WriteInt32(n int32)

func (*Buffer) WriteStartMsg

func (b *Buffer) WriteStartMsg(msgType byte)

func (*Buffer) WriteString

func (b *Buffer) WriteString(str string)

type Config

type Config struct {
	Network  string
	Host     string
	Port     int
	Username string
	Password string
	Database string
}

func (*Config) Addr

func (c *Config) Addr() string

type Connection

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

func NewConnection

func NewConnection(ctx context.Context, cfg *Config) (*Connection, error)

func (*Connection) Begin

func (c *Connection) Begin() (driver.Tx, error)

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) Prepare

func (c *Connection) Prepare(query string) (driver.Stmt, error)

func (*Connection) QueryContext

func (c *Connection) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)

type Connector

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

func NewConnector

func NewConnector(cfg *Config) *Connector

func (*Connector) Connect

func (c *Connector) Connect(ctx context.Context) (driver.Conn, error)

func (*Connector) Driver

func (c *Connector) Driver() driver.Driver

type Driver

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

func NewDriver

func NewDriver() *Driver

func (*Driver) Open

func (d *Driver) Open(name string) (driver.Conn, error)

func (*Driver) OpenConnector

func (d *Driver) OpenConnector(name string) (driver.Connector, error)

type Reader

type Reader struct {
	*bufio.Reader
}

func NewReader

func NewReader(reader *bufio.Reader) *Reader

func (Reader) Discard

func (r Reader) Discard(n int32) error

func (Reader) Int32

func (r Reader) Int32() (int32, error)

func (Reader) MsgLen

func (r Reader) MsgLen() (int32, error)

func (Reader) ReadMessageType

func (r Reader) ReadMessageType() (byte, error)

func (Reader) ReadNumBytes

func (r Reader) ReadNumBytes(num int) ([]byte, error)

func (Reader) String

func (r Reader) String() (string, error)

Jump to

Keyboard shortcuts

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