mirror of
https://github.com/VinGarcia/ksql.git
synced 2025-09-04 19:36:56 +00:00
Updated KSQL vs Other Tools (markdown)
parent
475717a1ef
commit
a660fe3239
@ -1,27 +1,38 @@
|
|||||||
## Why KSQL and not SQLX, PGX, or GORM?
|
## Why KSQL and not SQLX, PGX, or GORM?
|
||||||
|
|
||||||
|
### Low-level tools:
|
||||||
|
|
||||||
If you have worked with the `database/sql` package, `sqlx`
|
If you have worked with the `database/sql` package, `sqlx`
|
||||||
or even `pgx` you might have felt as I did that it feels
|
or even `pgx` you might have got the impression as I did that
|
||||||
awkward:
|
it feels awkward.
|
||||||
|
|
||||||
|
I did write a text explaining my concerns regarding these libraries,
|
||||||
|
so if you want a more in-depth view please [read it here](https://betterprogramming.pub/golang-sql-problems-with-existing-libraries-145a037261b8)
|
||||||
|
|
||||||
|
But here follows a short description of the issues I find when working with these libraries:
|
||||||
|
|
||||||
1. Too many error checks even for simple queries
|
1. Too many error checks even for simple queries
|
||||||
2. Easy ways of writing errors, like breaking the order of the `.Scan` arguments
|
2. Easy ways of writing errors, like breaking the order of the `.Scan` arguments,
|
||||||
forgetting to call `rows.Close()` or calling it before checking for errors,
|
forgetting to call `rows.Close()`, calling `defer rows.Close()` before checking for errors,
|
||||||
missing some error check, forgetting to call `.Rollback()` or `.Commit()`.
|
missing error checks, forgetting to call `.Rollback()` or `.Commit()` and so on.
|
||||||
3. There is a lot of code duplication in regards to attributes/column names, that need
|
3. There is a lot of code duplication in regards to attributes/column names, that need
|
||||||
to be repeated on many different queries on the same struct.
|
to be repeated on many different queries on the same struct.
|
||||||
4. No easy way to make common actions like inserting a record, making updates, partial updates, or deletes.
|
4. No easy way to make common actions like inserting a record, making updates, partial updates, or deletes.
|
||||||
|
|
||||||
|
### High-level tools:
|
||||||
|
|
||||||
Because of that some people feel tempted to use ORMs and in Go the most famous one is GORM.
|
Because of that some people feel tempted to use ORMs and in Go the most famous one is GORM.
|
||||||
|
|
||||||
However, ORMs are complicated tools that require the whole team to learn them, they are less stable
|
However, ORMs are complicated tools that require the whole team to learn them, they are less stable
|
||||||
and readable than pure SQL and will often help developers to write bad and inefficient queries
|
and readable than pure SQL and will often allow or even encourage developers to write bad and
|
||||||
or even bugs for lack of understanding of the tool.
|
inefficient queries or even bugs for lack of understanding of the tool.
|
||||||
|
|
||||||
> To illustrate this it might be enough to say that a quick search on
|
> To illustrate this it might be enough to say that a quick search on
|
||||||
> [GORM's godoc](https://pkg.go.dev/github.com/jinzhu/gorm#pkg-index)
|
> [GORM's godoc](https://pkg.go.dev/github.com/jinzhu/gorm#pkg-index)
|
||||||
> shows it has in total 169 public functions.
|
> shows it has in total 169 public functions.
|
||||||
|
|
||||||
|
### Tools relying on Code Generation:
|
||||||
|
|
||||||
Finally, we have Code Generation tools like `sqlc` and `sqlboiler`, and if that's your thing you might prefer to use them.
|
Finally, we have Code Generation tools like `sqlc` and `sqlboiler`, and if that's your thing you might prefer to use them.
|
||||||
|
|
||||||
However, there are also reasons not to:
|
However, there are also reasons not to:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user