-
-
Notifications
You must be signed in to change notification settings - Fork 203
Add purego driver #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@Arsen6331, to pass as GORM compatible driver, this should also succeed in all tests of GORM itself (see https://github.com/go-gorm/gorm/tree/master/tests). Hope this helps to clear things out. |
How would I pass a tag to github actions? You need to pass the |
I ran the tests on my desktop. It passed, here are the results:
|
I've figured out how to do the tests in the playground repo: go-gorm/playground#476 |
I think GORM-playground unfortunately doesn't take into account the modified go.mod file, since inside Github actions, the fresh clone of GORM is happening, and the inner tests still use the GORM's original go.mod. I suggest you try cloning GORM itself, and change go.mod inside See this PR for example of such driver switch: https://github.com/go-gorm/gorm/pull/4921/files |
I just tried disabling CGo, and the test failed because -race needs CGo according to the error message. I removed -race and the test succeeded, so it is in fact using the driver I added. |
sounds a reasonable solution for me, but seems like the gorm tests failed even w/o the |
The latest test is successful, with cgo disabled. |
|
I just tried, they do seem to fail. Interestingly, https://github.com/glebarez/sqlite imports https://github.com/glebarez/go-sqlite, which uses the same driver as I do here (modernc.org/sqlite) but doesn't fail the tests. I'm not sure what the difference is between them. |
the https://github.com/glebarez/go-sqlite is a slightly different frontend (database/sql implementation) for modernc.org/sqlite. |
Ok then, I'll modify the PR to use glebarez/go-sqlite if you don't mind. |
Well, it's still not going to work as a simple tag switch for existing users of this driver, because modernc.org/sqlite (and https://github.com/glebarez/go-sqlite) still uses different syntax for PRAGMA specification in connection strings (e.g. enabling foreign-key constraint) |
This comment was marked as outdated.
This comment was marked as outdated.
I just tried using https://github.com/glebarez/go-sqlite, and all the gorm tests succeeded. |
Oh, you meant the cgo and purego drivers use different connection string syntax. It's 2 AM here and I'm tired, sorry for not realizing that. |
It looks like it wouldn't be too difficult to convert between the two syntaxes, if that's a suitable solution. A better solution might just be to document this in the README and warn users about the difference. |
This implements a pure-go alternative driver whenever CGO_ENABLED=0 Related: go-gorm#93 Fixes: go-gorm#35 Fixes: go-gorm#72 Fixes: go-gorm#77 Fixes: go-gorm#160
What did this pull request do?
This PR adds a purego driver that can be built via tags. The test for purego doesn't use a custom function on the custom driver as it is currently impossible to do that. It instead registers the function on the default driver. The cgo test is unchanged. Other than that, everything should work the same, just pass
-tags purego
when building or testing to switch to the purego driver. Building without the flag will build using the cgo driver.If anything should be changed, I would be happy to do so.
#77
User Case Description
My use case for this change is easy cross-compilation and portability of binaries using GORM.