Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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