7 ms·
Show HN: Sqlkit – Golang SQL package with nested transactions
- wrs 7y ago>nullable types are converted into their default value in golang This just seems...wrong. Why would the column be nullable if you don’t actually care if it’s NULL?
- pxue 7y agoFollow up questions: if I read out a nullable text field and write the same struct back into the database is it going to insert an empty string into that column? Also related, how would auto incr pk work?
- kodebrew 7y agoYes I think it would insert an empty string. I think all the tests are using uuid's as primary keys, this is a good point -- thanks for raising.
- noir_lord 7y agoThat would be horrible if you had other systems that predated and did depend on the null (you could argue they shouldn't do that but well shouldn't and didn't aren't the same thing alas).
- caesarshift 7y agoWhy is NULL a bad thing? Sometimes I absolutely want to know if a field is NULL, so i can coalesce to the desired value. I know this is SQL Server specific, since Oracle treats empty strings and NULLs the same, but that approach has always felt wrong to me. Thoughts? Edit: I see maybe that I should have scrolled down further before posting this. Lots of discussion further down about NULL values.
- redis_mlc 7y agoUsing UUIDs as a primary key is considered an anti-pattern from space and performance standpoints. You should use UUIDs only when, you know, you need a UUID.
- pushpop 7y agoIn my experience most of the time a field is nullable it’s by accident. Some RDBMS and/or SQL “IDEs” default to allowing null too, which doesn’t help matters. Personally I think NULL shouldn’t be supported unless the developer categorically sets a “yes, I actually do want this archaic option enabled” flag in their DB backend. Edit: getting a lot of heat for this comment from people misunderstanding it. I’m not saying “null” shouldn’t exist, just that it shouldn’t be the default. Side point: most of the time people think they need null they don’t.
- camdenlock 7y ago“Unset” is an extremely valuable state to be able to check. It’s why we have null/nil in well-designed languages. The zero value of a golang int is not the same as indicating a lack of presence. There are plenty of scenarios where “unset” is a necessary state vs the zero value.
- pushpop 7y agoI agree however it is only valuable under specific circumstances while it can frequently create hidden traps. On balance it causes more problems than it solves. Which is why I suggested it should be an optional flag enabled on the backend rather than the default.
- baq 7y agoMaybe/Option would be better. NULL is what we've got though. setting columns to not null is leaps ahead of most programming languages anyway.
- peteretep 7y ago> On balance it causes more problems than it solves This is far from clear
- pushpop 7y agoLike everything, it depends on your language and framework. But after 30 years of experience writing software in strictly typed languages, I’ve seen lots of people get caught out with nullable fields. However if you’re main body of experience is Perl (for example) then NULL isn’t ever an issue.
- kodebrew 7y agoMaybe this is true? I may not have thought through the entire feature that carefully. The initial thought behind it: Go programmers generally use values for scalars instead of pointers. Can we make an sql mapper that reflects that general practice? Maybe the answer is no.
- vbezhenar 7y agoJava JDBC use similar approach for primitive types and has method wasNull which returns true if the last retrieved value was actually null. I hate that approach, honestly, but that's from Java perspective, may be it's more natural for Go developers.
- wrs 7y agoThere's an inherent semantic mismatch here. SQL scalars have a dimension (NULL) that Go scalars don't have, so Go scalars just don't have enough information to represent SQL values. You have to put that dimension somewhere. Rather than using Go's separate dimension of nil-ness of pointers, you could put it in a separate boolean return value, or wrap it in a struct (see C#'s Nullable<T>), or make it queryable with a separate method (like IsNull(index)). Whatever it is, it also has to be two-way, so you can write NULLs as well as read them.
- nerdponx 7y agoFor any practical usage, this is a fundamentally broken implementation. I spend something like 10% of my working hours un-fucking data that was poisoned by lazy, inconsistent, and/or incorrect handling of missing data. This is what makes Excel such a dumpster fire for handling data. It is absolutely the wrong decision to make any new piece of software that handles missing data like this.
- Rapzid 7y agoGo's defaults for types are great in a lot of go specific ways, but anyone who has dealt with needing to use pointers all over the place in DTOs knows how disgusting it can get.
- kodebrew 7y agoAgreed.
- wilsonfiifi 7y agoAnother nice Go(lang) package for database access that doesn't get in your way when you want to drop down to pure SQL is db [0] by upper.io. [0] https://upper.io/db.v3
- ereyes01 7y agoFor me it doesn't get more seamless than github.com/jmoiron/sqlx No frills, just a little reflection to tie struct fields <=> SQL params.
- dewey 7y agoTwo small issues and one question: - the link to GoDoc is not working yet: https://godoc.org/github.com/colinjfw/sqlkit https://godoc.org/github.com/colinjfw/sqlkit - Typo in the README: Unmarsal instead of Unmarshal Without going through everything in detail, why would I pick this over the very popular sqlx? https://github.com/jmoiron/sqlx https://github.com/jmoiron/sqlx
- kodebrew 7y agoThanks for finding the typos! Short answer: It's sqlx + a query builder + some extras around transaction management.
- Betty5Oliver 7y agoYou can also work together with who pick me out of collections and debt, He's so kind, real, legit and with affordable price. he help me boost my credit score to 795 plus pay off my credit card and business loan debt within the next 4 days after i contact him and pay the upfront payment he ask for. Get him for similar issue on : richskrentacyberservice AT gmail DOT com He was the one who made me happy again.
- waynewhite827 7y agoIt was so so nice that kevin introduce me to Permanentcreditrepairer the most creditable and reliable hacker on internet and no one has ever spoke nagetive about him. he`s into various kind of jobs like : Facebook hacking/spying, Whatsapp spying, Phone tracking and cloning, Snapchat, Instagram, Wechat, Text messages, Bank statement, Increasing your credit score, Hack hangouts or any media messenger or sites. You can contact him via PERMANENTCREDITREPAIRER AT gmail DOT com. YOU WILL BE GLAD YOU DO SO..... GOODLUCK!!!
- woodjcb 7y agoI was in such a hurry because I needed my credit score boost up quickly for the personal loan i need to enlargement family. Have been powerless for years my kids doesn’t go to a school of my choice. Thanks to Rich who light up the candle, He Erase My Negative Credit Bureau, Equifax off my TransUnion and get up my score to 797 along the process. Reach him via # plus mail: richskrentacyberservice@gmail.com. +1 (440) 459-0850
- elishacavil8 7y agoHello friends i just have to share this very incredible hacker who you will enjoy is service so much that you would be unable to stopnworking with him, I had a low credit score and late payments. so i got strongly attracted with Rich Skrenta HACKER who increased my credit score to 810 across 2 credit bureaus within 2weeks and do away with the late payment plus car loans. i never appreciate this stuff was real until i experienced it myself. Info to contact: RICHSKRENTACYBERSERVICE AT GMAIL DOT COM or by use of (440)459-0850
- fjjseffelaar 7y agoNote! if you are urgently in need of a personal loan or you need a hacker to repair your credit score and remove all negative Equifax. Here is the light to the solution: PERMANENTCREDITREPAIRER@GMAIL.COM. I saw some testimonial shared about him on an article about how people says good things about him, he had save many lives and he deliver his services with all sincerity. I have also tried him and i didn't regret! He help me apply for a loan of $70,000.00 and also pay off my bank dept along the line.