gofr
gofr copied to clipboard
Add support for sqlite
Description:
- Added
sqlite3as an acceptable value forDB_DIALECT - Add import for
github.com/mattn/go-sqlite3driver - Updated the logic to initialize the connection string using only
DB_HOSTfor SQLite - The server/app needs to be built with
CGO_ENABLED=1in 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 Can you please also update the Test function TestSQL_getDBConnectionStringand add the test case for newly added code.
sure
@rokerzfirst101 - please add/extend documentation for using Sqlite in gofr - https://gofr.dev/docs/advanced-guide/dealing-with-datasources
@vipul-rawat I've updated the database documentation
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.
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 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
closing as stale, will add another one