sqlite

package
v0.0.0-...-16bbc8a Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

sqlite is a package designed to interact specifically with the SQLite3 database engine. It is configured by default to use SQLite's "write to disk" functionality to store data in a flat file on the OS.

Index

Constants

View Source
const SEPARATOR = ","

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

DBClient is the atomic unit of interacting with SQLite.

func NewClient

func NewClient(filename string) (*Client, error)

NewClient creates a client and opens a connection to a database. It allows for connection to arbitrarily named databases. It returns a pointer to a DBClient object if successful; an error otherwise.

filename is the name of the flat file where the data will be stored.

It returns a pointer to a DBClient object if successful; an error otherwise.

func (*Client) AddIPDetails

func (c *Client) AddIPDetails(contract model.IPDetails) (*model.IPDetails, error)

AddIPDetails is the creation operation for adding new data to the database. It returns a representation of the object added to the database if successful; an error otherwise.

contract is the data model used by most of the system for IPDetails and represents the object to be stored.

It returns a representation of the object added to the database if successful; an error otherwise.

func (*Client) Close

func (c *Client) Close() error

Close will attempt to close the database connection. This should usually be called with a defer statement when opening any connection to the database.

func (*Client) GetIPDetailByAddress

func (c *Client) GetIPDetailByAddress(address string) (*model.IPDetails, error)

GetIPDetailByAddress is the retrieval operation for getting data from the database. It returns a representation of the object requested in the database if successful; an error otherwise.

address is the IP address that we want to query the database for.

It returns a representation of the object requested in the database if successful; an error otherwise.

func (*Client) UpdateIPDetails

func (c *Client) UpdateIPDetails(contract model.IPDetails) (*model.IPDetails, error)

UpdateIPDetails is the update operation for editing data to the database. It returns a representation of the object updated in the database if successful; an error otherwise.

contract is the data model used by most of the system for IPDetails and represents the object to be stored.

It returns a representation of the object updated it the database if successful; an error otherwise.

type IPDetails

type IPDetails struct {
	ID           string
	CreatedAt    time.Time `db:"created_at"`
	UpdatedAt    time.Time `db:"updated_at"`
	ResponseCode string    `db:"response_code"`
	IPAddress    string    `db:"ip_address"`
}

IPDetails is a struct designed to make interacting with the database easier. The struct used by most of the system is close, but not quite what we need for interacting with the DB.

Jump to

Keyboard shortcuts

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