✨ Nifty Utilities and PostgreSQL Extensions for Exposed

Overview

ExposedPowerUtils

Utilities and Extensions for Exposed, because while Exposed is a pretty nice framework, it tries to support a lot of SQL dialects, so a lot of advanced features that aren't supported by the SQL standard aren't supported in Exposed.

Thankfully Exposed is very extendable, allowing you to support features that it doesn't support out of the box! This repository contains a bunch of Exposed tidbits that I use on a lot of my projects.

Getting Started

repositories {
  mavenCentral()
  maven("https://repo.perfectdreams.net/")
}

Then, in your dependencies...

dependencies {
  implementation("net.perfectdreams.exposedpowerutils:ModuleNameHere:CurrentVersionHere")
}

Here's an example!

dependencies {
  implementation("net.perfectdreams.exposedpowerutils:postgres-java-time:1.0.0")
}

Modules

:exposed-power-utils

Contains general purpose extensions and utilities for Exposed, not bound to a specific SQL dialect.

:postgres-power-utils

Contains PostgreSQL extensions and utilities for Exposed.

  • Basic jsonb support
    • You get and store data using Strings, the way how you are going to serialize and deserialize your data is up to you!
  • Create and update PostgreSQL enums with Java enums

Example:

transaction(test) {
// You need to create the PostgreSQL enum before creating any tables that depend on the enum
createOrUpdatePostgreSQLEnum(CharacterType.values())
SchemaUtils.createMissingTablesAndColumns(PlayerInfo)
PlayerInfo.insert {
// The jsonb column returns a String, the serialization and deserialization is up to you!
it[PlayerInfo.information] = "{\"name\":\"MrPowerGamerBR\"}"
it[PlayerInfo.favoriteCharacter] = CharacterType.LORITTA
}
}
}
object PlayerInfo : LongIdTable() {
val information = jsonb("information")
val favoriteCharacter = postgresEnumeration<CharacterType>("favorite_character")
}
// Keep in mind that there are some reserved types in PostgreSQL
// https://www.postgresql.org/docs/current/sql-keywords-appendix.html
enum class CharacterType {
LORITTA,
PANTUFA,
GABRIELA
}

:postgres-java-time

Instant timestamp(...) with PostgreSQL's TIMESTAMP WITH TIMEZONE.

Example:

transaction(test) {
SchemaUtils.createMissingTablesAndColumns(ActionLog)
// Exposed's "timestamp" implementation has an issue where it depends on the system's time zone.
// So if you inserted "Instant.now()", it would depend on your system time zone, and that's not good!
// Imagine if you have two machines in different time zones, and you are trying to keep an audit log,
// even if both codes were executed at the same time, due to time zone differences, both times would
// be different!
//
// If you ran the following code with Exposed's "timestamp", it will fail.
//
// That's why we use the "timestampWithTimeZone", read more at https://www.toolbox.com/tech/data-management/blogs/zone-of-misunderstanding-092811/
val now = Instant.now()
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
val id1 = ActionLog.insertAndGetId {
it[ActionLog.timestamp] = now
it[ActionLog.text] = "Hello from UTC!"
}
TimeZone.setDefault(TimeZone.getTimeZone("America/Sao_Paulo"))
val id2 = ActionLog.insertAndGetId {
it[ActionLog.timestamp] = now
it[ActionLog.text] = "Hello from America/Sao_Paulo!"
}
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
val timezone1 = ActionLog.select { ActionLog.id eq id1 }.first()[ActionLog.timestamp]
val timezone2 = ActionLog.select { ActionLog.id eq id2 }.first()[ActionLog.timestamp]
assert(timezone1 == timezone2) { "The instants aren't equal! $timezone1 $timezone2" }
}
}
object ActionLog : LongIdTable() {
val timestamp = timestampWithTimeZone("timestamp")
val text = text("text")
}


Similar projects:

You might also like...
A simple NoSQL client for Android. Meant as a document store using key/value pairs and some rudimentary querying. Useful for avoiding the hassle of SQL code.

SimpleNoSQL A simple NoSQL client for Android. If you ever wanted to just save some data but didn't really want to worry about where it was going to b

An Android helper class to manage database creation and version management using an application's raw asset files

THIS PROJECT IS NO LONGER MAINTAINED Android SQLiteAssetHelper An Android helper class to manage database creation and version management using an app

SquiDB is a SQLite database library for Android and iOS

Most ongoing development is currently taking place on the dev_4.0 branch. Click here to see the latest changes and try out the 4.0 beta. Introducing S

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

Android library for auto generating SQL schema and Content provider

Android-AnnotatedSQL Android library for auto generating SQL schema and Content Provider by annotations. You will get a full-featured content provider

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

An ORM for Android with type-safety and painless smart migrations
An ORM for Android with type-safety and painless smart migrations

Android Orma Orma is a ORM (Object-Relation Mapper) for Android SQLiteDatabase. Because it generates helper classes at compile time with annotation pr

A simple ToDo app to demonstrate the use of Realm Database in android to perform some basic CRUD operations like Create, Update and Delete.
A simple ToDo app to demonstrate the use of Realm Database in android to perform some basic CRUD operations like Create, Update and Delete.

Creating a Realm Model Class @RealmClass open class Note() : RealmModel { @PrimaryKey var id: String = "" @Required var title: String

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

Owner
💻📱 Transformando sonhos em realidade! — @LorittaBot, @SparklyPower e muito mais!
null
Exposed spring integration and code generator for dsl interface

Infra-ORM 欢迎使用 Infra-ORM, 这是一个基于 Exposed 的 ORM 框架,可以和 Spring Boot 集成良好,如果你是 Kotlin 开发者,推荐你试试 Exposed, 配合 Infra-ORM 可以给你带来最佳的开发体验。 为什么造这个轮子? Exposed 提供

Red Sparrow 1 Jan 2, 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
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
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
Reactive extensions for SimpleNoSQL

RxSimpleNoSQL Reactive extensions for SimpleNoSQL. Manipulate entities using Observables and Completables. Examples Suppose we have the following enti

xmartlabs 37 Aug 29, 2021
AndroidQuery is an Android ORM for SQLite and ContentProvider which focuses on easy of use and performances thanks to annotation processing and code generation

WARNING: now that Room is out, I no longer maintain that library. If you need a library to easy access to default android ContentProvider, I would may

Frédéric Julian 19 Dec 11, 2021
LiteGo is a Java-based asynchronous concurrency library. It has a smart executor, which can be freely set the maximum number of concurrent at same time , and the number of threads in waiting queue. It can also set waiting policies and overload strategies.

LiteGo:「迷你」的Android异步并发类库 LiteGo是一款基于Java语言的「异步并发类库」,它的核心是一枚「迷你」并发器,它可以自由地设置同一时段的最大「并发」数量,等待「排队」线程数量,还可以设置「排队策略」和「超载策略」。 LiteGo可以直接投入Runnable、Callable

马天宇 189 Nov 10, 2022
This is an Online Book App in which user can read and add their books on favourites fragment and also give rating on it.

BookHub-AndroidApp BookHub Basic Android App Based on the concept of Fragment, Navigation Drawer, Database (Room), Internet Access, etc. See the app o

Yash Kumar Shrivas 3 Mar 10, 2022
A blazing fast, powerful, and very simple ORM android database library that writes database code for you.

README DBFlow is fast, efficient, and feature-rich Kotlin database library built on SQLite for Android. DBFlow utilizes annotation processing to gener

Andrew Grosner 4.9k Dec 30, 2022
A blazing fast, powerful, and very simple ORM android database library that writes database code for you.

README DBFlow is fast, efficient, and feature-rich Kotlin database library built on SQLite for Android. DBFlow utilizes annotation processing to gener

Andrew Grosner 4.9k Dec 30, 2022