transformer

package module
v0.0.0-...-288ecda Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 7 Imported by: 0

README

datastore-transformer

Library to apply transformations over Google Datastore entities

This repo is not stable yet: Be careful!

Example

Remove field OldField and add field NewField with value 1 to all entities of kind KindToTransform

package main

import (
	"cloud.google.com/go/datastore"
	"context"
	"github.com/rbcervilla/datastore-transformer"
)

func main() {

	ctx := context.Background()
	cli, _ := datastore.NewClient(ctx, "project-id")

	tr, _ := transformer.New(cli, datastore.NewQuery("KindToTransform"))
	
	tr.Apply(
		transformer.RemoveField("OldField"),
		transformer.SetField("NewField", 1, true))

	tr.Do(ctx)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doer

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

Doer runs the query and sends to the workers the entities to transform and save.

func New

func New(cli *datastore.Client, query *datastore.Query, opts ...Option) (*Doer, error)

New creates a new transformer Doer

func (*Doer) Apply

func (d *Doer) Apply(t ...Transformer)

Apply adds Transformer to be applied to an Entity

func (*Doer) Do

func (d *Doer) Do(ctx context.Context) error

Do queries the entities and sends to the workers

func (*Doer) NotifyErr

func (d *Doer) NotifyErr() <-chan error

type Entity

type Entity struct {
	Properties map[string]datastore.Property
	// contains filtered or unexported fields
}

Entity contains key and properties of a datastore entity

Implements datastore.KeyLoader in order to Load and Save the entity.

func (*Entity) Load

func (e *Entity) Load(props []datastore.Property) error

func (*Entity) LoadKey

func (e *Entity) LoadKey(k *datastore.Key) error

func (*Entity) Save

func (e *Entity) Save() ([]datastore.Property, error)

type Option

type Option func(d *Doer) error

Option is a functional option for configuring the Doer

func WithConcurrency

func WithConcurrency(c int) Option

WithConcurrency function to set numer of workers running concurrently

func WithFailOnError

func WithFailOnError(v bool) Option

type Transformer

type Transformer interface {
	Transform(e *Entity) error
}

Transformer is the interface that wraps methos Transform

Transform performs transformations on the Entity

type TransformerFunc

type TransformerFunc func(e *Entity) error

TransformerFunc type is an adapter to allow the use of functions as Transformer

func RemoveField

func RemoveField(field string) TransformerFunc

RemoveField returns a TransformerFunc that remove field of the Entity

func SetField

func SetField(field string, value interface{}, index bool) TransformerFunc

SetField returns a TransformerFunc that sets a field to the Entity

func (TransformerFunc) Transform

func (f TransformerFunc) Transform(e *Entity) error

Jump to

Keyboard shortcuts

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