From 3b322f3cb64f4ddbca5a7c294e1eba7ca443c2f7 Mon Sep 17 00:00:00 2001 From: Ash Logan Date: Tue, 7 May 2024 14:12:22 +1000 Subject: [PATCH] feat(datastore): Implement UpdateObjectPeriod(...) --- datastore/puyo_datastore.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/datastore/puyo_datastore.go b/datastore/puyo_datastore.go index 072e0b8..574550f 100644 --- a/datastore/puyo_datastore.go +++ b/datastore/puyo_datastore.go @@ -15,6 +15,7 @@ var selectByDataIdStmt *sql.Stmt var selectByNameAndOwnerStmt *sql.Stmt var insertObjectStmt *sql.Stmt var updateMetaBinaryStmt *sql.Stmt +var updatePeriodStmt *sql.Stmt // === GETTERS === @@ -159,14 +160,8 @@ func InitializeObjectRatingWithSlot(_ uint64, _ *types.DataStoreRatingInitParamW // === UPDATERS === -// Parts of ChangeMeta -func UpdateObjectPeriodByDataIDWithPassword(_ *nextypes.PrimitiveU64, _ *nextypes.PrimitiveU16, _ *nextypes.PrimitiveU64) *nex.Error { - return nex.NewError(nex.ResultCodes.Core.NotImplemented, "UpdateObjectPeriodByDataIDWithPassword unimplemented") -} - -// Parts of ChangeMeta -func UpdateObjectMetaBinaryByDataIDWithPassword(dataID *nextypes.PrimitiveU64, metaBinary *nextypes.QBuffer, _ *nextypes.PrimitiveU64) *nex.Error { - result, err := updateMetaBinaryStmt.Exec(metaBinary.Value, dataID.Value) +func updateObjects(stmt *sql.Stmt, args ...any) *nex.Error { + result, err := stmt.Exec(args...) if err != nil { return nex.NewError(nex.ResultCodes.DataStore.SystemFileError, err.Error()) } @@ -181,6 +176,16 @@ func UpdateObjectMetaBinaryByDataIDWithPassword(dataID *nextypes.PrimitiveU64, m return nil } +// Parts of ChangeMeta +func UpdateObjectPeriodByDataIDWithPassword(dataID *nextypes.PrimitiveU64, period *nextypes.PrimitiveU16, _ *nextypes.PrimitiveU64) *nex.Error { + return updateObjects(updatePeriodStmt, period.Value, dataID.Value) +} + +// Parts of ChangeMeta +func UpdateObjectMetaBinaryByDataIDWithPassword(dataID *nextypes.PrimitiveU64, metaBinary *nextypes.QBuffer, _ *nextypes.PrimitiveU64) *nex.Error { + return updateObjects(updateMetaBinaryStmt, metaBinary.Value, dataID.Value) +} + // Parts of ChangeMeta func UpdateObjectDataTypeByDataIDWithPassword(_ *nextypes.PrimitiveU64, _ *nextypes.PrimitiveU16, _ *nextypes.PrimitiveU64) *nex.Error { return nex.NewError(nex.ResultCodes.Core.NotImplemented, "UpdateObjectDataTypeByDataIDWithPassword unimplemented") @@ -255,6 +260,12 @@ func initDatastore() { panic(err) } updateMetaBinaryStmt = stmt + + stmt, err = Postgres.Prepare(`UPDATE datastore.objects SET period = $1 WHERE data_id = $2`) + if err != nil { + panic(err) + } + updatePeriodStmt = stmt } // Helpers for nex types