Example #1
0
func (driver *Sharded) Insert(params database.Params, analytic database.Analytic) error {
	// Construct DBPath
	dbPath := manager.DBPath{
		Name:      params.DBName,
		Directory: driver.directory,
	}

	// Push to right shard based on analytic time
	shardName := timeToShardName(analytic.Time)

	// Construct shard DBPath
	shardPath := manager.DBPath{
		Name:      shardName,
		Directory: dbPath.String(),
	}

	// Get DB from manager
	db, err := driver.DBManager.Acquire(shardPath)
	if err != nil {
		driver.DBManager.Logger.Error("Error executing Insert/Acquire on DB %s: %v\n", shardPath, err)
		return &errors.InternalError
	}
	defer driver.DBManager.Release(db)

	// Insert data if everything's OK
	err = query.Insert(db.DB, analytic)

	if err != nil {
		driver.DBManager.Logger.Error("Error executing Insert on DB %s: %v\n", shardPath, err)
		return &errors.InsertFailed
	}

	return nil
}
Example #2
0
func (driver *SQLite) Insert(params database.Params, analytic database.Analytic) error {
	// Construct DBPath
	dbPath := manager.DBPath{
		Name:      params.DBName,
		Directory: driver.directory,
	}

	// Get DB from manager
	db, err := driver.DBManager.Acquire(dbPath)
	if err != nil {
		return &errors.InternalError
	}
	defer driver.DBManager.Release(db)

	// Insert data if everything's OK
	err = query.Insert(db.DB, analytic)

	if err != nil {
		return &errors.InsertFailed
	}

	return nil
}