com.backnd.database 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -250,7 +250,7 @@ namespace BACKND.Database.Internal
250
250
  }
251
251
 
252
252
  /// <summary>
253
- /// SetClause 목록 기반 UPDATE 쿼리 생성 (Inc/Dec용)
253
+ /// SetClause 목록 기반 UPDATE 쿼리 생성 (Set/Inc/Dec용)
254
254
  /// </summary>
255
255
  public static string BuildUpdateQueryFromSetClauses(string tableName, List<SetClause> setClauses, string whereClause)
256
256
  {
@@ -258,8 +258,14 @@ namespace BACKND.Database.Internal
258
258
  throw new InvalidOperationException("No set clauses specified");
259
259
 
260
260
  var setStatements = setClauses.Select(clause =>
261
- $"{clause.ColumnName} = {clause.ColumnName} {clause.Operator} {ValueFormatter.FormatValueForQuery(clause.Value)}"
262
- );
261
+ {
262
+ var formattedValue = ValueFormatter.FormatValueForQuery(clause.Value);
263
+ // Operator가 null이면 직접 값 설정 (Set), 아니면 산술 연산 (Inc/Dec)
264
+ if (string.IsNullOrEmpty(clause.Operator))
265
+ return $"{clause.ColumnName} = {formattedValue}";
266
+ else
267
+ return $"{clause.ColumnName} = {clause.ColumnName} {clause.Operator} {formattedValue}";
268
+ });
263
269
 
264
270
  return $"UPDATE {tableName} SET {string.Join(", ", setStatements)} WHERE {whereClause}";
265
271
  }
@@ -12,11 +12,11 @@ namespace BACKND.Database.Network
12
12
  {
13
13
  public static class DatabaseExecutor
14
14
  {
15
- //private static readonly string SERVER_URL = "http://localhost:10002";
15
+ private static readonly string SERVER_URL = "http://localhost:10002";
16
16
  //private static readonly string SERVER_URL = "https://api.alpha.thebackend.io";
17
17
  //private static readonly string SERVER_URL = "https://api.beta.thebackend.io";
18
18
 
19
- private static readonly string SERVER_URL = "https://api.thebackend.io";
19
+ //private static readonly string SERVER_URL = "https://api.thebackend.io";
20
20
  private static readonly string ENDPOINT = "/v1/database/store";
21
21
  private static readonly int MAX_RETRIES = 3;
22
22
  private static readonly float RETRY_DELAY = 1.0f;
package/QueryBuilder.cs CHANGED
@@ -242,19 +242,32 @@ namespace BACKND.Database
242
242
  return this;
243
243
  }
244
244
 
245
+ public QueryBuilder<T> Set<TField>(Expression<Func<T, TField>> selector, TField value)
246
+ {
247
+ var columnName = GetColumnNameFromExpression(selector);
248
+ ValidateNoDuplicateSetClause(columnName);
249
+ setClauses.Add(new SetClause
250
+ {
251
+ ColumnName = columnName,
252
+ Operator = null,
253
+ Value = value
254
+ });
255
+ return this;
256
+ }
257
+
245
258
  private void ValidateNoDuplicateSetClause(string columnName)
246
259
  {
247
260
  if (setClauses.Any(c => c.ColumnName == columnName))
248
261
  throw new InvalidOperationException($"'{columnName}' is already being modified. Each field can only be modified once.");
249
262
  }
250
263
 
251
- public async BTask<MutationResult> Exec()
264
+ public async BTask<MutationResult> Update()
252
265
  {
253
266
  if (setClauses.Count == 0)
254
- throw new InvalidOperationException("No modifications specified. Use Inc() or Dec() before Exec()");
267
+ throw new InvalidOperationException("No modifications specified. Use Set(), Inc() or Dec() before Update()");
255
268
 
256
269
  if (whereConditions.Count == 0)
257
- throw new InvalidOperationException("Exec requires a Where() condition");
270
+ throw new InvalidOperationException("Update requires a Where() condition");
258
271
 
259
272
  var whereClause = BuildWhereClause();
260
273
  var query = BuildUpdateQueryFromSetClauses(whereClause);
@@ -276,8 +289,14 @@ namespace BACKND.Database
276
289
  private string BuildUpdateQueryFromSetClauses(string whereClause)
277
290
  {
278
291
  var setStatements = setClauses.Select(clause =>
279
- $"{clause.ColumnName} = {clause.ColumnName} {clause.Operator} {FormatValueForQuery(clause.Value)}"
280
- );
292
+ {
293
+ var formattedValue = FormatValueForQuery(clause.Value);
294
+ // Operator가 null이면 직접 값 설정 (Set), 아니면 산술 연산 (Inc/Dec)
295
+ if (string.IsNullOrEmpty(clause.Operator))
296
+ return $"{clause.ColumnName} = {formattedValue}";
297
+ else
298
+ return $"{clause.ColumnName} = {clause.ColumnName} {clause.Operator} {formattedValue}";
299
+ });
281
300
 
282
301
  return $"UPDATE {modelInstance.GetTableName()} SET {string.Join(", ", setStatements)} WHERE {whereClause}";
283
302
  }
@@ -37,7 +37,7 @@ namespace BACKND.Database
37
37
  return;
38
38
 
39
39
  if (whereConditions.Count == 0)
40
- throw new InvalidOperationException("Inc/Dec requires a WHERE clause");
40
+ throw new InvalidOperationException("Set/Inc/Dec requires a WHERE clause");
41
41
 
42
42
  var whereClause = SqlBuilder.BuildWhereClause(
43
43
  whereConditions,
@@ -108,6 +108,22 @@ namespace BACKND.Database
108
108
  return this;
109
109
  }
110
110
 
111
+ /// <summary>
112
+ /// 필드 값 직접 설정
113
+ /// </summary>
114
+ public TransactionQueryBuilder<T> Set<TField>(Expression<Func<T, TField>> selector, TField value)
115
+ {
116
+ var columnName = expressionAnalyzer.GetColumnNameFromKeySelector(selector);
117
+ ValidateNoDuplicateSetClause(columnName);
118
+ setClauses.Add(new SetClause
119
+ {
120
+ ColumnName = columnName,
121
+ Operator = null,
122
+ Value = value
123
+ });
124
+ return this;
125
+ }
126
+
111
127
  private void ValidateNoDuplicateSetClause(string columnName)
112
128
  {
113
129
  if (setClauses.Any(c => c.ColumnName == columnName))
@@ -161,6 +177,34 @@ namespace BACKND.Database
161
177
  return transaction;
162
178
  }
163
179
 
180
+ /// <summary>
181
+ /// Set/Inc/Dec로 지정한 필드만 UPDATE 작업 추가
182
+ /// </summary>
183
+ public TransactionBuilder Update()
184
+ {
185
+ if (setClauses.Count == 0)
186
+ throw new InvalidOperationException("No modifications specified. Use Set(), Inc() or Dec() before Update()");
187
+
188
+ if (whereConditions.Count == 0)
189
+ throw new InvalidOperationException("Update requires a WHERE clause");
190
+
191
+ var whereClause = SqlBuilder.BuildWhereClause(
192
+ whereConditions,
193
+ isOfCurrentUser,
194
+ modelInstance.GetTableType());
195
+ var sql = SqlBuilder.BuildUpdateQueryFromSetClauses(
196
+ modelInstance.GetTableName(),
197
+ setClauses,
198
+ whereClause);
199
+
200
+ transaction.AddStatement(sql);
201
+ setClauses.Clear();
202
+
203
+ // 활성 QueryBuilder 해제
204
+ transaction.activeQueryBuilder = null;
205
+ return transaction;
206
+ }
207
+
164
208
  /// <summary>
165
209
  /// DELETE 작업 추가
166
210
  /// </summary>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.backnd.database",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "displayName": "BACKND Database",
5
5
  "description": "BACKND Database is a Unity SDK for seamless integration with BACKND cloud database services.\n\nEasily manage and synchronize game data such as player profiles, game states, and leaderboards across multiple platforms.\nIdeal for Unity developers looking to implement robust database solutions without complex backend setups.",
6
6
  "unity": "2021.3",