entity 0.1.3

ORM for D programming language, like JPA and Doctine2.

To use this package, put the following dependency into your project's dependencies section:



Entity is ORM for D language (similar to JPA, fork from hibernated)

Uses DDBC as DB abstraction layer: https://github.com/buggins/ddbc

Available as DUB package

Use SQLite 3.7.11 or later. In older versions syntax INSERT INTO (col1, col2) VALUES (1, 2), (3, 4) is not supported.

Database config url:


Sample code:

import entity;
import std.algorithm;
import std.stdio;

// Annotations of entity classes

class User {
    long id;
    string name;
    LazyCollection!Role roles;

class Role {
    int id;
    string name;
    LazyCollection!User users;

int main()
    // create metadata from annotations
    EntityMetaData schema = new SchemaInfoImpl!(User, Role);
    // setup DB connection factory
    version (USE_MYSQL) {
            MySQLDriver driver = new MySQLDriver();
            string url = MySQLDriver.generateUrl("localhost", 3306, "test_db");
            string[string] params = MySQLDriver.setUserAndPassword("testuser", "testpasswd");
            Dialect dialect = new MySQLDialect();
        } else {
        import ddbc.all;
            SQLITEDriver driver = new SQLITEDriver();
            string url = "zzz.db"; // file with DB
            static import std.file;
            string[string] params;
            Dialect dialect = new SQLiteDialect();
        DataSource ds = new ConnectionPoolDataSourceImpl(driver, url, params);
        // create managerion factory
        EntityManagerFactory factory = new EntityManagerFactoryImpl(schema, dialect, ds);

        // Create schema if necessary
            // get connection
            Connection conn = ds.getConnection();

            factory.getDBMetaData().updateDBSchema(conn, false, true);

        // create managerion
        EntityManager manager = factory.createEntityManager();

        Role myrole = new Role();
        myrole.name = "Admin";
        User user = new User();
        user.name = "Brian";
        user.roles = myrole;
        manager = factory.createEntityManager();

        writeln("user.name,", user.name);
        writeln("user.id,", user.id);

        User myuser = manager.createQuery("FROM User WHERE name=:username").
        setParameter("username", "Brian").uniqueResult!User();
        writeln("myuser.name,", myuser.name);
        writeln("myuser.id,", myuser.id);

        return 0;

Authors: huntlabs

Dependencies: ddbc

0.1.3 2017-Apr-27
0.1.2 2017-Apr-05
0.1.1 2017-Mar-22
0.1.0 2017-Mar-20
0.0.8 2016-Jul-27
Show all 12 versions
  • 1 downloads today

  • 12 downloads this week

  • 45 downloads this month

  • 519 downloads total