sparql

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: BSD-3-Clause Imports: 12 Imported by: 0

README

pipeline status coverage report

Go SQL driver for SPARQL

SUPER EXPERIMENTAL

A SPARQL-Driver for Go. Including database/sql implementation.

Usage

See examples.

FAQ

Q: Can I use ? for placeholders? A: No. Please use $1, $2, $3, ... as placeholders.

Q: Which version's golang is supported? A: go 1.11.x or later.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Binding

type Binding map[string]struct {
	Type     Type        `json:"type"`
	DataType IRI         `json:"datatype"`
	XMLLang  string      `json:"xml:lang"`
	Value    interface{} `json:"value"`
}

Binding is a part of a SPARQL query result json.

type Client

type Client struct {
	HTTPClient http.Client
	Logger     logger.Logger
	Endpoint   string
	// contains filtered or unexported fields
}

Client queries to its SPARQL endpoint.

func New

func New(endpoint string, opts ...Option) (*Client, error)

New returns `sparql.Client`.

func (*Client) Close

func (c *Client) Close() error

Close closes this client

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping sends a HTTP HEAD request to the endpoint.

func (*Client) Query

func (c *Client) Query(
	ctx context.Context,
	query string,
	params ...Param,
) (*QueryResult, error)

Query queries to the endpoint.

type Head struct {
	Vars []string `json:"vars"`
}

Head is a part of a SPARQL query result json.

type IRI

type IRI string

IRI https://www.w3.org/TR/rdf-sparql-query/#rIRI_REF

func (IRI) Ref

func (i IRI) Ref() string

Ref returns IRI_REF.

type IRIRef

type IRIRef interface {
	Ref() string
}

IRIRef https://www.w3.org/TR/rdf-sparql-query/#rIRIref

type Literal

type Literal struct {
	Value       interface{}
	DataType    IRIRef
	LanguageTag string
}

Literal http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/#dfn-literal

func (Literal) Serialize

func (l Literal) Serialize() string

Serialize returns the serialized literal string.

type Option

type Option func(*Client) error

Option sets an option to the SPARQL client.

func IdleConnTimeout

func IdleConnTimeout(timeout time.Duration) Option

IdleConnTimeout sets the maximum amount of time an idle (keep-alive) connection.

func MaxIdleConns

func MaxIdleConns(n int) Option

MaxIdleConns sets max idle connections.

func Prefix

func Prefix(prefix string, iri IRI) Option

Prefix sets a global PREFIX for all queries.

func Timeout

func Timeout(timeout time.Duration) Option

Timeout sets the connection timeout duration. Also KeepAlive timeout.

type Param

type Param struct {
	// Ordinal position of the parameter starting from one and is always set.
	Ordinal int
	// Value is the parameter value.
	Value interface{}
}

Param is a parameter to fill placeholders

func (Param) Serialize

func (p Param) Serialize() string

Serialize returns the serialized as query parameter. nolint: gocyclo

type PrefixedName

type PrefixedName string

PrefixedName https://www.w3.org/TR/rdf-sparql-query/#rPrefixedName

func (PrefixedName) Ref

func (p PrefixedName) Ref() string

Ref returns PrefixedName.

type QueryResult

type QueryResult struct {
	Head    Head    `json:"head"`
	Results Results `json:"results"`
	Boolean bool    `json:"boolean"`
}

QueryResult is a destination to decoding a SPARQL query result json.

type Results

type Results struct {
	Bindings []Binding `json:"bindings"`
}

Results is a part of a SPARQL query result json.

type Serializable

type Serializable interface {
	Serialize() string
}

Serializable serialize data to embed to queries.

type Type

type Type string

Type is the binding value type.

const (
	TypeIRI          Type = "uri"
	TypeLiteral      Type = "literal"
	TypeTypedLiteral Type = "typed-literal"
	TypeBlankNode    Type = "bnode"
)

Types https://www.w3.org/TR/rdf-sparql-json-res/#variable-binding-results

Directories

Path Synopsis
_example
sql

Jump to

Keyboard shortcuts

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