slonik
JDBI
slonik | JDBI | |
---|---|---|
71 | 27 | |
4,422 | 1,917 | |
- | 1.3% | |
9.3 | 9.3 | |
3 days ago | 12 days ago | |
TypeScript | Java | |
GNU General Public License v3.0 or later | Apache 2.0 license |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
slonik
-
Sneakiest development trap: making easy easier...
And sometimes invest instead in learning a technology rather than hide it: for example slonik encourages you to write normal SQL queries by making SQL templating easier and safer. In turn, your IDE would be able to understand those queries and give you support based on the database schemas you actually have.
-
Drizzle is just as unready for prime-time as Prisma, what else is there?
I'd push you to consider using postgres, slonik or similar for database queries. With these libraries, you just write SQL, but they perform input sanitization for you. So you can safely write:
- Slonik: PostgreSQL client for Node.js with runtime validation
-
PostgresJs: The Fastest full featured PostgreSQL client for Node.js and Deno
You can already use postgres with Slonik.
https://github.com/gajus/slonik#user-content-slonik-how-are-...
It is not going to be the default because it is way slower.
https://github.com/gajus/slonik/actions/runs/6616647651
Test node_version:18 test_only:postgres-integration is taking 3 minutes.
Test node_version:18 test_only:pg-integration is taking 38 seconds.
-
Integrating Slonik with Express.js
For those uninitiated, Slonik is a battle-tested SQL query building and execution library for Node.js. Its primary goal is to allow you to write and compose SQL queries in a safe and convenient way. Now, let's see how it pairs with Express.js.
-
Which Postgres client are you using?
I am the maintainer of Slonik and I am trying to understand what portion of this sub-users are using Slonik vs other libraries, and if they are using anything else – what are their reasons for it.
-
JEP Draft: String Templates (Final)
It's nice that they implemented string templates essentially exactly the same way Javascript template literals and tag functions work. They even give an example of using it to create a prepared statement (e.g. DB."SELECT * FROM foo WHERE bar = \{inputParam}") which is exactly what many NodeJS libraries due, e.g. Slonik https://github.com/gajus/slonik, like sql`SELECT * FROM foo WHERE bar = ${inputParam}`;
-
We use TypeScript not based on preference, but because we want to make money
I've found libraries like Zod useful when interacting with external data sources like a database. Slonik[1] uses Zod to define the types expected from a SQL query and then performs runtime validation on the data to ensure that the query is yielding the expected type.
I don't think it's necessary to use Zod/runtime validation everywhere, but it's a nice tool to have on hand.
[1]https://github.com/gajus/slonik
-
Is ORM still an anti-pattern?
Demonstrate how easily and accidentally one can make an SQL injection with these:
https://github.com/porsager/postgres
https://github.com/gajus/slonik
-
The Epic Stack by Kent C. Dodds
Have you tried Slonik (https://github.com/gajus/slonik)? It won't generate types from queries automatically, but it encourages writing SQL vs. a query builder and allows type annotations of queries with Zod. Query results are validated at runtime to ensure the queries are typed correctly.
JDBI
-
Permazen: Language-natural persistence to KV stores
While this may work for greenfield applications, I don't see this working well for preexisting schemas. From their getting started page: "Database fields are automatically created for any abstract getter methods", which definitely scares me away since they seem to be relying on automatic field type conversions.
I prefer to manage my schemas when I can and do type and DAO conversions via mapper classes in the very simple and elegant JDBI framework where you write SQL annotations above your DAO methods https://jdbi.org/#_declarative_api
JDBI does wonders for wonky old schemas you've inherited, since joins etc work out of the box (just throw them in your annotations!) The annotations can also link to .SQL files for the big hairy queries.
All these "do magic" frameworks (hibernate being one of the first) work in the simple cases but then fall apart whenever you need to do anything complex/not-prescribed. I end up having to dig into the internals of the framework to see what's going wrong which negates their whole value add.
-
Is ORM still an anti-pattern?
> I've been doing ORM on Java since Hibernate was new, and it has always sucked.
Have you ever looked at something like myBatis? In particular, the XML mappers: https://mybatis.org/mybatis-3/dynamic-sql.html
Looking back, I actually quite liked it - you had conditionals and ability to build queries dynamically (including snippets, doing loops etc.), while still writing mostly SQL with a bit of XML DSL around it, which didn't suck as much as one might imagine. The only problem was that there was still writing some boilerplate, which I wasn't the biggest fan of.
Hibernate always felt like walking across a bridge that might collapse at any moment (one eager fetch away from killing the performance, or having some obscure issue related to the entity mappings), however I liked tooling that let you point towards your database and get a local set of entities mapped automatically, even though codegen also used to have some issues occasionally (e.g. date types).
That said, there's also projects like jOOQ which had a more code centric approach, although I recall it being slightly awkward to use in practice: https://www.jooq.org/ (and the autocomplete killed the performance in some IDEs because of all the possible method signatures)
More recently, when working on a Java project, I opted for JDBI3, which felt reasonably close to what you're describing, at the expense of not being able to build dynamic queries as easily, as it was with myBatis: https://jdbi.org/
That said, with the multi-line string support we have in Java now, it was rather pleasant regardless: https://blog.kronis.dev/tutorials/2-4-pidgeot-a-system-for-m...
I don't think there's a silver bullet out there, everything from lightweight ORMs, to heavy ORMs like Hibernate, or even writing pure SQL has drawbacks. You just have to make the tradeoffs that will see you being successful in your particular project.
-
Sketch of a Post-ORM
I found JDBi[1] to be a really nice balance between ORM and raw SQL. It gives me the flexibility I need but takes care of a lot of the boilerplate. It's almost like a third category.
1. http://jdbi.org
- Is it just me, or does the Spring Framework lead to hard-to-maintain code and confusion with annotations?
-
Can someone tell me a good resource to learn and practice JDBC in java?
You could use something like jdbi or mybatis. It's not as ugly as raw jdbc and easier to use without all of the gunk from an ORM like hibernate.
-
Which JVM Language Would You Choose for a New Server-Side Project?
We use JDBI. Very simple and lightweight. It uses an object mapper not a full fledged ORM.
-
Why people don't like Java?
Alternatively there are... hybrid solutions like Kotlin's https://github.com/JetBrains/Exposed or https://jdbi.org/ that don't quite... do all the heavy lifting for querying but allow you to sorta stitch queries together manually.
-
Top 5 Server-Side Frameworks for Kotlin in 2022: Micronaut
As seems that Micronaut does not include anything similar by default, we use JDBI and that SQL to retrieve one random greeting from the greetings table.
-
Fiz um mapa interativo com os resultados do segundo turno do STE com postgres (+postgis) e openlayers
Ah! E sobre o que eu usei no backend, alem de postgres e fly.io, o backend eh eh Java, usando um framework chamado quarkus e jdbi pra fazer a interface com o banco.
-
Is JDBC becoming a “legacy” API??
More personally, I'm not much an ORM guy. I've just never found that the benefits outweigh the costs, but that's just my opinion. That said, I don't use JDBC directly in my own projects anymore, strongly preferring to use JDBI instead. I find that it walks the line between "make using the database easier" and "get between you and the database" beautifully. But there's not a darn thing wrong with using JDBC directly.
What are some alternatives?
Knex - A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.
jOOQ - jOOQ is the best way to write SQL in Java
TypeORM - ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Spring Data JPA - Simplifies the development of creating a JPA-based data access layer.
Prisma - Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
HikariCP - 光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Sequelize - Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.
sql2o - sql2o is a small library, which makes it easy to convert the result of your sql-statements into objects. No resultset hacking required. Kind of like an orm, but without the sql-generation capabilities. Supports named parameters.
pgtyped - pgTyped - Typesafe SQL in TypeScript
Querydsl - Unified Queries for Java
pg-promise - PostgreSQL interface for Node.js
Flyway - Flyway by Redgate • Database Migrations Made Easy.