Skip to content

Commit d36f19f

Browse files
committed
Docs.
1 parent eba71b1 commit d36f19f

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

ext/unicode/unicode.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
// - LIKE and REGEXP operators,
66
// - collation sequences.
77
//
8-
// The implementation is not 100% compatible with the [ICU extension]:
9-
// - upper() and lower() use [strings.ToUpper], [strings.ToLower] and [cases];
10-
// - the LIKE operator follows [strings.EqualFold] rules;
11-
// - the REGEXP operator uses Go [regexp/syntax];
12-
// - collation sequences use [collate].
13-
//
14-
// It also provides (approximately) from PostgreSQL:
15-
// - casefold(),
8+
// Like PostgreSQL, it also provides:
169
// - initcap(),
10+
// - casefold(),
1711
// - normalize(),
1812
// - unaccent().
1913
//
14+
// The implementations are not 100% compatible:
15+
// - upper(), lower(), initcap() casefold() use [strings.ToUpper], [strings.ToLower], [strings.Title] and [cases];
16+
// - normalize(), unaccent() use [transform] and [unicode.Mn];
17+
// - the LIKE operator follows [strings.EqualFold] rules;
18+
// - the REGEXP operator uses Go [regexp/syntax];
19+
// - collation sequences use [collate].
20+
//
2021
// Expect subtle differences (e.g.) in the handling of Turkish case folding.
2122
//
2223
// [ICU extension]: https://sqlite.org/src/dir/ext/icu
@@ -27,6 +28,7 @@ import (
2728
"errors"
2829
"regexp"
2930
"strings"
31+
"sync"
3032
"unicode"
3133
"unicode/utf8"
3234

@@ -159,8 +161,16 @@ func casefold(ctx sqlite3.Context, arg ...sqlite3.Value) {
159161
ctx.ResultRawText(cases.Fold().Bytes(arg[0].RawText()))
160162
}
161163

164+
var unaccentPool = sync.Pool{
165+
New: func() any {
166+
return transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
167+
},
168+
}
169+
162170
func unaccent(ctx sqlite3.Context, arg ...sqlite3.Value) {
163-
unaccent := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
171+
unaccent := unaccentPool.Get().(transform.Transformer)
172+
defer unaccentPool.Put(unaccent)
173+
164174
res, _, err := transform.Bytes(unaccent, arg[0].RawText())
165175
if err != nil {
166176
ctx.ResultError(err) // notest

ext/uuid/uuid.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ import (
1717

1818
// Register registers the SQL functions:
1919
//
20-
// uuid([version], [domain/namespace], [id/data])
21-
//
22-
// Generates a UUID as a string.
23-
//
24-
// uuid_str(u)
25-
//
26-
// Converts a UUID into a well-formed UUID string.
27-
//
28-
// uuid_blob(u)
29-
//
30-
// Converts a UUID into a 16-byte blob.
20+
// - uuid([ version [, domain/namespace, [ id/data ]]]):
21+
// to generate a UUID as a string,
22+
// - uuid_str(u):
23+
// to convert a UUID into a well-formed UUID string,
24+
// - uuid_blob(u):
25+
// to convert a UUID into a 16-byte blob,
26+
// - uuid_extract_version(u):
27+
// to extract the version of a RFC 4122 UUID,
28+
// - uuid_extract_timestamp(u):
29+
// to extract the timestamp of a version 1/2/6/7 UUID,
30+
// - gen_random_uuid(u):
31+
// to generate a version 4 (random) UUID.
3132
func Register(db *sqlite3.Conn) error {
3233
const flags = sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS
3334
return errors.Join(
@@ -38,7 +39,8 @@ func Register(db *sqlite3.Conn) error {
3839
db.CreateFunction("uuid_str", 1, flags, toString),
3940
db.CreateFunction("uuid_blob", 1, flags, toBlob),
4041
db.CreateFunction("uuid_extract_version", 1, flags, version),
41-
db.CreateFunction("uuid_extract_timestamp", 1, flags, timestamp))
42+
db.CreateFunction("uuid_extract_timestamp", 1, flags, timestamp),
43+
db.CreateFunction("gen_random_uuid", 0, sqlite3.INNOCUOUS, generate))
4244
}
4345

4446
func generate(ctx sqlite3.Context, arg ...sqlite3.Value) {

0 commit comments

Comments
 (0)