Documentation
¶
Overview ¶
Package hash gives SQLite hash functions:
sqlite.NewConnector(dsn, hash.Option())
Then md5(x), sha1(x), sha256(x), sha512(x) and crc32(x). Each hashes the bytes of a text or a blob (an integer as its decimal text) and gives the hash as a blob, crc32 as an integer. Use hex() for text: hex(sha256('abc')). NULL gives NULL. A REAL is an error: write CAST(x AS TEXT). md5 and sha1 are broken for security: use them to find copies, not to check what someone sent.
Example ¶
package main
import (
"database/sql"
"fmt"
"github.com/liustack/sqlite"
"github.com/liustack/sqlite/ext/hash"
)
func main() {
c, err := sqlite.NewConnector(":memory:", hash.Option())
if err != nil {
panic(err)
}
db := sql.OpenDB(c)
defer db.Close()
var sum string
var crc int64
err = db.QueryRow(`SELECT lower(hex(sha256('abc'))), crc32('hello')`).Scan(&sum, &crc)
if err != nil {
panic(err)
}
fmt.Println(sum)
fmt.Println(crc)
}
Output: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad 907060870
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.