Code Monkey home page Code Monkey logo

styx's Introduction

Styx

Database Engine for different SQL and NoSQL databases

Install

go get -u github.com/masudur-rahman/styx

Quickstart

package main

import (
	"context"
	"time"

	"github.com/masudur-rahman/styx/sql"
	"github.com/masudur-rahman/styx/sql/sqlite"
	"github.com/masudur-rahman/styx/sql/sqlite/lib"
)

type User struct {
	ID        int64     `db:"id,pk autoincr"`
	Name      string    `db:"name,uq"`
	FullName  string    `db:"full_name,uqs"`
	Email     string    `db:",uqs"`
	CreatedAt time.Time `db:"created_at"`
}

func main() {
	// Create sqlite connection
	conn, _ := lib.GetSQLiteConnection("test.db")

	// Start a database engine
	var db sql.Engine
	db = sqlite.NewSQLite(context.Background(), conn)

	// Migrate database
	db.Sync(User{})

	db = db.Table("user")

	// Insert
	db.InsertOne(&User{Name: "masud", FullName: "Masudur Rahman", Email: "[email protected]"})

	// Read
	var user User
	db.ID(1).FindOne(&user)
	db.Where("email=?", "[email protected]").FindOne(&user)
	db.FindOne(&user, User{Name: "masud"})
	db.Columns("name", "email").FindOne(&user, User{Name: "masud"}) // fetch only name, email columns

	// Update
	db.ID(user.ID).UpdateOne(User{Email: "[email protected]"})
	db.Where("email=?", "[email protected]").UpdateOne(User{FullName: "Test User"})

	// Delete
	db.ID(1).DeleteOne()              // delete by id
	db.DeleteOne(User{Name: "masud"}) // delete using filter
}


Why styx name is chosen as this go orm

  • Mythological Connection: In Greek mythology, the River Styx separates the world of the living from the world of the dead. Similarly, this ORM acts as a bridge between your application code (the living) and the database (the "dead" storage). It facilitates the flow of data between these two realms.

  • Focus on Data Access: The Styx was also considered a barrier or boundary. Similarly, this ORM acts as a controlled point of access for your application to interact with the database. It ensures data integrity and prevents unauthorized modification.

  • Symbolism: The Styx is often depicted as a dark and mysterious river. This can be seen as a metaphor for the complexity of database interactions that this ORM simplifies for developers.

Overall, Styx evokes a sense of connection, control, and hidden power, all of which are relevant functionalities of an ORM.

styx's People

Contributors

masudur-rahman avatar

Watchers

James Cloos avatar  avatar

styx's Issues

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.