-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Helper functions for time.Time #26
Comments
While I agree that storing times is a pretty common case (I use it a lot myself!), I don't want to introduce the surface area in this package. Reason being: SQLite notably doesn't have a time type, so the representation that applications use vary based on need. I would rather just expose the column access primitives, and then have applications transform the data into I'm open to hearing concrete API proposals, but I don't want to raise hopes that I'm necessarily going to merge anything. After all, "no is temporary, yes is forever." Notes:
|
I want to argue but damn, you have thought it through. Maybe it could/should live at a sqlitex level, if at all. |
I agree that sqlitex would be the right place for it, if such a function should be added. The strawman I've been thinking of is: package sqlitex
// ColumnTime returns a query result as a time in UTC. The time must be
// in one of the formats 1-7 from https://sqlite.org/lang_datefunc.html#time_values.
// That is, one of:
//
// YYYY-MM-DD
// YYYY-MM-DD HH:MM
// YYYY-MM-DD HH:MM:SS
// YYYY-MM-DD HH:MM:SS.SSS
// YYYY-MM-DDTHH:MM
// YYYY-MM-DDTHH:MM:SS
// YYYY-MM-DDTHH:MM:SS.SSS
//
// Column indices start at 0.
func ColumnTime(stmt *sqlite.Stmt, col int) time.Time
// GetTime returns a query result value for colName as a time.
func GetTime(stmt *sqlite.Stmt, colName string) time.Time The part where I'm stuck is that this implies for symmetry that there should be a stmt.BindText(1, timeValue.Format("2006-01-02 15:04:05")) |
I was thinking of it being a little more complicated than that. So for example if you're using the Julian for float64 you can actually get down to the microsecond level if I recall correctly. The string version is easier give that saucing and loading as time.3339 works well already. I can totally add in my own version no problem it just seems like something that's very common at this level |
I'd be nice to be able to have Get/Set of time.Time directly. Versions for rfc3339, int64 unix sec && int64 unix milliseconds it what i tend to use most. Are you open to PRs?
The text was updated successfully, but these errors were encountered: