Dalgo

Database Abstraction Layer (DAL) in Go language
Alternatives To Dalgo
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Tidb34,18568101a day ago1,289April 07, 20224,039apache-2.0Go
TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://tidbcloud.com/free-trial
Metabase32,667
21 hours ago1June 08, 20223,049otherClojure
The simplest, fastest way to get business intelligence and analytics to everyone in your company :yum:
Dbeaver32,313
21 hours ago1,750apache-2.0Java
Free universal database tool and SQL client
Cockroach27,260502221 hours ago248August 06, 20216,607otherGo
CockroachDB - the open source, cloud-native distributed SQL database.
Sqlmap27,229
3 days ago1February 27, 201858otherPython
Automatic SQL injection and database takeover tool
Directus21,8225021 hours ago55September 22, 2022221otherTypeScript
The Modern Data Stack 🐰 — Directus is an instant REST+GraphQL API and intuitive no-code data collaboration app for any SQL database.
Tdengine21,4211a day ago12April 14, 20221,032agpl-3.0C
TDengine is an open source, high-performance, cloud native time-series database optimized for Internet of Things (IoT), Connected Cars, Industrial IoT and DevOps.
Surrealdb20,733
a day ago35December 14, 2021228otherRust
A scalable, distributed, collaborative, document-graph database, for the realtime web
Postgrest20,635
42 days ago37July 12, 2022207mitHaskell
REST API for any Postgres database
Shardingsphere18,469821 hours ago7June 04, 2020742apache-2.0Java
Ecosystem to transform any database into a distributed database system, and enhance it with sharding, elastic scaling, encryption features & more
Alternatives To Dalgo
Select To Compare


Alternative Project Comparisons
Readme

DALgo - Database Abstraction Layer (DAL) in Go

To use: go getgithub.com/dal-go/dalgo

Status

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

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.

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 - Objectrelational 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.

Contributing

Contributions are welcome but should follow the contribution guidelines.

Popular Database Projects
Popular Sql Projects
Popular Data Storage Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Golang
Database
Sql
Nosql
Golang Library