hash

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Option

func Option() sqlite.Option

Option adds the functions to a connector.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL