Why is there a pyramid image on a SQL article ? Haha, good question ! This article is about how to organize a SQL table to represent a tree as a pyramid shape. This technique was explained to me briefly by very skilled SQL programmer. And I must say that I did not understand the interest at first. Only by putting the explanations on paper (and by doing some drawings) I understood all the interest of this clever method.
Pointer or not and mutable or not If you don’t know what’s a pointer or want a reminder you may read the excelent Dave Cheney post : Understand Go pointers in less than 800 words or your money back When should I use pointer, when should I use reference ? TLDR: Methods using receiver pointers are common; the rule of thumb for receivers is, “If in doubt, use a pointer.
Golang and Unicode First what’s a string in go ? In go a string is an immutable slice of byte. In go every string you declare is UTF-8 encoded (but the one you get from user may have different encoding; you must absolutely know the encoding of a string you get). Some definition Unicode define every letter in the world as code points. UTF-8 is a manner to encode all this code point (there is many : UTF-16, UTF-32, UTF-7), UTF-8 is the one used for best space efficiency : a char can be 1 byte (with ASCII table compatibility) or more (up to 4); comparing to UTF-16 where the minimum size is 2 bytes; UTF-32 is best for speed in string manipulation (knowing that every code points is always 4 bytes enable random access : string slicing is O(1) in UTF-32 and O(n) in UTF-8) … and UTF-7 is a bizarre Unicode unofficial encoding used only by imap, let’s not worry about it.
SQL scan in Go without headache If this is first time you do sql with Go you probably should read this tutorial first, and comme back here to improve scan. TLDR: Use sqlx for doing SQL. sqlx sit on top of standard sql library adding very convenient function especialy to scan result to a struct. SQL scan without sqlx Sql scan is a little bit tedious in Golang : the scan order must match your SQL query order.
- OLDER POSTS
- page 1 of 2