Skip to content

Commit

Permalink
Change ORM name to styx, also Database to Engine
Browse files Browse the repository at this point in the history
Signed-off-by: Masudur Rahman <masudjuly02@gmail.com>
  • Loading branch information
masudur-rahman committed Apr 4, 2024
1 parent 702c1b2 commit f04ecee
Show file tree
Hide file tree
Showing 23 changed files with 148 additions and 113 deletions.
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# database
# Styx
Database Engine for different SQL and NoSQL databases

## Install
```shell
go get -u github.com/masudur-rahman/database
go get -u github.com/masudur-rahman/styx
```

## Quickstart
Expand All @@ -15,9 +15,9 @@ import (
"context"
"time"

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

type User struct {
Expand All @@ -33,8 +33,8 @@ func main() {
conn, _ := lib.GetSQLiteConnection("test.db")

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

// Migrate database
db.Sync(User{})
Expand All @@ -59,4 +59,21 @@ func main() {
db.ID(1).DeleteOne() // delete by id
db.DeleteOne(User{Name: "masud"}) // delete using filter
}

```

<br>
<hr>

### 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.
2 changes: 1 addition & 1 deletion dberr/check.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dberr

import "github.com/masudur-rahman/database/sql/postgres/lib"
import "github.com/masudur-rahman/styx/sql/postgres/lib"

func CheckEntityNameNonEmpty(entity string) error {
if entity == "" {
Expand Down
10 changes: 5 additions & 5 deletions examples/quickstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"time"

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

type User struct {
Expand All @@ -22,8 +22,8 @@ func main() {
conn, _ := lib.GetSQLiteConnection("test.db")

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

// Migrate database
db.Sync(User{})
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/masudur-rahman/database
module github.com/masudur-rahman/styx

go 1.20

Expand Down
6 changes: 3 additions & 3 deletions mock/database.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mock

type Database interface {
Entity(name string) Database
type Engine interface {
Entity(name string) Engine

ID(id string) Database
ID(id string) Engine

FindOne(document interface{}, filter ...interface{}) (bool, error)
FindMany(documents interface{}, filter interface{}) error
Expand Down
8 changes: 4 additions & 4 deletions mock/map/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package _map
import (
"reflect"

"github.com/masudur-rahman/database/dberr"
"github.com/masudur-rahman/database/mock"
"github.com/masudur-rahman/styx/dberr"
"github.com/masudur-rahman/styx/mock"

"github.com/rs/xid"
)
Expand All @@ -21,12 +21,12 @@ func NewMockDB() *MockDB {
}
}

func (m *MockDB) Entity(name string) mock.Database {
func (m *MockDB) Entity(name string) mock.Engine {
m.entity = name
return m
}

func (m *MockDB) ID(id string) mock.Database {
func (m *MockDB) ID(id string) mock.Engine {
m.id = id
return m
}
Expand Down
10 changes: 5 additions & 5 deletions nosql/arangodb/arangodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package arangodb
import (
"context"

"github.com/masudur-rahman/database/dberr"
"github.com/masudur-rahman/database/nosql"
"github.com/masudur-rahman/database/pkg"
"github.com/masudur-rahman/styx/dberr"
"github.com/masudur-rahman/styx/nosql"
"github.com/masudur-rahman/styx/pkg"

arango "github.com/arangodb/go-driver"
)
Expand All @@ -24,12 +24,12 @@ func NewArangoDB(ctx context.Context, db arango.Database) ArangoDB {
}
}

func (a ArangoDB) Collection(collection string) nosql.Database {
func (a ArangoDB) Collection(collection string) nosql.Engine {
a.collectionName = collection
return a
}

func (a ArangoDB) ID(id string) nosql.Database {
func (a ArangoDB) ID(id string) nosql.Engine {
a.id = id
return a
}
Expand Down
6 changes: 3 additions & 3 deletions nosql/database.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package nosql

type Database interface {
Collection(name string) Database
type Engine interface {
Collection(name string) Engine

ID(id string) Database
ID(id string) Engine

FindOne(document interface{}, filter ...interface{}) (bool, error)
FindMany(documents interface{}, filter interface{}) error
Expand Down
12 changes: 6 additions & 6 deletions nosql/mock/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions sql/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import (
"database/sql"
)

type Database interface {
BeginTx() (Database, error)
type Engine interface {
BeginTx() (Engine, error)
Commit() error
Rollback() error

Table(name string) Database
Table(name string) Engine

ID(id any) Database
In(col string, values ...any) Database
Where(cond string, args ...any) Database
Columns(cols ...string) Database
AllCols() Database
MustCols(cols ...string) Database
ShowSQL(showSQL bool) Database
ID(id any) Engine
In(col string, values ...any) Engine
Where(cond string, args ...any) Engine
Columns(cols ...string) Engine
AllCols() Engine
MustCols(cols ...string) Engine
ShowSQL(showSQL bool) Engine

FindOne(document any, filter ...any) (bool, error)
FindMany(documents any, filter ...any) error
Expand Down
12 changes: 6 additions & 6 deletions sql/mock/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions sql/postgres/lib/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"strings"
"time"

"github.com/masudur-rahman/database/pkg"
"github.com/masudur-rahman/database/sql/postgres/pg-grpc/pb"
"github.com/masudur-rahman/styx/pkg"
"github.com/masudur-rahman/styx/sql/postgres/pg-grpc/pb"

"github.com/iancoleman/strcase"
_ "github.com/lib/pq"
Expand Down
20 changes: 10 additions & 10 deletions sql/postgres/pg-grpc/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"database/sql"
"strings"

"github.com/masudur-rahman/database/dberr"
"github.com/masudur-rahman/database/pkg"
isql "github.com/masudur-rahman/database/sql"
"github.com/masudur-rahman/database/sql/postgres/pg-grpc/pb"
"github.com/masudur-rahman/styx/dberr"
"github.com/masudur-rahman/styx/pkg"
isql "github.com/masudur-rahman/styx/sql"
"github.com/masudur-rahman/styx/sql/postgres/pg-grpc/pb"

"google.golang.org/protobuf/types/known/anypb"
)
Expand All @@ -27,32 +27,32 @@ func NewDatabase(ctx context.Context, client pb.PostgresClient) Database {
}
}

func (d Database) Table(name string) isql.Database {
func (d Database) Table(name string) isql.Engine {
d.table = name
return d
}

func (d Database) ID(id any) isql.Database {
func (d Database) ID(id any) isql.Engine {
d.id = id
return d
}

func (d Database) In(s string, a ...any) isql.Database {
func (d Database) In(s string, a ...any) isql.Engine {
//TODO implement me
panic("implement me")
}

func (d Database) Where(s string, a ...any) isql.Database {
func (d Database) Where(s string, a ...any) isql.Engine {
//TODO implement me
panic("implement me")
}

func (d Database) Columns(s ...string) isql.Database {
func (d Database) Columns(s ...string) isql.Engine {
//TODO implement me
panic("implement me")
}

func (d Database) AllCols() isql.Database {
func (d Database) AllCols() isql.Engine {
//TODO implement me
panic("implement me")
}
Expand Down
2 changes: 1 addition & 1 deletion sql/postgres/pg-grpc/postgres_helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pg_grpc

import (
"github.com/masudur-rahman/database/sql/postgres/pg-grpc/pb"
"github.com/masudur-rahman/styx/sql/postgres/pg-grpc/pb"
)

func InitializePostgresClient() (pb.PostgresClient, error) {
Expand Down
6 changes: 3 additions & 3 deletions sql/postgres/pg-grpc/server/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"log"
"net"

"github.com/masudur-rahman/database/pkg"
"github.com/masudur-rahman/database/sql/postgres/lib"
"github.com/masudur-rahman/database/sql/postgres/pg-grpc/pb"
"github.com/masudur-rahman/styx/pkg"
"github.com/masudur-rahman/styx/sql/postgres/lib"
"github.com/masudur-rahman/styx/sql/postgres/pg-grpc/pb"

"google.golang.org/grpc"
health "google.golang.org/grpc/health/grpc_health_v1"
Expand Down
Loading

0 comments on commit f04ecee

Please sign in to comment.