- 授权协议: Apache
- 开发语言: D语言
- 操作系统: 跨平台
- 软件首页: https://gitee.com/huntlabs/entity
- 软件文档: https://gitee.com/huntlabs/entity
软件介绍
Entity 是 D 语言(dlang)数据库操作 ORM 框架,设计参照 javax JPA 实现,具有很好的扩展性和规范性,数据库驱动依赖 Huntlabs 开发的 database for dlang 。
特性
实现了完整的 CriteriaQuery 支持
对 Repository 也有部分封装
完全对象化查询,不用考虑底层数据库驱动
支持的数据库
PostgreSQL 9.0+
MySQL 5.1+
SQLite 3.7.11+
使用示例
import entity; @Table("user") class User : Entity { @PrimaryKey @AutoIncrement int id; string name; double money; string email; bool status; } void main() { DatabaseOption options = new DatabaseOption("mysql://root:123456@localhost:3306/huntblog?charset=utf-8"); EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("default", options); 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 = "brian@huntlabs.cn";
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);
Perl入门经典
[美]Curtis "Ovid" Poe / 朱允刚、韩雷、叶斌 / 清华大学出版社 / 2013-9-20 / 78.00
作为最有影响力的编程语言之一,Perl被广泛用在Web开发、数据处理和系统管理中。无论是Perl新手,还是想要加强自己实战技能的Perl程序员,《Perl入门经典》都提供了处理日常情况所需的各种技术。凭借十多年的Perl经验,作者Curtis“Ovid”Poe一开始先简单回顾了Perl的基础知识,然后以此为出发点,举例说明了Perl在工作场所中的各种真实用法。此外,书中还包含了一些动手练习、宝贵建......一起来看看 《Perl入门经典》 这本书的介绍吧!