Convert Figma logo to code with AI

upper logodb

Data Access Layer (DAL) for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.

3,524
233
3,524
155

Top Related Projects

36,491

The fantastic ORM library for Golang, aims to be developer friendly

15,960

general purpose extensions to golang's database/sql

6,660

Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm

Generate a Go ORM tailored to your database schema.

1,430

A Tasty Treat For All Your Database Needs

12,095

Generate type-safe code from SQL

Quick Overview

upper/db is a productive data access layer for Go that provides a common interface to work with different data sources such as PostgreSQL, MySQL, SQLite, MSSQL, and QL. It simplifies database operations by offering an expressive and fluent query builder, while still allowing raw SQL queries when needed.

Pros

  • Supports multiple database backends with a unified API
  • Provides a fluent and intuitive query builder
  • Offers both ORM-like functionality and raw SQL capabilities
  • Lightweight and performant compared to full-fledged ORMs

Cons

  • Less feature-rich compared to some full ORM solutions
  • May require more manual work for complex queries or relationships
  • Learning curve for developers used to traditional SQL or other ORMs
  • Limited support for advanced database-specific features

Code Examples

  1. Connecting to a database:
import (
    "github.com/upper/db/v4"
    "github.com/upper/db/v4/adapter/postgresql"
)

sess, err := postgresql.Open(postgresql.ConnectionURL{
    Host:     "localhost",
    Database: "mydb",
    User:     "user",
    Password: "pass",
})
if err != nil {
    log.Fatal(err)
}
defer sess.Close()
  1. Querying records:
type User struct {
    ID   int    `db:"id"`
    Name string `db:"name"`
}

var users []User
err := sess.Collection("users").Find().OrderBy("name").Limit(10).All(&users)
if err != nil {
    log.Fatal(err)
}
  1. Inserting a record:
newUser := User{Name: "John Doe"}
res, err := sess.Collection("users").Insert(newUser)
if err != nil {
    log.Fatal(err)
}
id, _ := res.LastInsertId()
fmt.Printf("Inserted user with ID: %d\n", id)

Getting Started

  1. Install upper/db:

    go get github.com/upper/db/v4
    
  2. Import the package and the appropriate adapter:

    import (
        "github.com/upper/db/v4"
        "github.com/upper/db/v4/adapter/postgresql" // or mysql, sqlite, etc.
    )
    
  3. Connect to your database:

    sess, err := postgresql.Open(postgresql.ConnectionURL{
        Host:     "localhost",
        Database: "mydb",
        User:     "user",
        Password: "pass",
    })
    if err != nil {
        log.Fatal(err)
    }
    defer sess.Close()
    
  4. Start querying and manipulating data using the session object.

Competitor Comparisons

36,491

The fantastic ORM library for Golang, aims to be developer friendly

Pros of gorm

  • More extensive feature set, including advanced querying and associations
  • Larger community and ecosystem, with more third-party plugins and extensions
  • Better support for complex database operations and migrations

Cons of gorm

  • Steeper learning curve due to its extensive API and features
  • Potentially slower performance for simple queries compared to upper/db
  • More opinionated approach, which may not suit all project structures

Code Comparison

upper/db:

res := sess.Collection("users").Find(db.Cond{"name": "John"})
var users []User
err := res.All(&users)

gorm:

var users []User
result := db.Where("name = ?", "John").Find(&users)

Both libraries provide a clean and intuitive API for querying databases, but gorm offers more advanced features and a more "magical" approach, while upper/db focuses on simplicity and flexibility.

15,960

general purpose extensions to golang's database/sql

Pros of sqlx

  • More lightweight and closer to raw SQL, offering better performance for complex queries
  • Provides compile-time query checking, reducing runtime errors
  • Supports a wider range of database drivers out of the box

Cons of sqlx

  • Less abstraction, requiring more manual SQL writing
  • Steeper learning curve for developers not familiar with SQL
  • Limited support for advanced ORM features like migrations and relationships

Code Comparison

sqlx:

rows, err := db.Query("SELECT id, name FROM users WHERE age > ?", 18)
for rows.Next() {
    var u User
    err := rows.Scan(&u.ID, &u.Name)
    // Process user
}

upper/db:

res := db.Collection("users").Find(db.Cond{"age >": 18})
var users []User
err := res.All(&users)
// Process users

The sqlx example shows direct SQL usage with manual scanning, while upper/db provides a more abstracted, ORM-like approach. sqlx offers more control but requires more code, whereas upper/db simplifies database operations at the cost of some flexibility.

6,660

Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm

Pros of xorm

  • More extensive feature set, including schema synchronization and reverse engineering
  • Better performance for complex queries and large datasets
  • Supports a wider range of databases, including SQLite and TiDB

Cons of xorm

  • Steeper learning curve due to more complex API
  • Less idiomatic Go code, with more reliance on struct tags
  • Larger codebase and more dependencies

Code Comparison

upper/db:

collection := db.Collection("users")
result := collection.Find(db.Cond{"age >": 18}).OrderBy("name")

xorm:

var users []User
err := engine.Where("age > ?", 18).OrderBy("name").Find(&users)

Key Differences

  • upper/db focuses on simplicity and idiomatic Go code, while xorm offers more advanced features
  • xorm uses an ORM-style approach with struct tags, while upper/db uses a more flexible query builder
  • upper/db has a smaller footprint and fewer dependencies, making it easier to integrate into projects
  • xorm provides better performance for complex scenarios but may be overkill for simpler use cases

Both libraries have their strengths, and the choice between them depends on project requirements, performance needs, and developer preferences.

Generate a Go ORM tailored to your database schema.

Pros of sqlboiler

  • Generates type-safe, performant Go code from database schemas
  • Supports complex queries and relationships out of the box
  • Provides excellent integration with database migrations

Cons of sqlboiler

  • Steeper learning curve due to generated code complexity
  • Less flexibility for ad-hoc queries compared to upper/db
  • Requires regeneration of code when database schema changes

Code Comparison

sqlboiler:

users, err := models.Users().All(ctx, db)
if err != nil {
    return err
}

upper/db:

var users []User
err := sess.Collection("users").Find().All(&users)
if err != nil {
    return err
}

Key Differences

  • sqlboiler focuses on code generation and type safety, while upper/db provides a more flexible, runtime-based approach
  • upper/db offers a simpler API for basic CRUD operations, whereas sqlboiler excels in complex querying scenarios
  • sqlboiler requires more setup and maintenance due to code generation, but potentially offers better performance
  • upper/db provides a more database-agnostic approach, while sqlboiler is tailored to specific database schemas

Both libraries have their strengths and are suitable for different use cases. sqlboiler is ideal for projects with complex, well-defined database schemas, while upper/db shines in scenarios requiring more flexibility and ease of use.

1,430

A Tasty Treat For All Your Database Needs

Pros of Pop

  • Integrated with Buffalo framework, providing a seamless development experience
  • Supports multiple databases (PostgreSQL, MySQL, SQLite) out of the box
  • Includes a migration system for easy schema management

Cons of Pop

  • Less flexible for use outside of Buffalo projects
  • May have a steeper learning curve for developers not familiar with Buffalo
  • Limited support for advanced database features compared to upper/db

Code Comparison

Pop:

db, err := pop.Connect("development")
if err != nil {
    log.Fatal(err)
}
users := []User{}
err = db.All(&users)

upper/db:

sess, err := postgresql.Open(settings)
if err != nil {
    log.Fatal(err)
}
defer sess.Close()
res := sess.Collection("users").Find()
var users []User
err = res.All(&users)

Both libraries provide a clean API for database operations, but upper/db offers a more database-agnostic approach, while Pop is more tightly integrated with the Buffalo ecosystem. upper/db may be more suitable for projects requiring fine-grained control over database operations, while Pop excels in rapid development within the Buffalo framework.

12,095

Generate type-safe code from SQL

Pros of sqlc

  • Generates type-safe Go code from SQL queries, reducing runtime errors
  • Supports complex queries and joins, offering more flexibility for advanced database operations
  • Provides better performance due to compile-time query validation

Cons of sqlc

  • Steeper learning curve, especially for developers not familiar with SQL
  • Requires writing raw SQL queries, which can be verbose for simple operations
  • Less abstraction from the underlying database, potentially making database migrations more challenging

Code Comparison

sqlc:

// Generated by sqlc
func (q *Queries) GetUser(ctx context.Context, id int64) (User, error) {
    row := q.db.QueryRowContext(ctx, "SELECT id, name, email FROM users WHERE id = $1", id)
    var i User
    err := row.Scan(&i.ID, &i.Name, &i.Email)
    return i, err
}

upper/db:

// Using upper/db
var user User
err := db.Collection("users").Find(db.Cond{"id": id}).One(&user)

Key Differences

  • sqlc generates code based on SQL queries, while upper/db uses a more abstract query builder
  • upper/db provides a higher level of abstraction, making it easier to use for simple CRUD operations
  • sqlc offers more control over complex queries and potentially better performance for advanced use cases

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

upper/db unit tests status

upper/db

upper/db is a productive data access layer (DAL) for Go that provides agnostic tools to work with different data sources, such as:

See upper.io/v4 for documentation and code samples.

The tour

tour

Take the tour to see real live examples in your browser.

License

Licensed under MIT License

Contributors

See the list of contributors.