Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.
/ dal Public archive

Database Access Layer written in Go for Postgres

License

Notifications You must be signed in to change notification settings

neumachen/dal

Repository files navigation

Build Status Coverage Status Doc Go Report Card

dal - Database Access Layer

Description

This package is very opinionated. It aims to eliminate inline code SQL statemnts by requiring a virtual file system that will hold all the sql templates in memory during runtime.

This package wraps the database/sql package.

Development

This package is still under active development. It is wise to vendor this package because although not planned some breaking API changes may be introduced.

Required Interfaces

type FileStore interface {
    Get(file string) (string, error)
}

The interface FileStore is a required interface that must be implemented in order to instantiate a new DAL because this is need when calling the query methods for the purpose of parsing the SQL template.

Usage

package main

func main() {
    lgr := func(msg string) {
        log.Println(msg)
    }

    dataStore, err := loadDataStore(envcfg.PgDbCreds(), envcfg.DbPingTime(), fileStore, lgr)
    if err != nil {
        log.Fatalln(err)
    }
}


func loadDataStore(dbCreds string, dbPingTime int, fileStore vfs.Store, lgr finlog.Logger) (dal.DAL, error) {
    pgdal, openErr := dal.Open("postgres", envcfg.PgDbCreds())
    if openErr != nil {
            return nil, openErr
    }

    lgrFunc := func(msg string) {
            lgr.Info(msg)
    }

    pingErr := dal.PingDatabase(pgdal, dbPingTime, lgrFunc)
    if pingErr != nil {
            return nil, pingErr
    }

    return dal.New(pgdal, fileStore), nil
}

About

Database Access Layer written in Go for Postgres

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published