Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
Conn connects to a SPARQL source.
func (*Conn) QueryContext ¶
func (c *Conn) QueryContext( ctx context.Context, query string, args []driver.NamedValue, ) (driver.Rows, error)
QueryContext queries to a SPARQL source.
Example ¶
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) }
Output:
Example (Hojin_info) ¶
db := sql.OpenDB(NewConnector( "https://api.hojin-info.go.jp/sparql", client.WithHTTPClient(&http.Client{ Timeout: 5 * time.Second, }), client.WithPrefix("hj", "http://hojin-info.go.jp/ns/domain/biz/1#"), client.WithPrefix("ic", "http://imi.go.jp/ns/core/rdf#"), )) ctx := context.Background() if err := db.PingContext(ctx); err != nil { panic(err) } //noinspection SqlDialectInspection rows, err := db.QueryContext(ctx, ` SELECT ?v FROM <http://hojin-info.go.jp/graph/hojin> WHERE { ?n ic:名称/ic:表記 ?v . FILTER regex(?v, "マネー") } LIMIT 100`) if err != nil { panic(err) } for rows.Next() { var v string if err := rows.Scan(&v); err != nil { panic(err) } log.Println(v) } if err := rows.Close(); err != nil { panic(err) } if err := db.Close(); err != nil { panic(err) }
Output:
type Connector ¶
type Connector struct { Name string // contains filtered or unexported fields }
Connector generates `driver.Conn` with a context.
func NewConnector ¶
NewConnector returns `driver.Connector`.
type Driver ¶
type Driver struct{}
Driver accesses SPARQL sources.
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
Rows implements `driver.Rows` with `sparql.QueryResult`.
Click to show internal directories.
Click to hide internal directories.