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
Proposed PR: configurable time encoding #1126
Comments
I would think that you would have to change reading/parsing to also consider the custom encoding, or else it will be unable to read what it just wrote, unless it happens to be the same as one of the entries in I also wonder if this sort of thing would be better in a |
For truly custom formats, that's right. I was envisioning that these would be more of a enum type that would relate to selecting one of the Lines 2126 to 2140 in 8543684
Today if I have a unix timestamp stored in e.g. a As for the location of the configuration... I'm not partial to it and actually don't know that much about the options available. I only picked the DSN since I was familiar with it and saw other config there. I can take a look at a Connector implementation if you think that is now worth investing in. |
The other thing to keep in mind is that with what you are proposing, it would affect the entire connection. You might be better served making something that implements |
I started this with experiments using custom types. They work for the database's use, but those same time values are then used lots of other places and it gets tedious bumping into I don't know if there is any other way to effect per-field configuration. Well, I'll let you think it over and no biggee if you decide the design doesn't fit and you close this. The fork is pretty easy to keep up and serves my needs. |
I’ve also run into this issue. I tend to write time in a string format in the highest resolution SQLite natively supports (milliseconds), without truncation of 0 suffixes, for sortability: I’ve resorted to a custom type with (de)serialization which embeds a I’ve played with solutions myself. One I liked was having a driver initializer constructor function taking a struct, instead of relying on an |
Hi, and thank you for an excellent library that I've used for years!
This driver stores
time.Time
values as strings:go-sqlite3/sqlite3.go
Line 219 in 8543684
int
version of whatever time I'm using.I'd like to propose a new driver configuration parameter,
_time_format
, that would let one opt into different storage formats. This lets you usetime.Time
directly but get the encoding you want. I've built a version that allowsunix
andunix_ms
formats, and it is a small (~dozen LOC) change: kalafut/go-sqlite3.Other formats could be added in the future too, which might be useful (e.g. I noticed #951 (comment)). Note that this is completely opt-in and only affects the way values are written. Reading/parsing is unchanged.
Is this of any interest? If so I can prepare a proper PR with better, consolidated tests, and some docs.
Thanks for taking a look.
The text was updated successfully, but these errors were encountered: