cosmosSql

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 11 Imported by: 0

README

golang-comos-sql-api

A simple golang package for querying an Azure Cosmos DB. This is needed because the Azure-sdk-for-go only allows querying individual elements from the database.

Quickstart

go get github.com/Brownymister/golang-comos-sql-api

Example

Example of executing a query in a Cosmos DB container. In this example, you can query multiple elements.

container := NewContainer(tt.args.endpoint_uri, tt.args.master_key, tt.args.database, tt.args.container)

query := TQuerry{
    Query: "SELECT * FROM c WHERE c.name = @name",
    Parameters: []TParameter{
        {
            Name:  "@name",
            Value: "Test",
        },
    },
},

status, body, continuation := container.Select(query, "", 0, "")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerData

type ContainerData struct {
	// contains filtered or unexported fields
}

func (*ContainerData) Insert

func (container *ContainerData) Insert(insertBody string, partitionkey string) (Status string, Body string, Continuation string)

func (*ContainerData) Select

func (container *ContainerData) Select(querry TQuerry, partitionkey string, max_item_count int, continuation string) (Status string, Body string, Continuation string)

execute the passed query using the rest api

type ContainerFuncs

type ContainerFuncs interface {
	Select(querry TQuerry, partitionkey string, max_item_count int, continuation string) (Status string, Body string, Continuation string)
	Insert(insertBody string, partitionkey string) (Status string, Body string, Continuation string)
}

func NewContainer

func NewContainer(endpoint_uri string, master_key string, database string, containerName string) ContainerFuncs

type TParameter

type TParameter struct {
	Name  string `json:"name"`  // query Parameter selector (starts with @)
	Value any    `json:"value"` // value of the Parameter
}

type TQuerry

type TQuerry struct {
	Query      string       `json:"query"`
	Parameters []TParameter `json:"parameters"`
}

TQuerry structure for querry call:

Jump to

Keyboard shortcuts

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