discover

package
v0.0.0-...-67f94d3 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CollectionLinks map[string]Link

CollectionLinks is a map with all Links found in the database

type Discover

type Discover struct {
	Fetcher Fetcher
	// contains filtered or unexported fields
}

Discover will walk trought Database using its Fetcher and collect some data about the schema

func New

func New(ctx context.Context, r Fetcher) *Discover

New returns a new discover

func (Discover) Collection

func (d Discover) Collection(ctx context.Context, db string, collection string) (CollectionLinks, error)

Collection retrieves all path that can be an ObjectId

func (Discover) Database

func (d Discover) Database(ctx context.Context, db string) (map[string]CollectionLinks, error)

Database returns all links about all collections inside a Database

type Fetcher

type Fetcher interface {
	ExistsByID(ctx context.Context, db, collection string, id primitive.ObjectID) (bool, error)
	ListDatabases(ctx context.Context) ([]string, error)
	ListCollections(ctx context.Context, db string) ([]string, error)
	SampleCollection(ctx context.Context, db, collection string, size int) ([]primitive.M, error)
}

Fetcher describes all methods needed by Discover

type Link struct {
	Value string `json:"-"`
	Path  string
	With  []string
	Avg   float32
}

Link represents a path that leads to an ObjectId as a string

func Linkify

func Linkify(m primitive.M, currentPath string) ([]Link, error)

Linkify transforms an primitive.M to a slice of Link

type Repository

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

Repository contains all methods to access to Mongodb

func NewRepository

func NewRepository(opts ...RepositoryOptionF) *Repository

NewRepository creates a new Repository

func (Repository) ExistsByID

func (r Repository) ExistsByID(ctx context.Context, db, collection string, id primitive.ObjectID) (bool, error)

ExistsByID tests the existence of a document by its ID in a specific database collection

func (Repository) ListCollections

func (r Repository) ListCollections(ctx context.Context, db string) ([]string, error)

ListCollections will return all collection names for a specific db

func (Repository) ListDatabases

func (r Repository) ListDatabases(ctx context.Context) ([]string, error)

ListDatabases will return all database names that client can access

func (Repository) SampleCollection

func (r Repository) SampleCollection(ctx context.Context, db, collection string, size int) ([]primitive.M, error)

SampleCollection returns a random sample of a specific size from a specific db.collection

type RepositoryOptionF

type RepositoryOptionF func(*Repository)

RepositoryOptionF describes a func that will be called from the New func

func RepositoryWithClient

func RepositoryWithClient(c *mongo.Client) RepositoryOptionF

RepositoryWithClient allows caller to set a specific client which will be used to request

Jump to

Keyboard shortcuts

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