gofr icon indicating copy to clipboard operation
gofr copied to clipboard

Add support for sqlite

Open rokerzfirst101 opened this issue 1 year ago • 7 comments
trafficstars

Description:

  • Added sqlite3 as an acceptable value for DB_DIALECT
  • Add import for github.com/mattn/go-sqlite3 driver
  • Updated the logic to initialize the connection string using onlyDB_HOST for SQLite
  • The server/app needs to be built with CGO_ENABLED=1 in order for the SQLite driver to work

How it works:

To use SQLite as the Database, the user would need to provide the following configs or environment variables:

DB_DIALECT=sqlite3
DB_HOST={connection-string}

Connection String Ref: https://github.com/mattn/go-sqlite3?tab=readme-ov-file#connection-string

Closes #423

rokerzfirst101 avatar Apr 08 '24 08:04 rokerzfirst101

@rokerzfirst101 Can you please also update the Test function TestSQL_getDBConnectionStringand add the test case for newly added code.

Umang01-hash avatar Apr 08 '24 10:04 Umang01-hash

sure

rokerzfirst101 avatar Apr 08 '24 10:04 rokerzfirst101

@rokerzfirst101 - please add/extend documentation for using Sqlite in gofr - https://gofr.dev/docs/advanced-guide/dealing-with-datasources

vipul-rawat avatar Apr 10 '24 06:04 vipul-rawat

@vipul-rawat I've updated the database documentation

rokerzfirst101 avatar Apr 10 '24 09:04 rokerzfirst101

Adding a requirement for cgo reduces compatibility. Many people do prefer to use go without cgo. There is an implementation which does not require cgo, we should prefer that.

vikash avatar Apr 10 '24 19:04 vikash

I've replaced the github.com/mattn/go-sqlite3 pkg with modernc.org/sqlite and updated the documentation. I tested using the migration example for all 3 supported databases, and faced some issues which are also fixed.

rokerzfirst101 avatar Apr 10 '24 22:04 rokerzfirst101

@rokerzfirst101 Rather than taking connection string from the user, we can take the configs in the following way and keep it consistent across for all SQL databases which we currently support

DB_HOST=localhost #Not possible to add? does it support connecting to a remote file in that case it can be supported
DB_USER=root # can be used
DB_PASSWORD=password # can be used
DB_NAME=test #db_name?
DB_DIALECT=mysql #sqlite will be used here

aryanmehrotra avatar May 06 '24 09:05 aryanmehrotra

closing as stale, will add another one

rokerzfirst101 avatar May 23 '24 09:05 rokerzfirst101