sparql: github.com/garsue/sparql Index | Examples | Files | Directories

package sparql

import "github.com/garsue/sparql"

Index

Examples

Package Files

conn.go connector.go driver.go stmt.go

type Conn Uses

type Conn struct {
    Client *client.Client
}

Conn connects to a SPARQL source.

func (*Conn) Begin Uses

func (*Conn) Begin() (driver.Tx, error)

Begin is not supported. SPARQL does not have transactions.

func (*Conn) Close Uses

func (c *Conn) Close() error

Close closes this connection but nothing to do.

func (*Conn) Ping Uses

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

Ping sends a HTTP HEAD request to the source.

func (*Conn) Prepare Uses

func (c *Conn) Prepare(query string) (driver.Stmt, error)

Prepare returns a prepared statement.

func (*Conn) QueryContext Uses

func (c *Conn) QueryContext(
    ctx context.Context,
    query string,
    args []driver.NamedValue,
) (driver.Rows, error)

QueryContext queries to a SPARQL source.

Code:

db := sql.OpenDB(NewConnector("http://ja.dbpedia.org/sparql"))

ctx := context.Background()
if err2 := db.PingContext(ctx); err2 != nil {
    panic(err2)
}

rows, err := db.QueryContext(
    ctx,
    "select distinct * where "+
        "{ <http://ja.dbpedia.org/resource/東京都> ?p ?o .  } LIMIT 1",
)
if err != nil {
    panic(err)
}

for rows.Next() {
    var p, o client.URI
    if err := rows.Scan(&p, &o); err != nil {
        panic(err)
    }
    log.Printf("%T %v %T %v", p, p, o, o)
}

if err := rows.Close(); err != nil {
    panic(err)
}

var o int
if err := db.QueryRowContext(
    ctx,
    "select distinct * where "+
        "{ <http://ja.dbpedia.org/resource/東京都> "+
        "<http://dbpedia.org/ontology/wikiPageID> ?o .  } LIMIT 1",
).Scan(&o); err != nil {
    panic(err)
}
log.Printf("%T %v", o, o)

if err := db.Close(); err != nil {
    panic(err)
}

type Connector Uses

type Connector struct {
    Name string
    // contains filtered or unexported fields
}

Connector generates `driver.Conn` with a context.

func NewConnector Uses

func NewConnector(
    name string,
    opts ...client.Option,
) *Connector

NewConnector returns `driver.Connector`.

func (*Connector) Connect Uses

func (c *Connector) Connect(ctx context.Context) (driver.Conn, error)

Connect returns `driver.Conn` with a context.

func (*Connector) Driver Uses

func (c *Connector) Driver() driver.Driver

Driver returns underlying `driver.Driver`.

type Driver Uses

type Driver struct{}

Driver accesses SPARQL sources.

func (*Driver) Open Uses

func (d *Driver) Open(name string) (driver.Conn, error)

Open returns `driver.Conn`.

func (*Driver) OpenConnector Uses

func (d *Driver) OpenConnector(name string) (driver.Connector, error)

OpenConnector returns `driver.Connector`.

type Rows Uses

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

Rows implements `driver.Rows` with `sparql.QueryResult`.

func (*Rows) Close Uses

func (r *Rows) Close() error

Close closes the rows iterator.

func (*Rows) Columns Uses

func (r *Rows) Columns() []string

Columns returns the names of the columns.

func (*Rows) Next Uses

func (r *Rows) Next(dest []driver.Value) error

Next is called to populate the next row of data into the provided slice.

type Stmt Uses

type Stmt struct {
    *client.Statement
}

Stmt implements `driver.Stmt` with `sparql.Statement`.

func (*Stmt) Close Uses

func (s *Stmt) Close() error

Close closes the statement. Actually do nothing.

func (*Stmt) Exec Uses

func (*Stmt) Exec(args []driver.Value) (driver.Result, error)

Exec is not supported. DO NOT USE.

func (*Stmt) NumInput Uses

func (s *Stmt) NumInput() int

NumInput is not supported. Always return -1.

func (*Stmt) Query Uses

func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)

Query queries to the endpoint.

func (*Stmt) QueryContext Uses

func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)

QueryContext queries to a SPARQL source.

Directories

PathSynopsis
client

Package sparql imports 5 packages (graph). Updated 2019-01-27. Refresh now. Tools for package owners.