func createDb(c *cli.Context) error { dbName := c.GlobalString("db") if dbName == "" { cli.ShowAppHelp(c) return nil } dbOptions := rdb.NewDefaultOptions() dbOptions.SetCreateIfMissing(true) defaultFlags.setOptions(dbOptions, c) db, err := rdb.OpenDb(dbOptions, dbName) if err != nil { log.Fatal(err) } defer db.Close() return nil }
func compactDb(c *cli.Context) error { dbName := c.GlobalString("db") if dbName == "" { cli.ShowAppHelp(c) return nil } dbOptions := rdb.NewDefaultOptions() dbOptions.SetCreateIfMissing(true) defaultFlags.setOptions(dbOptions, c) db, err := rdb.OpenDb(dbOptions, dbName) if err != nil { log.Fatal(err) } db.CompactRange(rdb.Range{}) db.Flush(rdb.NewDefaultFlushOptions()) fmt.Println(db.GetProperty("rocksdb.stats")) fmt.Println("done") return nil }