A MySQL connector wrapper that supports mapping to Kotlin classes.

Overview

Racoon

Racoon is a wrapper for the MySQL connector. It makes communicating with the database easier by providing a bunch of functionalities:

  • Mapping query results to classes.
  • Query parameter support (prepared statements)
    • Custom types support
    • Indexed parameter support
    • Named parameter support
    • Basic types support
    • Smart cast query result to match the class field type

Racoon is developed with freedom of use in mind from the beginning. This property of Racoon can be seen in the mapping operations that allow the use of reified generic types and runtime types.

Installation

To build the library, run the following command:

$ ./gradlew clean build -x test

To publish the library to the local Maven repository, run the following command:

$ ./gradlew publishToMavenLocal

Roadmap

  • Basics:
    • Table column name mapping (ANNOTATIONS?) (ADDED MAPPING FUNCTIONALITY, BUT APPLIES TO ALL)
    • Get query info (number of rows, number of columns, column names, column types, ecc...)?
  • Insert query support
    • Custom ID annotation
    • Update the ID field upon insertion
    • Detect ID field by name or annotation
  • Update query support
  • Basic cache support?
  • Custom cache support?
  • Pooling:
    • Possibility to disable pooling without limiting the number of connections (TO BE TESTED)
    • Remove expired connections in the pool even if are being used
    • Possibility to set the minimum number of connections in the pool???
Comments
  • Added basic caches to RM functions

    Added basic caches to RM functions

    The basic RM functions (find, insert, update and delete) now have cached and uncached variants. The old methods (such as find and findK) are now cached, and new methods (such as findUncached and findKUncached) are uncached.

    The cache size can be configured in the RacoonConfiguration object.

    A new method has been added: refresh. It allows to refresh the cache of a given object by executing the findUncached method.

    enhancement 
    opened by a-vezzoli-02 1
  • Fixed ambiguous null LazyId

    Fixed ambiguous null LazyId

    The LazyId does not have an empty method anymore, and the get method cannot return a null value. If a property of a Table can be null, make the LazyId itself nullable.

    A small fix of the update method is also included.

    bug enhancement 
    opened by a-vezzoli-02 1
  • LazyId should be splitted into null and non-null variants

    LazyId should be splitted into null and non-null variants

    Is your feature request related to a problem? Please describe. Always have to check if the value of a LazyId is null or not makes the code "heavy". Also there are cases where a LazyId cannot have a null value (for example when a foreign key has a NON NULL)

    Describe the solution you'd like Splitting the LazyId class into different classes:

    • a generic one (the current LazyId)
    • a null one
    • a non-null one

    Note that LazyId would then become a sealed class and the variants would be subclasses.

    Describe alternatives you've considered Probably also splitting the non-null variant into:

    • a non-null lazy one
    • a non-null defined one

    could be useful

    Additional context No.

    enhancement 
    opened by a-vezzoli-02 1
  • Enhanced the ParameterCaster interface

    Enhanced the ParameterCaster interface

    The ParameterCaster interface can now be used to achieve more complex behaviours. A prefix and a postfix can be optionally be defined such that when executing auto-generated queries (for example when using the insert or find methods), the resulting query is customized with these two new properties

    enhancement 
    opened by a-vezzoli-02 1
  • Fix for idleTimeout parameter of ConnectionSettings

    Fix for idleTimeout parameter of ConnectionSettings

    If a connection is idle for more than the specified time in the idleTimeout settings, the connection will be closed and when a new one is requested, a new one is created instead of the same one being used.

    The old behavior of the idleTimeout is replaced by the new property socketTimeout.

    bug 
    opened by a-vezzoli-02 1
  • Fix for idleTimeout parameter of ConnectionSettings

    Fix for idleTimeout parameter of ConnectionSettings

    If a connection is idle for more that the specified time in the idleTimeout settings, the connection will be closed and when a new one is requested, a new one is created instead of the same one being used.

    The old beaviour of the idleTimeout is replaced by the new property socketTimeout.

    bug 
    opened by a-vezzoli-02 1
  • Unsigned types not supported as query parameters

    Unsigned types not supported as query parameters

    Describe the bug A class using the Table interface doesn't work as expected if one of the properties is an unsigned one. This happens only when a value is set using parameter binding.

    In particular, this exception is thrown when executing a query with an UInt being used as a parameter:

    java.sql.SQLException: Cannot convert class kotlin.UInt to SQL type requested due to com.mysql.cj.exceptions.WrongArgumentException - Invalid argument value: java.io.NotSerializableException
    

    To Reproduce Steps to reproduce the behavior:

    1. Create a class that implements the Table interface
    2. Create a property with an unsigned Kotlin type
    3. Execute a query that sets the previously defined property as a parameter of the prepared statement
    4. See the exception above

    Expected behavior Unsigned types should be supported??

    Screenshots No.

    Version

    • MySQL: Any
    • Racoon: 0.1.2b and earlier (and probably newer)

    Additional context This can't probably be fixed. Unsigned types are not supported by Java, and so not supported by the MySQL connector. A possible fix would be to cast an unsigned type to its corresponding signed one, but it would be more confusing than declaring the field signed in the first place. Another possible fix would be to cast the unsigned type to String and let MySQL handle the conversion after, but this seems a cheap trick that could prevent Racoon from working with other DBMS in the future.

    bug good first issue wontfix 
    opened by a-vezzoli-02 0
  • Remove setValue and getValue functions from LazyId

    Remove setValue and getValue functions from LazyId

    Describe the bug LazyId should not be used with a delegation. Using it this way makes the code more error-prone and inefficient. For example, suppose only the id needs to be retrieved from the object when using the delegation pattern. In that case, a whole new query and mapping must be done, while when using the LazyId, the id can be collected directly.

    Expected behavior No.

    Screenshots No.

    Version

    • MySQL: Any
    • Racoon: Latest branch

    Additional context No.

    bug 
    opened by a-vezzoli-02 0
  • ConnectionString.idleTimeout not working as intended

    ConnectionString.idleTimeout not working as intended

    Describe the bug The idleTimeout property of the ConnectionSettings does not change the actual idle time of the connection.

    To Reproduce Steps to reproduce the behavior:

    1. Use a ConnectionSetting instance with a short idleTimeout;
    2. Request a connection from RacoonDen and release it;
    3. Wait for the defined `idleTimeout.

    Expected behavior The ping test while requesting the next connection, should be negative, but its positive (it depends on the configuration of the Database itself)

    Screenshots No.

    Version

    • MySQL: Any
    • Racoon: Latest branch

    Additional context A series of queries should be used instead of the idleTimeout URL parameter: https://dba.stackexchange.com/a/174640

    bug 
    opened by a-vezzoli-02 0
  • Enum type support

    Enum type support

    Is your feature request related to a problem? Please describe. No.

    Describe the solution you'd like An enum should be used as the type of a property in the primary constructor. The enum should implement an interface which defines the correlation between the in-code enum constant and the in-database enum constant.

    Describe alternatives you've considered Maybe leave the opportunity to use enums without a specific interface implementation, such that less runtime-errors occurs.

    Additional context No.

    enhancement 
    opened by a-vezzoli-02 0
Releases(v0.1.4)
  • v0.1.4(Jul 24, 2022)

  • v0.1.0-alpha(May 22, 2022)

    Version

    This release is just an alpha, which means that the library should not be used in a production environment. Many changes may and will happen, and some of them may be incompatible with this release.

    Goal

    The main goal of this release is to:

    • Show how the library works
    • Providing a minimal functional code that can be used as a demo

    Features

    All the main features included in this release:

    • Connect to the database specifying the connection parameters in the RacoonConfiguration object
    • Pooling support with the RacoonDen object:
      • The pool can be configured in the RacoonConfiguration object
      • The RacoonDen object is the primary way of creating RacoonManager instances
    • Transaction support with the RacoonManager class
    • Execute query in the database with raw SQL queries:
      • Execute SELECT queries using the QueryRacoon or the find method of the RacoonManager
      • Execute INSERT queries using the InsertRacoon or the insert method of the RacoonManager
      • Execute UPDATE queries using the ExecuteRacoon or the update method of the RacoonManager
    • Record to object mapping:
      • The result of a QueryRacoon can be mapped to a list of objects
      • The result of a QueryRacoon can be mapped to a list of wrapper objects
      • The result of update and insert modify the object accordingly
    • Support for default and custom table aliasing
    • Support for custom type conversion
    • String function extension for snake case conversion
    Source code(tar.gz)
    Source code(zip)
    racoon-0.1.0-alpha.zip(70.54 KB)
Owner
null
lightweight and minimalist ORM for Java/Android. works with SQLite & MySQL. (not actively maintained)

Description ORMAN is an minimalistic and lightweight ORM framework for Java which can handle your common database usage without writing SQL and strugg

Ahmet Alp Balkan 246 Nov 20, 2022
Object-relational mapping for Android

RushOrm Object-relational mapping for Android RushOrm replaces the need for SQL by mapping java classes to SQL tables. What is the aim? The aim is to

Stuart Campbell 172 Nov 11, 2022
A lightweight wrapper around SQLiteOpenHelper which introduces reactive stream semantics to SQL operations.

SQL Brite A lightweight wrapper around SupportSQLiteOpenHelper and ContentResolver which introduces reactive stream semantics to queries. Deprecated T

Square 4.6k Jan 5, 2023
A wrapper around Android's SQLiteDatabase with restoring capability

Restorable SQLiteDatabase RestorableSQLiteDatabase is a wrapper to replicate android's SQLiteDatabase class with restoring capability. This wrapper ma

Navid 21 Oct 21, 2022
Kotlin-Exposed-SQL - Example of using Exposed with Kotlin for the consumption of relational SQL Databases

Kotlin Exposed SQL Sencillo ejemplo sobre el uso y abuso de Exposed ORM de Jetbr

José Luis González Sánchez 3 Jun 14, 2022
requery - modern SQL based query & persistence for Java / Kotlin / Android

A light but powerful object mapping and SQL generator for Java/Kotlin/Android with RxJava and Java 8 support. Easily map to or create databases, perfo

requery 3.1k Dec 29, 2022
A Java/Kotlin library for Android platform, to manage bean's persistence in SQLite, SharedPreferences, JSON, XML, Properties, Yaml, CBOR.

Thanks to JetBrains for support Kripton Persistence Library project! Kripton Persistence Library Kripton is a java library, for Android platform, that

xcesco 117 Nov 11, 2022
Upsert DSL extension for Exposed, Kotlin SQL framework

Exposed Upsert Upsert DSL extension for Exposed, Kotlin SQL framework. Project bases on various solutions provided by community in the official "Expos

Dzikoysk 23 Oct 6, 2022
Samples demonstrating the usage of Realm-Kotlin SDK

Realm-Kotlin Samples This repository contains a set of projects to help you learn about using Realm-Kotlin SDK Each sample demonstrates different use

Realm 52 Dec 31, 2022
Collection of Kotlin APIs/tools to make using Realm Mobile database easier

Compass Kotlin API and tools to make working with Realm easier Components Compass is designed to make working with Realm easier through collection of

Arunkumar 16 Oct 4, 2022
Upsert DSL extension for Exposed, Kotlin SQL framework

Exposed Upsert Upsert DSL extension for Exposed, Kotlin SQL framework. Project bases on various solutions provided by community in the official "Expos

Reposilite Playground 23 Oct 6, 2022
sql-delight example, a plugin by Square which is pure kotlin and it is useful in kmm

Sql-Delight-Example01 Developed by Mahdi Razzaghi Ghaleh first example of sql-delight What is SqlDelight? Kotlin Multiplatform is one of the most inte

rq_mehdi 0 Jan 24, 2022
RecordMe - Record your voice application with kotlin

RecordMe A simple voice recording app. Made Using : Kotlin, Navigation Component

Steve Waweru 2 Apr 28, 2022
Starter code for Android Kotlin Fundamentals Codelab 6.1 Room

TrackMySleepQuality - Starter Code Starter code for Android Kotlin Fundamentals Codelab 6.1 Room Introduction TrackMySleepQuality is an app for record

YamanAswal 0 Jan 15, 2022
BookSearchApp - Book Search App With Kotlin

BookSearchApp IT Book Search App Search IT books with keyword and view informati

null 1 Feb 7, 2022
Memory objects for Kotlin/JVM and Java

Memoria Why should an object care about where to store their bytes? Examples Basics RAM can used as a memory storage: val ram: BytesMemory = RamMemory

null 6 Jul 29, 2022
JAKO: Just Another Kotlin Orm (PostgreSQL)

JAKO: Just Another Kotlin Orm (PostgreSQL) JAKO is a simple, minimal, no-dependency library to build and execute postgresql statements using a fluent

Alessio 6 May 27, 2022
Room Database Queries with Kotlin Flow

Room Database Queries with Flow This app displays a list of bus stops and arrival times. Tapping a bus stop on the first screen will display a list of

asifj96 0 Apr 26, 2022
Code samples for the second edition of "Kotlin in Action".

Code samples for Kotlin in Action, Second Edition This project contains the code samples from book "Kotlin in Action, Second Edition" by Roman Elizaro

Kotlin 16 Dec 29, 2022