db

package
v0.0.0-...-fe143b1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

type Card struct {
	CardID           int64          `json:"cardId"`
	CardName         string         `json:"cardName"`
	CardType         string         `json:"cardType"`
	CardArtist       string         `json:"cardArtist"`
	CardEffect       NullStringJSON `json:"cardEffect,omitempty"`
	CardPower        NullInt64JSON  `json:"cardPower,omitempty"`
	CardIntelligence NullInt64JSON  `json:"cardIntelligence,omitempty"`
	CardEndurance    NullInt64JSON  `json:"cardEndurance,omitempty"`
}

---------------------------------

Data Structures

---------------------------------- Card describes the required and optional data needed to create a new card in our card table

type CardCreate

type CardCreate struct {
	CardName         string         `json:"cardName"`
	CardType         string         `json:"cardType"`
	CardArtist       string         `json:"cardArtist"`
	CardEffect       NullStringJSON `json:"cardEffect,omitempty"`
	CardPower        NullInt64JSON  `json:"cardPower,omitempty"`
	CardIntelligence NullInt64JSON  `json:"cardIntelligence,omitempty"`
	CardEndurance    NullInt64JSON  `json:"cardEndurance,omitempty"`
}

CardCreate describes the data needed to create a given card in our db

type CardManager

type CardManager interface {
	GetAllCards() ([]*Card, error)
	GetCardsByCardType(cardType string) ([]*Card, error)
	GetCardByCardName(cardName string) (*Card, error)

	CreateCard(cardCreate *CardCreate) (int64, error)
	UpdateCard(cardUpdate *CardUpdate) (int64, error)
}

CardManager describes all of the methods used to interact with the card table in our database

type CardUpdate

type CardUpdate struct {
	CardID           int64          `json:"cardId,omitempty"`
	CardName         NullStringJSON `json:"cardName,omitempty"`
	CardType         NullStringJSON `json:"cardType,omitempty"`
	CardArtist       NullStringJSON `json:"cardArtist,omitempty"`
	CardEffect       NullStringJSON `json:"cardEffect,omitempty"`
	CardPower        NullInt64JSON  `json:"cardPower,omitempty"`
	CardIntelligence NullInt64JSON  `json:"cardIntelligence,omitempty"`
	CardEndurance    NullInt64JSON  `json:"cardEndurance,omitempty"`
}

CardUpdate describes the data needed to update a given card in our db

type DB

type DB struct {
	*sql.DB
}

DB is the struct that we're going to use to implement all of our Datasbase interfaces; All of the methods defined on each of our interfaces will be implemented on this DB struct

func New

func New() (*DB, error)

New initializes a new postgres database connection and attaches said connection to our DB struct, which we can then call all of the methods described by the our varies Database interfaces

func (*DB) CreateCard

func (db *DB) CreateCard(cardCreate *CardCreate) (int64, error)

CreateCard adds a new entry to the card table in our database

func (*DB) CreateSet

func (db *DB) CreateSet(setCreate *SetCreate) (*Set, error)

---------------------------------

Method Implementations

---------------------------------- CreateSet adds a new entry to the card table in our database

func (*DB) GetAllCards

func (db *DB) GetAllCards() ([]*Card, error)

GetAllCards fetches all cards in our db

func (*DB) GetCardByCardName

func (db *DB) GetCardByCardName(cardName string) (*Card, error)

GetCardByCardName fetches a specific card by its name from the db

func (*DB) GetCardsByCardType

func (db *DB) GetCardsByCardType(cardType string) ([]*Card, error)

GetCardsByCardType fetches all cards with a specific type

func (*DB) UpdateCard

func (db *DB) UpdateCard(cardUpdate *CardUpdate) (int64, error)

UpdateCard updates an existing entry in the cards table

type DatabaseManager

type DatabaseManager interface {
	CardManager
	SetManager
}

DatabaseManager combines all of the database interactions into one

type NullBoolJSON

type NullBoolJSON struct {
	sql.NullBool
}

NullBoolJSON extends sql.NullBool to nicely (Un)Marshal JSON

func (*NullBoolJSON) MarshalJSON

func (nb *NullBoolJSON) MarshalJSON() ([]byte, error)

MarshalJSON handles sql.NullBool to JSON

func (*NullBoolJSON) UnmarshalJSON

func (nb *NullBoolJSON) UnmarshalJSON(data []byte) error

UnmarshalJSON handles JSON to sql.NullBool

type NullInt64JSON

type NullInt64JSON struct {
	sql.NullInt64
}

NullInt64JSON extends sql.NullInt64 to nicely (Un)Marshal JSON

func (*NullInt64JSON) MarshalJSON

func (ni *NullInt64JSON) MarshalJSON() ([]byte, error)

MarshalJSON handles sql.NullInt64 to JSON

func (*NullInt64JSON) UnmarshalJSON

func (ni *NullInt64JSON) UnmarshalJSON(data []byte) error

UnmarshalJSON handles JSON to sql.NullInt64

type NullStringJSON

type NullStringJSON struct {
	sql.NullString
}

NullStringJSON extends sql.NullString to nicely (Un)Marshal JSON

func (*NullStringJSON) MarshalJSON

func (ns *NullStringJSON) MarshalJSON() ([]byte, error)

MarshalJSON handles sql.NullString to JSON

func (*NullStringJSON) UnmarshalJSON

func (ns *NullStringJSON) UnmarshalJSON(data []byte) error

UnmarshalJSON handles JSON to sql.NullString

type NullTimeJSON

type NullTimeJSON struct {
	pq.NullTime
}

NullTimeJSON extends pq.NullTime to nicely (Un)Marshal JSON

func (*NullTimeJSON) MarshalJSON

func (nt *NullTimeJSON) MarshalJSON() ([]byte, error)

MarshalJSON handles pq.NullTime to JSON

func (*NullTimeJSON) UnmarshalJSON

func (nt *NullTimeJSON) UnmarshalJSON(data []byte) error

UnmarshalJSON handles JSON to pq.NullTime

type Set

type Set struct {
	SetID   int64  `json:"setId"`
	SetName string `json:"setName"`
}

---------------------------------

Data Structures

---------------------------------- Set describes the required and optional data needed to create a new set in our set table

type SetCreate

type SetCreate struct {
	SetName string `json:"setName"`
}

SetCreate describes the data needed to create a given set in our db

type SetManager

type SetManager interface {
	CreateSet(setCreate *SetCreate) (*Set, error)
}

SetNabager describes all of the methods used to interact with the set table in our database

Jump to

Keyboard shortcuts

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