arangodb

package
v0.0.0-...-f29e771 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ArangodbCmd = &cobra.Command{
	Use:   "arangodb",
	Short: "subcommand for arangodb database management",
}

ArangodbCmd is the subcommand for managing arangodb database

View Source
var DeleteCmd = &cobra.Command{
	Use:   "delete",
	Short: "delete all data from all the collections",
	Args:  cobra.NoArgs,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		tls, _ := cmd.Flags().GetBool("is-secure")
		session, db, err := arangomanager.NewSessionDb(
			&arangomanager.ConnectParams{
				User:     viper.GetString("arangodb-user"),
				Pass:     viper.GetString("arangodb-pass"),
				Database: viper.GetString("database"),
				Host:     viper.GetString("arangodb-host"),
				Port:     viper.GetInt("arangodb-port"),
				Istls:    tls,
			},
		)
		if err != nil {
			return fmt.Errorf("error in connecting to database %s", err)
		}
		registry.SetArangoSession(session)
		registry.SetArangodbConnection(db)
		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		db := registry.GetArangodbConnection()
		colls, err := db.Handler().Collections(context.Background())
		if err != nil {
			return fmt.Errorf(
				"error in retrieving collections for database %s %s",
				viper.GetString("database"),
				err,
			)
		}
		logger := registry.GetLogger()
		var names []string
		for _, c := range colls {
			props, err := c.Properties(context.Background())
			if err != nil {
				return fmt.Errorf(
					"error in retrieving properties of collection %s %s",
					c.Name(), err,
				)
			}
			if props.IsSystem {
				continue
			}
			names = append(names, c.Name())
		}
		logger.Debugf("received %s collections for deletion", strings.Join(names, " "))
		if len(viper.GetStringSlice("exclude")) > 0 {
			logger.Debugf(
				"excluding the %s collections",
				strings.Join(viper.GetStringSlice("exclude"), ""),
			)
			names = collection.Remove(names, viper.GetStringSlice("exclude")...)
		}
		logger.Debugf("going to delete %s collections", strings.Join(names, " "))
		err = db.Truncate(names...)
		if err != nil {
			return err
		}
		logger.Infof("deleted %s collections", strings.Join(names, " "))
		return nil
	},
}

DeleteCmd deletes all data from the given collections

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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