Skip to content
Vinícius Garcia edited this page Jul 16, 2023 · 11 revisions

Welcome to the KSQL wiki!

KSQL the Keep it Simple SQL library

KSQL was created to offer an actually simple and satisfactory tool for interacting with SQL Databases in Golang.

The core idea on KSQL is to offer an easy to use interface, the actual comunication with the database is decoupled so we can use KSQL on top of pgx, database/sql and possibly other tools. You can even create you own backend adapter for KSQL which is useful in some situations.

Why KSQL?

KSQL is meant to improve on the existing ecosystem by providing a well-designed database package that has:

  1. A small number of easy-to-use helper functions for common use cases
  2. Support for more complicated use-cases by allowing the user to write SQL directly

This strategy allows the API to be

  • Very simple with a small number of functions
  • Harness all the power of SQL, by just allowing the user to type SQL
  • Less opportunities for making mistakes, which makes code reviews easier
  • A succinct and idiomatic Go idiom reducing the cognitive complexity of your code
  • Easy ways of mocking your database when you need to
  • Support for all common relational database: mysql, sqlite, sqlserver and postgres

Some special use-cases also have some special support:

  • The QueryChunks() method helps you in the few situations when you might need to load in a single query more data than would fit in memory.
  • For saving you time when you are selecting all fields from a struct you can omit the SELECT ... part of the query which causes KSQL to write this part for you saving a lot of work when working with big structs/tables.
  • The Nested Structs feature will help you reuse existing structs/models when working with JOINs.

Supported Drivers:

KSQL is well decoupled from its backend implementation which makes it easy to change the actual technology used.

Note: different backend drivers (e.g. one for Postgres, another for Mysql), might expect different SQL dialects and/or support different input types. KSQL only forwards the query, params and scan values to these drivers, and makes no attempt at hiding these differences.

Currently, we already support the following databases:

  • Using the database/sql as the backend we support the following drivers:
    • "sqlite3"
    • "mysql"
    • "sqlserver"
  • For Postgres, we work on top of pgx (actually pgxpool) which is a lot faster for Postgres databases.

If you need a new database/sql driver or backend adapter included please open an issue or make your own implementation and submit it as a Pull Request.