Move query to its own subpackage (#152)
Move all the query system to its own package. The reason is to avoid it to rely on unexported methods and structures, and move it out of the main package since this is really not a core feature. It is still tied to the toml.TomlTree and toml.Position structures for now. * Move query mechanism to its own subpackage * Rename QueryResult to Result to avoid stutter * Add query.CompileAndExecute Fixes #116
This commit is contained in:
@@ -36,6 +36,11 @@ func TreeFromMap(m map[string]interface{}) (*TomlTree, error) {
|
||||
return result.(*TomlTree), nil
|
||||
}
|
||||
|
||||
// Position returns the position of the tree.
|
||||
func (t *TomlTree) Position() Position {
|
||||
return t.position
|
||||
}
|
||||
|
||||
// Has returns a boolean indicating if the given key exists.
|
||||
func (t *TomlTree) Has(key string) bool {
|
||||
if key == "" {
|
||||
@@ -247,15 +252,6 @@ func (t *TomlTree) createSubTree(keys []string, pos Position) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Query compiles and executes a query on a tree and returns the query result.
|
||||
func (t *TomlTree) Query(query string) (*QueryResult, error) {
|
||||
q, err := CompileQuery(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return q.Execute(t), nil
|
||||
}
|
||||
|
||||
// LoadReader creates a TomlTree from any io.Reader.
|
||||
func LoadReader(reader io.Reader) (tree *TomlTree, err error) {
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user