🎯 Specialized PostgreSQL Types

Native support for PostgreSQL's advanced types. IPv4/IPv6, LTree hierarchies, DateRange with type-aware operators.

What are Specialized Types?

FraiseQL natively supports PostgreSQL's advanced data types with GraphQL-friendly operators. Network types (IPv4/IPv6), hierarchical data (LTree), date ranges, and moreβ€”all with type-safe operations no other GraphQL framework provides.

Type PostgreSQL Type Example Operators Use Case
Network (IPv4/IPv6) inet, cidr inSubnet, isPrivate, isLoopback Infrastructure, IoT
Hierarchical Data ltree ancestor_of, descendant_of, matches Organizations, Taxonomies
Date/Time Ranges daterange, tstzrange overlaps, contains, adjacent Scheduling, Availability
JSON/JSONB jsonb contains, has_key, path_exists Flexible schemas

Network Types

1. Define Network Schema

from fraiseql import fraiseql
from fraiseql.types.scalars import IPv4Address, IPv6Address

@fraiseql.type
class Server:
    id: int
    hostname: str
    ipv4: IPv4Address
    ipv6: IPv6Address
    location: str

2. Query with Network Operators

# Find all servers in a subnet
{
  servers(where: {
    ipv4: { inSubnet: "10.0.0.0/8" }
  }) {
    hostname
    ipv4
    location
  }
}

# Find private IP addresses
{
  servers(where: {
    ipv4: { isPrivate: true }
  }) {
    hostname
    ipv4
  }
}

# Find loopback addresses
{
  servers(where: {
    ipv4: { isLoopback: true }
  }) {
    hostname
    ipv4
  }
}

3. Generated SQL

-- FraiseQL generates type-aware PostgreSQL
SELECT * FROM servers
WHERE ipv4::inet << '10.0.0.0/8'::inet;

SELECT * FROM servers
WHERE inet_is_private(ipv4::inet);

SELECT * FROM servers
WHERE host(ipv4::inet) = '127.0.0.1';

-- Native PostgreSQL type casting and functions βœ…

Hierarchical Data (LTree)

1. Define Hierarchical Schema

from fraiseql import fraiseql
from fraiseql.types.scalars import LTree

@fraiseql.type
class Location:
    id: int
    name: str
    path: LTree  # e.g., "usa.california.san_francisco"

@fraiseql.type
class Machine:
    id: str
    name: str
    location: Location

2. Query with Hierarchical Operators

# Find all machines in California (any city)
{
  machines(where: {
    location: {
      path: { ancestor_of: "usa.california.*" }
    }
  }) {
    name
    location { name path }
  }
}

# Find all US locations
{
  locations(where: {
    path: { descendant_of: "usa" }
  }) {
    name
    path
  }
}

# Pattern matching
{
  locations(where: {
    path: { matches: "usa.*.san_*" }
  }) {
    name
    path
  }
}

3. Generated SQL

-- FraiseQL generates ltree-aware queries
SELECT m.* FROM machines m
JOIN locations l ON m.location_id = l.id
WHERE l.path::ltree @> 'usa.california'::ltree;

SELECT * FROM locations
WHERE path::ltree <@ 'usa'::ltree;

SELECT * FROM locations
WHERE path::ltree ~ 'usa.*.san_*'::lquery;

-- Hierarchical queries with ltree operators βœ…

Key Benefits

🌐

Network Management

DevOps, infrastructure, IoT. Filter by subnet, detect private IPs, manage network topologies.

🏒

Hierarchical Data

Organizations, geographic locations, taxonomies. Ancestor/descendant queries with ltree.

πŸ“…

Date Range Queries

Scheduling, availability, booking systems. Overlap detection, containment checks.

πŸ”’

Type Safety

GraphQL validates types at query time. PostgreSQL enforces types at runtime.

⚑

Native Performance

PostgreSQL's specialized indexes (GiST, GIN) for ltree and network types.

🎯

No Workarounds

Other frameworks use strings + custom logic. FraiseQL uses native PostgreSQL types.

Available Operators

Network Types (IPv4/IPv6)

# Network operators
ipv4: {
  inSubnet: "10.0.0.0/8"      # IP in subnet
  isPrivate: true             # RFC 1918 private address
  isLoopback: true            # 127.0.0.1
  eq: "192.168.1.1"           # Exact match
  ne: "0.0.0.0"               # Not equal
}

LTree (Hierarchical)

# Hierarchical operators
path: {
  ancestor_of: "usa.california"     # Parent of path
  descendant_of: "usa"              # Child of path
  matches: "usa.*.san_*"            # Pattern matching
  eq: "usa.california.sf"           # Exact match
}

Date Ranges

# Range operators
availability: {
  overlaps: ["2024-01-01", "2024-12-31"]   # Overlaps range
  contains: "2024-06-15"                   # Contains date
  adjacent: ["2024-12-31", "2025-01-01"]   # Adjacent to range
}

Perfect For

Why This is Unique

Framework Network Types Hierarchical Data Date Ranges
Hasura ❌ String fields ❌ Manual JSON logic ❌ Custom operators
PostGraphile ⚠️ Limited support ⚠️ Plugin required ⚠️ Basic only
Strawberry/Graphene ❌ No native support ❌ Manual implementation ❌ Custom resolvers
FraiseQL βœ… Full support + operators βœ… Native ltree with queries βœ… Range types + operators

No other GraphQL framework has this level of PostgreSQL type support. FraiseQL exposes PostgreSQL's power directly to GraphQL with type-safe operators.

Ready for PostgreSQL's Full Power?

Specialized types are available in FraiseQL v0.9.5+