Documentation
¶
Overview ¶
Package ipaddr provides typed IP / CIDR helper functions for SQL queries. Pure Go via net/netip; no external dependencies.
Functions ¶
- ipcontains(prefix, ip) → BOOL: true if prefix contains ip
- ipoverlaps(prefix1, prefix2) → BOOL: true if the two prefixes overlap
- ipfamily(ip-or-prefix) → INTEGER (4 or 6)
- iphost(ip-or-prefix) → TEXT: canonical address form
- ipmasklen(prefix) → INTEGER: prefix bit count
- ipnetwork(prefix) → TEXT: the prefix's masked network address
Ported from ncruces/ext/ipaddr with one upstream bug fix: ipoverlaps in ncruces parses arg[0] twice (lines 50-51 of upstream ipaddr.go), effectively comparing prefix1 to itself. Our version reads each prefix from its own argument, matching the function's documented semantics.
Usage ¶
import (
sqlite "gosqlite.org"
"gosqlite.org/ext/ipaddr"
)
if err := ipaddr.Register(conn); err != nil { ... }
rows, _ := db.QueryContext(ctx,
`SELECT ip FROM events WHERE ipcontains('10.0.0.0/8', ip)`)
For pool-wide install via [gosqlite.org.Driver.ConnectHook], blank-import the auto sub-package:
import _ "gosqlite.org/ext/ipaddr/auto"
Index ¶
Constants ¶
View Source
const ( FuncIPContains = "ipcontains" FuncIPOverlaps = "ipoverlaps" FuncIPFamily = "ipfamily" FuncIPHost = "iphost" FuncIPMaskLen = "ipmasklen" FuncIPNetwork = "ipnetwork" )
Exported names of the SQL functions Register installs.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.