TemplatedJDBC

A zero dependency light-weight wrapper for JDBC, using String Templates and records.

OTHER License

Stars
6

Bot releases are hidden (Show)

TemplatedJDBC - 0.1.1 Latest Release

Published by hjohn 2 months ago

  • Fix null handling for primitive wrappers. When a primitive wrapper was used in a record, and the value stored in the database was null, the returned value would be the default value for the type instead of null.
TemplatedJDBC - 0.1.0

Published by hjohn 3 months ago

  • Modularized project
  • Add support for type conversions on the database and reflector level:

This allows back and forth conversions of a Java class to a database type, for example:

    databaseBuilder.addTypeConverter(
        LocalDateTime.class, 
        TypeConverter.of(Timestamp.class, Timestamp::valueOf, Timestamp::toLocalDateTime)
    );
  • Batch support to insert multiple objects with one statement:
    database.accept(tx ->
        tx."INSERT INTO company (\{ALL}) VALUES (\{ALL.batch(companies)})".execute()
    );
  • Reflector now supports bean classes (and already supported records), for easier custom types:
    Reflector.ofClass(MyBean.class);
  • Reflector allows fully customizing its construction to allow for unsupported types:
    Reflector<Coordinate> reflector = Reflector.custom(
        Coordinate.class,
        row -> new Coordinate(row.getInt(0), row.getInt(1)),
        List.of(
            Mapping.of("x", int.class, Coordinate::x), 
            Mapping.of("y", int.class, Coordinate::y)
        )
   ); 
  • Inlining of a record sub-type has been made explicit, and can now be fully controlled for all types (not just records):

Given:

    record Coordinate(int x, int y) {}
    record Trip(Coordinate start, Coordinate end) {}

Then:

    Reflector.of(Trip.class)
        .nest("start", Reflector.of(Coordinate.class))
        .nest("end", Reflector.of(Coordinate.class));

Will create a Reflector for Trip with the fields start_x, start_y, end_x and end_y.

The prefixing behavior can be controlled by using either Reflector::inline or Reflector::nest and using the new Reflector::prefix method.

  • Some backwards incompatible rearranging of types to improve the structure of the project
TemplatedJDBC - 0.0.5

Published by hjohn 8 months ago

  • Converted Database and CheckedDatabase to interfaces
  • Made MockDatabase implement Database
  • Added MockCheckedDatabase which implements CheckedDatabase
TemplatedJDBC - 0.0.4

Published by hjohn 8 months ago

  • Add MockDatabase to make testing easier
  • Row no longer throws SQLException when using it
  • Delay obtaining Connection until a statement needs to be executed
TemplatedJDBC - 0.0.3

Published by hjohn 8 months ago

  • Support for functional transactions and retries
  • Databases are now constructed via a builder
  • At builder level the exception type (checked or unchecked) can be chosen
TemplatedJDBC - 0.0.2

Published by hjohn 8 months ago

  • Made the get and toOptional methods fail if there is more than one result
  • Added a getFirst method that operates how get did before (get the first result, ignoring any others)
TemplatedJDBC - Initial release

Published by hjohn 8 months ago