uuid

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package uuid gives SQLite the functions of SQLite's own uuid extension:

sqlite.NewConnector(dsn, uuid.Option())

Then:

uuid()          a random UUID (version 4) as text, '8f2b...-....'
uuid_str(x)     the UUID x, a 16-byte blob or text, as canonical text
uuid_blob(x)    the UUID x, a 16-byte blob or text, as a 16-byte blob

uuid_str and uuid_blob take text with or without dashes and braces, hex digits in either case, and give NULL for NULL or for something that is not a UUID.

Example
package main

import (
	"database/sql"
	"fmt"

	"github.com/liustack/sqlite"
	"github.com/liustack/sqlite/ext/uuid"
)

func main() {
	c, err := sqlite.NewConnector(":memory:", uuid.Option())
	if err != nil {
		panic(err)
	}
	db := sql.OpenDB(c)
	defer db.Close()
	var n int
	var canonical string
	err = db.QueryRow(`SELECT length(uuid()), uuid_str('{A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11}')`).Scan(&n, &canonical)
	if err != nil {
		panic(err)
	}
	fmt.Println(n, canonical)
}
Output:
36 a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11

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