json-queries

command
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 4 Imported by: ? 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.

README

JSON Queries

This example demonstrates JSON query functionality for querying and updating JSON columns in your database.

Features Demonstrated

  • Querying JSON fields for specific values using WhereJsonContains
  • Querying JSON arrays for values
  • Checking if JSON keys exist using WhereJsonContainsKey
  • Checking JSON array length using WhereJsonLength
  • Array indexing in JSON queries
  • Updating JSON fields with path notation
  • Combining multiple JSON query conditions

Running the Example

cd examples/json-queries
go run main.go

Running Tests

cd examples/json-queries
go test -v

Prerequisites

  • SQLite database (or modify the DSN to use your preferred database)
  • The example creates a products table with a JSON attributes column

Database Support

JSON query functions are supported for:

  • SQLite: Uses json_extract, json_type, and json_array_length functions
  • MySQL: Uses JSON_CONTAINS, JSON_CONTAINS_PATH, and JSON_LENGTH functions
  • PostgreSQL: Uses JSON functions (implementation may vary)

Example JSON Path Syntax

  • column->field - Access nested field
  • column->field->nested - Access deeply nested field
  • column->array->0 - Access array element by index

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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