Giter Club home page Giter Club logo

dalgo's Introduction

DALgo - Database Abstraction Layer (DAL) in Go

To use: go get github.com/dal-go/dalgo

Status

Build, Test, Vet, Lint Go Report Card Coverage Status Version GoDoc Sourcegraph

Summary

Using this module allows you:

  1. To abstract work with data storage so underlying API can be swapped.

  2. Write less code. Write more readable code.

  3. Easily add logging & hooks for all DB operations.

  4. Write unit tests for your business logic without dependency on specific API.

Quality Assurance

Overview generated by ChatGPT-4

The github.com/dal-go/dalgo package provides a consistent and flexible API for working with different types of databases in Go. By providing a single interface for different types of databases, dalgo allows developers to write code that is agnostic to the underlying data store. This can help reduce development time and improve code maintainability, while also providing the flexibility to choose the data store that best suits their needs. The package includes an easy-to-use API for querying, inserting, updating, and deleting records, as well as features for handling errors and logging. It also supports transactions.

Currently, the dalgo package supports a variety of different databases, including relational databases such as MS SQL Server, MySQL and PostgreSQL, as well as key-value stores like Redis and Memcached. It can also be used with cloud-based data stores like Google Firestore and Datastore.

It comes with a set of end-to-end tests that are run against different DB clients. By running these tests against multiple database clients, dalgo can ensure that it is compatible with a wide range of database systems and that it can handle scenarios such as concurrent access, complex queries, and schema changes.

Dalgo will include a code generation tool that can generate Go code for interacting with the database based on the database schema. This feature can be especially useful when working with large databases with complex schemas.

Overall, the dalgo package provides a consistent, flexible & agnostic API for working with different types of databases in Go. By allowing developers to write database-agnostic code, it provides a powerful tool for reducing development time and improving code maintainability, while also offering the flexibility to choose the data store that best suits their needs.

Packages

  • dal - Database Abstraction Layer
  • orm - Object–relational mapping
  • record - helpers to simplify working with dalgo records in strongly typed way.

DAL implementations for specific APIs

DALgo defines abstract interfaces and helpers methods to work with databases in abstract manner.

Here is modules that bridge DALgo to specific APIs:

Test coverage

The CI process for this package and for officially supported bridges runs unit tests and end-to-end integration tests.

DALgo interfaces

Package: github.com/dal-go/dalgo/dal

The main abstraction is though dalgo.Record interface :

package dal

type Record interface {
	Key() *Key          // defines `table` name of the entity
	Data() any          // value to be stored/retrieved (without ID)
	Error() error       // holds error for the record
	SetError(err error) // sets error relevant to specific record
	Exists() bool       // indicates if the record exists in DB
}

All methods are working with the Record and use context.Context.

The Database interface defines an interface to a storage that should be implemented by a specific driver. Contributions for client bridges are very welcome! If the db driver does not support some operations it must return dalgo.ErrNotSupported.

package dal

type Database interface {
	TransactionCoordinator
	ReadonlySession
}

// TransactionCoordinator provides methods to work with transactions
type TransactionCoordinator interface {

	// RunReadonlyTransaction starts readonly transaction
	RunReadonlyTransaction(ctx context.Context, f ROTxWorker, options ...TransactionOption) error

	// RunReadwriteTransaction starts read-write transaction
	RunReadwriteTransaction(ctx context.Context, f RWTxWorker, options ...TransactionOption) error
}

// ReadonlySession defines methods that do not modify database
type ReadonlySession interface {

	// Get gets a single record from database by key
	Get(ctx context.Context, record Record) error

	// GetMulti gets multiples records from database by keys
	GetMulti(ctx context.Context, records []Record) error

	// Select executes a data retrieval query
	Select(ctx context.Context, query Select) (Reader, error)
}

// ReadwriteSession defines methods that can modify database
type ReadwriteSession interface {
	ReadonlySession
	writeOnlySession
}

type writeOnlySession interface {

	// Insert inserts a single record in database
	Insert(c context.Context, record Record, opts ...InsertOption) error

	// Set sets a single record in database by key
	Set(ctx context.Context, record Record) error

	// SetMulti sets multiples records in database by keys
	SetMulti(ctx context.Context, records []Record) error

	// Update updates a single record in database by key
	Update(ctx context.Context, key *Key, updates []Update, preconditions ...Precondition) error

	// UpdateMulti updates multiples records in database by keys
	UpdateMulti(c context.Context, keys []*Key, updates []Update, preconditions ...Precondition) error

	// Delete deletes a single record from database by key
	Delete(ctx context.Context, key *Key) error

	// DeleteMulti deletes multiple records from database by keys
	DeleteMulti(ctx context.Context, keys []*Key) error
}

Note that getters are populating records in place using target instance obtained via Record.GetData().

Originally developed to support work with Google AppEngine Datastore and Firebase Firestore it takes into account its specifics. This works well with other key-value storages as well. Also dalgo supports SQL databases.

Projects & modules that use DALgo

More dependants can be found using SourceGraph search.

Contributions are welcome but should follow the contribution guidelines.

dalgo's People

Contributors

renovate-bot avatar renovate[bot] avatar trakhimenok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dalgo's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: File contents are invalid JSON but parse using JSON5. Support for this will be removed in a future release so please change to a support .json5 file name or ensure correct JSON syntax.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/ci.yml
gomod
go.mod
  • go 1.20
  • github.com/stretchr/testify v1.9.0
  • github.com/strongo/random v0.0.1

  • Check this box to trigger a request for Renovate to run again on this repository

feature: Implement `db:"field_name,noindex,omitmepty"` tags

Currently to mark a field as non indexed or omitempty it's required to use platform specific tags like:

type SomeEntity struct {
  SomeField string `datastore:"some_field,noindex,omitempty"`
}

Ideally we should have strongo/db tags that would be translated to desired required by specific adapters (like gaedb).

type SomeEntity struct {
  SomeField string `db:"some_field,noindex,omitempty"`
}

Probably DB adapters should be required to implement some interface to make sure the expected behavior is not being ignored.

feature: Implement simple query interface

Should support:

  • Simple filtering by AND (optional OR support)
  • Ordering (ascending & descending)
  • Limit(n int)
  • Query.String() to SQL
  • Cursor (optional, for 1st version)

Limitations:

  • Single entity (table), e.g. no joins (for now)

Initial implementation should have a bridge for Google AppEngine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.