All Projects → huntlabs → Hunt Entity

huntlabs / Hunt Entity

An object-relational mapping (ORM) framework for D language (Similar to JPA / Doctrine), support PostgreSQL and MySQL.

Programming Languages

d
599 projects
dlang
54 projects

Projects that are alternatives of or similar to Hunt Entity

Jooq
jOOQ is the best way to write SQL in Java
Stars: ✭ 4,695 (+9105.88%)
Mutual labels:  orm, hibernate, jpa, database, mysql, postgresql
Mikro Orm
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.
Stars: ✭ 3,874 (+7496.08%)
Mutual labels:  orm, entity, database, mysql, postgresql, sqlite
Denodb
MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
Stars: ✭ 498 (+876.47%)
Mutual labels:  orm, database, mysql, postgresql, sqlite
Prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite & MongoDB (Preview)
Stars: ✭ 18,168 (+35523.53%)
Mutual labels:  orm, database, mysql, postgresql, sqlite
Typeorm
ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Stars: ✭ 26,559 (+51976.47%)
Mutual labels:  orm, database, mysql, postgresql, sqlite
Ebean
Ebean ORM
Stars: ✭ 1,172 (+2198.04%)
Mutual labels:  orm, jpa, database, mysql, sqlite
Hibernate Reactive
A reactive API for Hibernate ORM, supporting non-blocking database drivers and a reactive style of interaction with the database.
Stars: ✭ 167 (+227.45%)
Mutual labels:  orm, hibernate, jpa, mysql, postgresql
Go Sqlbuilder
A flexible and powerful SQL string builder library plus a zero-config ORM.
Stars: ✭ 539 (+956.86%)
Mutual labels:  orm, database, mysql, postgresql, sqlite
Nut
Advanced, Powerful and easy to use ORM for Qt
Stars: ✭ 181 (+254.9%)
Mutual labels:  orm, database, mysql, postgresql, sqlite
Db
Data access layer for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.
Stars: ✭ 2,832 (+5452.94%)
Mutual labels:  orm, database, mysql, postgresql, sqlite
Linq2db
Linq to database provider.
Stars: ✭ 2,211 (+4235.29%)
Mutual labels:  orm, database, mysql, postgresql, sqlite
Node Orm2
Object Relational Mapping
Stars: ✭ 3,063 (+5905.88%)
Mutual labels:  orm, database, mysql, postgresql, sqlite
Bookshelf
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js
Stars: ✭ 6,252 (+12158.82%)
Mutual labels:  orm, database, mysql, postgresql, sqlite
Diesel
A safe, extensible ORM and Query Builder for Rust
Stars: ✭ 7,702 (+15001.96%)
Mutual labels:  orm, mysql, postgresql, sqlite
Phpmyfaq
phpMyFAQ - Open Source FAQ web application for PHP and MySQL, PostgreSQL and other databases
Stars: ✭ 494 (+868.63%)
Mutual labels:  database, mysql, postgresql, sqlite
Xorm
Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm
Stars: ✭ 6,464 (+12574.51%)
Mutual labels:  orm, mysql, postgresql, sqlite
Maghead
The fastest pure PHP database framework with a powerful static code generator, supports horizontal scale up, designed for PHP7
Stars: ✭ 483 (+847.06%)
Mutual labels:  orm, database, mysql, sqlite
Hibernate Orm
Hibernate's core Object/Relational Mapping functionality
Stars: ✭ 4,806 (+9323.53%)
Mutual labels:  orm, hibernate, jpa, database
Smartsql
SmartSql = MyBatis in C# + .NET Core+ Cache(Memory | Redis) + R/W Splitting + PropertyChangedTrack +Dynamic Repository + InvokeSync + Diagnostics
Stars: ✭ 775 (+1419.61%)
Mutual labels:  orm, mysql, postgresql, sqlite
Evolve
Database migration tool for .NET and .NET Core projects. Inspired by Flyway.
Stars: ✭ 477 (+835.29%)
Mutual labels:  database, mysql, postgresql, sqlite

Build Status

hunt-entity

Hunt-entity is an object-relational mapping tool for the D programming language. Referring to the design idea of JPA.

Support databases

  • PostgreSQL 9.0+
  • MySQL 5.1+
  • SQLite 3.7.11+

Depends

Simple code

import hunt.entity;

@Table("user")
class User
{
    mixin MakeModel;

    @PrimaryKey
    @AutoIncrement
    int id;

    string name;
    double money;
    string email;
    bool status;
}

void main()
{
    auto option = new EntityOption;

    option.database.driver = "mysql";
    option.database.host = "localhost";
    option.database.port = 3306;
    option.database.database = "test";
    option.database.username = "root";
    option.database.password = "123456";
    option.database.charset = "utf8mb4";
    option.database.prefix = "hunt_";

    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("default", option);
    EntityManager em = entityManagerFactory.createEntityManager();

    // begin transaction
    em.getTransaction().begin();

    // define your database existing row id in here
    int id = 10;

    auto user = em.find!User(id);
    log("User name is: ", user.name);

    // commit transaction
    em.getTransaction().commit();

    em.close();
    entityManagerFactory.close();
}

Insert row

    auto user = new User();
    user.name = "Brian";
    user.email = "[email protected]";
    user.money = 99.9;
    
    // insert user
    em.persist(user);
    log("User id is: ", user.id);

Delete row

    int n = em.remove!User(id);
    log("The number of users deleted is: ", n);

Update row

    auto user = em.find!User(id);
    log("User name is: ", user.name);
    user.name = "zoujiaqing";
    em.merge!User(user);
    log("The number of users updated is: ", n);

Use CriteriaQuery to find

    // create CriteriaBuilder object from em
    CriteriaBuilder builder = em.getCriteriaBuilder();

    CriteriaQuery!User criteriaQuery = builder.createQuery!User;
    Root!User root = criteriaQuery.from();
    Predicate p1 = builder.equal(root.User.id, id);
    TypedQuery!User typedQuery = em.createQuery(criteriaQuery.select(root).where(p1));

    auto user = typedQuery.getSingleResult();

    log("User name is: ", user.name);

Use CriteriaQuery to Multi-condition find

    // create CriteriaBuilder object from em
    CriteriaBuilder builder = em.getCriteriaBuilder();

    CriteriaQuery!User criteriaQuery = builder.createQuery!User;
    Root!User root = criteriaQuery.from();

    Predicate p1 = builder.lt(root.User.id, 1000);  // User id is less than 1000.
    Predicate p2 = builder.gt(root.User.money, 0);  // User money is greater than 0.
    Predicate p3 = builder.like(root.User.name, "z%");  // User name prefix is z.

    TypedQuery!User typedQuery = em.createQuery(criteriaQuery.select(root).where(builder.and(p1, p2), p3));
    User[] users = typedQuery.getResultList();

    log("The number of users found is: ", users.length);

Avaliable Versions

Identifier Description
HUNT_SQL_DEBUG Used to log debugging messages about SQL handling
HUNT_SQL_DEBUG_MORE Used to log more debugging messages about SQL handling
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].