dbxml

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2021 License: BSD-2-Clause Imports: 6 Imported by: 7

README

A basic Go interface to Oracle Berkeley DB XML

This requires Go version 1.2

Install

go get github.com/pebbe/dbxml

Docs

Documentation

Overview

A basic Go interface to Oracle Berkeley DB XML.

https://www.oracle.com/database/berkeley-db/xml.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(query string, namespaces ...Namespace) error

Check if query is valid without opening a database.

func Version

func Version() (major, minor, patch int)

Get DbXml version

Types

type Db

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

A database connection.

func Open

func Open(filename string) (*Db, error)

Open a database.

Attempt to open the database in read+write mode. If that fails, open in read-only mode.

Call db.Close() to ensure all write operations to the database are finished, before terminating the program.

func OpenRead

func OpenRead(filename string) (*Db, error)

Open a database in read-only mode.

func OpenReadWrite

func OpenReadWrite(filename string) (*Db, error)

Open a database in read+write mode.

Call db.Close() to ensure all write operations to the database are finished, before terminating the program.

func (*Db) All

func (db *Db) All() (*Docs, error)

Get all xml documents from the database.

Example:

docs, err := db.All()
if err != nil {
    fmt.Println(err)
} else {
    for docs.Next() {
        fmt.Println(docs.Name(), docs.Content())
    }
    if err := docs.Error(); err != nil {
        fmt.Println(err)
    }
}

func (*Db) Close

func (db *Db) Close()

Close the database.

This flushes all write operations to the database.

This is called automaticly on garbage collection. Note that teminating the program does not call the garbage collector.

func (*Db) Get

func (db *Db) Get(name string) (string, error)

Get an xml document by name from the database.

func (*Db) Merge

func (db *Db) Merge(filename string, replace bool) error

Merge a database from disc into this database.

func (*Db) Prepare

func (db *Db) Prepare(query string, namespaces ...Namespace) (*Query, error)

Prepare an XPATH query that runs on the default collection.

The query can be run multiple times, and a running query can be cancelled by query.Cancel()

func (*Db) PrepareRaw added in v1.3.0

func (db *Db) PrepareRaw(query string, namespaces ...Namespace) (*Query, error)

Prepare an XPATH query without setting the default collection.

The query can be run multiple times, and a running query can be cancelled by query.Cancel()

func (*Db) PutFile

func (db *Db) PutFile(filename string, replace bool) error

Put an xml file from disc into the database.

func (*Db) PutXml

func (db *Db) PutXml(name string, data string, replace bool) error

Put an xml document from memory into the database.

func (*Db) Query

func (db *Db) Query(query string, namespaces ...Namespace) (*Docs, error)

Get all xml documents that match the XPATH query from the database.

Example:

docs, err := db.Query(xpath_query)
if err != nil {
    fmt.Println(err)
} else {
    for docs.Next() {
        fmt.Println(docs.Name(), docs.Content())
    }
    if err := docs.Error(); err != nil {
        fmt.Println(err)
    }
}

func (*Db) QueryRaw added in v1.3.0

func (db *Db) QueryRaw(query string, namespaces ...Namespace) (*Docs, error)

TODO: Get all... what?

func (*Db) Remove

func (db *Db) Remove(name string) error

Remove an xml document from the database.

func (*Db) Size

func (db *Db) Size() (uint64, error)

Get the number of xml documents in the database.

type Docs

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

An iterator over xml documents in the database.

func (*Docs) Close

func (docs *Docs) Close()

Close iterator over xml documents in the database, that was returned by db.All(), db.Query(query), or query.Run().

This is called automaticly if docs.Next() reaches false, but you can also call it inside a loop to exit it prematurely:

docs, _ := db.All()
for docs.Next() {
    fmt.Println(docs.Name(), docs.Content())
    if some_condition {
        docs.Close()
    }
}

func (*Docs) Content

func (docs *Docs) Content() string

Get content of current xml document after call to docs.Next().

func (*Docs) Error

func (docs *Docs) Error() error

Get the error, if any, after docs.Next() returned false.

func (*Docs) Match

func (docs *Docs) Match() string

Get matched subtree from current xml document after call to docs.Next().

func (*Docs) Name

func (docs *Docs) Name() string

Get name of current xml document after call to docs.Next().

func (*Docs) Next

func (docs *Docs) Next() bool

Iterate to the next xml document in the list, that was returned by db.All(), db.Query(query), or query.Run().

func (*Docs) Value added in v1.3.0

func (docs *Docs) Value() string

Get expression result, for when it is not an xml element

type Namespace added in v1.1.0

type Namespace struct {
	Prefix string
	Uri    string
}

Namespaces for queries

type Query

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

A prepared query that can be run multiple times and interrupted while running.

func (*Query) Cancel

func (query *Query) Cancel()

Cancel a running query.

func (*Query) Close

func (query *Query) Close()

Close a query that was created with Prepare()

This is called automaticly when the database is closed.

func (*Query) Run

func (query *Query) Run() (*Docs, error)

Run a prepared query.

Jump to

Keyboard shortcuts

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