PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/g17khqpukees4237dtn3astzapmp462vjhsz6st4/datastore

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
datastore
Namespace
g17khqpukees4237dtn3astzapmp462vjhsz6st4
Files
11 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/g17khqpukees4237dtn3astzapmp462vjhsz6st4/datastore
gno
0.9

Files (11)

  • README.mdmarkdown
  • gnomod.tomltoml
  • datastore.gnogno
  • index.gnogno
  • query_options.gnogno
  • query.gnogno
  • record.gnogno
  • schema_options.gnogno
  • schema.gnogno
  • storage_options.gnogno
  • storage.gnogno
  • index.gnogno
    1package datastore23import (4	"gno.land/p/moul/collection/v0"5)67// DefaultIndexOptions defines the default options for new indexes.8

    Functions

    not supported for pure packages by the node (vm/qfuncs)

    Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.

    const DefaultIndexOptions = collection.DefaultIndex | collection.SparseIndex
    9
    10type (
    11 // IndexFn defines a type for single value indexing functions.
    12 // This type of function extracts a single string value from
    13 // a record that is then used to index it.
    14 IndexFn func(Record) string
    15
    16 // IndexMultiValueFn defines a type for multi value indexing functions.
    17 // This type of function extracts multiple string values from a
    18 // record that are then used to index it.
    19 IndexMultiValueFn func(Record) []string
    20
    21 // Index defines a type for custom user defined storage indexes.
    22 // Storages are by default indexed by the auto geneated record ID
    23 // but can additionally be indexed by other custom record fields.
    24 Index struct {
    25 name string
    26 options collection.IndexOption
    27 fn interface{}
    28 }
    29)
    30
    31// NewIndex creates a new single value index.
    32//
    33// Usage example:
    34//
    35// // Index a User record by email
    36// idx := NewIndex("email", func(r Record) string {
    37// return r.MustGet("email").(string)
    38// })
    39func NewIndex(name string, fn IndexFn) Index {
    40 return Index{
    41 name: name,
    42 options: DefaultIndexOptions,
    43 fn: func(v interface{}) string {
    44 return fn(v.(Record))
    45 },
    46 }
    47}
    48
    49// NewMultiValueIndex creates a new multi value index.
    50//
    51// Usage example:
    52//
    53// // Index a Post record by tag
    54// idx := NewMultiValueIndex("tag", func(r Record) []string {
    55// return r.MustGet("tags").([]string)
    56// })
    57func NewMultiValueIndex(name string, fn IndexMultiValueFn) Index {
    58 return Index{
    59 name: name,
    60 options: DefaultIndexOptions,
    61 fn: func(v interface{}) []string {
    62 return fn(v.(Record))
    63 },
    64 }
    65}
    66
    67// Name returns index's name.
    68func (idx Index) Name() string {
    69 return idx.name
    70}
    71
    72// Options returns current index options.
    73// These options define the index behavior regarding case sensitivity and uniquenes.
    74func (idx Index) Options() collection.IndexOption {
    75 return idx.options
    76}
    77
    78// Func returns the function that storage collections apply
    79// to each record to get the value to use for indexing it.
    80func (idx Index) Func() interface{} {
    81 return idx.fn
    82}
    83
    84// Unique returns a copy of the index that indexes record values as unique values.
    85// Returned index contains previous options plus the unique one.
    86func (idx Index) Unique() Index {
    87 if idx.options&collection.UniqueIndex == 0 {
    88 idx.options |= collection.UniqueIndex
    89 }
    90 return idx
    91}
    92
    93// CaseInsensitive returns a copy of the index that indexes record values ignoring casing.
    94// Returned index contains previous options plus the case insensitivity one.
    95func (idx Index) CaseInsensitive() Index {
    96 if idx.options&collection.CaseInsensitiveIndex == 0 {
    97 idx.options |= collection.CaseInsensitiveIndex
    98 }
    99 return idx
    100}
    101