Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tonivade/puredbc
Pure Functional Database Connection Layer for Java
https://github.com/tonivade/puredbc
experimental functional-programming java jdbc purefun typesafe
Last synced: 2 months ago
JSON representation
Pure Functional Database Connection Layer for Java
- Host: GitHub
- URL: https://github.com/tonivade/puredbc
- Owner: tonivade
- License: mit
- Created: 2020-01-10T06:08:00.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-17T06:02:54.000Z (4 months ago)
- Last Synced: 2024-09-17T08:38:12.444Z (4 months ago)
- Topics: experimental, functional-programming, java, jdbc, purefun, typesafe
- Language: Java
- Homepage:
- Size: 887 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PureDBC
Pure Functional Database Connection Layer
## Disclaimer
This project is experimental, so don't try to use in production.
## Objective
Develop a comprehensible and easy to use API:
- High level
- Flexible
- Type safe
- Composable
- Meaningful errors## Example
```java
// Table instance
Test TEST = new Test();
// Query DSL
SQL createTable = sql(
"create table if not exists test(",
"id identity primary key,",
"name varchar(100))");
SQL dropTable = sql("drop table if exists test");
SQL deleteAll = deleteFrom(TEST);
SQL1 deleteOne = deleteFrom(TEST).where(TEST.ID.eq());
SQL1 insertRowWithKey = insertInto(TEST).values(TEST.NAME);
SQL2 insertRow = insertInto(TEST).values(TEST.ID, TEST.NAME);
SQL2 updateRow = update(TEST).set(TEST.NAME).where(TEST.ID.eq());
SQL findAll = select(TEST.ID, TEST.NAME).from(TEST);
SQL count = select(TEST.ID.count().as("elements")).from(TEST);
SQL1 findOne = select(TEST.ID, TEST.NAME).from(TEST).where(TEST.ID.eq());
// PureDBC DSL
PureDBC>> program =
update(createTable)
.andThen(update(deleteAll))
.andThen(update(insertRow.bind(1, "toni")))
.andThen(update(insertRow.bind(2, "pepe")))
.andThen(queryIterable(findAll, TEST::asTuple));
assertEquals(
listOf(Tuple.of(1, "toni"), Tuple.of(2, "pepe")),
program.unsafeRun(dataSource));
```## License
Distributed under MIT License