@stravigor/banner 0.4.6 → 0.4.7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stravigor/banner",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "type": "module",
5
5
  "description": "Feature flags for the Strav framework",
6
6
  "license": "MIT",
@@ -65,7 +65,22 @@ export class DatabaseDriver implements FeatureStore {
65
65
  entries: Array<{ feature: string; scope: ScopeKey; value: unknown }>
66
66
  ): Promise<void> {
67
67
  if (entries.length === 0) return
68
- for (const e of entries) await this.set(e.feature, e.scope, e.value)
68
+ if (entries.length === 1) {
69
+ await this.set(entries[0].feature, entries[0].scope, entries[0].value)
70
+ return
71
+ }
72
+
73
+ await this.sql.begin(async tx => {
74
+ for (const e of entries) {
75
+ const jsonValue = JSON.stringify(e.value)
76
+ await tx`
77
+ INSERT INTO "_strav_features" ("feature", "scope", "value", "created_at", "updated_at")
78
+ VALUES (${e.feature}, ${e.scope}, ${jsonValue}::jsonb, NOW(), NOW())
79
+ ON CONFLICT ("feature", "scope")
80
+ DO UPDATE SET "value" = ${jsonValue}::jsonb, "updated_at" = NOW()
81
+ `
82
+ }
83
+ })
69
84
  }
70
85
 
71
86
  async forget(feature: string, scope: ScopeKey): Promise<void> {