项目作者: w11k

项目描述 :
Java SQL Database Library
高级语言: Java
项目地址: git://github.com/w11k/lsql.git
创建时间: 2013-07-04T14:17:34Z
项目社区:https://github.com/w11k/lsql

开源协议:Apache License 2.0

下载


Literate SQL - A Java Database Library

LSql (Literate SQL) is a Java database library focusing on type-safety and the preservation of the relational data model.

Key points:

  • LSql is not yet another object/relational mapper. We believe that functional application data (in particular stored in a relational model) should not be mapped to a strict classes/objects model. The relational data model is elegant, well-thought-out and a reliable way to model the application data. Any abstraction between the relational model and the application logic makes things more complicated and should be avoided.

  • Based on your database schema and SQL statement files, LSql generates Java classes (with an immutability API design) in order to interact with the database in a type-safe manner.

  • SQL is a superior language for data manipulation. The RDBMS should be choosen depending on the project requirements and database access libraries should not try to hide their characteristics.

Example

CRUD

Given the following DDL:

  1. CREATE TABLE person (
  2. id SERIAL PRIMARY KEY,
  3. name VARCHAR(200),
  4. age INT
  5. );

Java code:

  1. // insert
  2. Person_Table personTable = new Person_Table(lSql);
  3. Person_Row person = new Person_Row()
  4. .withName("John")
  5. .withAge(20);
  6. Optional<Integer> pk = personTable.insert(person);
  7. // load by ID
  8. Optional<Person_Row> personRowOptional = personTable.load(pk.get());
  9. personRowOptional.get().name == "John";
  10. personRowOptional.get().age == 20;

Query

Given the following SQL statement file PersonStatements.sql:

  1. --loadPersonByAge
  2. SELECT * FROM person WHERE age = /*=*/ 0 /**/;

Java code:

  1. PersonStatements statements = new PersonStatements(lSql);
  2. List<LoadPersonByAge> list = personStatements.loadPersonByAge()
  3. .withAge(20)
  4. .toList();
  5. list.get(0).name == "John";
  6. list.get(0).age == 20;

Download

Maven Repository Artifacts

All released files are stored in a Maven repository:

  1. <repositories>
  2. <repository>
  3. <snapshots>
  4. <enabled>false</enabled>
  5. </snapshots>
  6. <id>bintray-w11k-lsql</id>
  7. <name>bintray</name>
  8. <url>https://dl.bintray.com/w11k/lsql</url>
  9. </repository>
  10. </repositories>
  11. <dependencies>
  12. <dependency>
  13. <groupId>com.w11k.lsql</groupId>
  14. <artifactId>lsql-core</artifactId>
  15. <version>...</version>
  16. </dependency>
  17. <dependency>
  18. <groupId>com.w11k.lsql</groupId>
  19. <artifactId>lsql-guice</artifactId>
  20. <version>...</version>
  21. </dependency>
  22. <dependency>
  23. <groupId>com.w11k.lsql</groupId>
  24. <artifactId>lsql-cli</artifactId>
  25. <version>...</version>
  26. </dependency>
  27. </dependencies>