Skip to content

Commit f484ce8

Browse files
feat: implement bigint support across various components and enhance payload handling
1 parent a6eb30d commit f484ce8

8 files changed

Lines changed: 84 additions & 14 deletions

File tree

src/lib/helpers/faker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ function generateSingleValue(field: Field): string | number | boolean | NestedNu
243243
return faker.number.int({ min, max });
244244
}
245245

246+
case 'bigint': {
247+
return faker.number.bigInt().toString();
248+
}
249+
246250
case 'double': {
247251
const floatAttr = field as Models.ColumnFloat;
248252
const min = isWithinSafeRange(floatAttr.min) ? floatAttr.min : 0;

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/+layout.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
import { addNotification } from '$lib/stores/notifications';
6565
import { hash } from '$lib/helpers/string';
6666
import { preferences } from '$lib/stores/preferences';
67-
import { buildRowUrl, isRelationship } from './rows/store';
67+
import { buildRowUrl, isRelationship, buildPayload } from './rows/store';
6868
import { chunks } from '$lib/helpers/array';
6969
import { Submit, trackEvent } from '$lib/actions/analytics';
7070
@@ -346,7 +346,7 @@
346346
databaseId: page.params.database,
347347
tableId: page.params.table,
348348
rowId: row.$id,
349-
data: row
349+
data: buildPayload(columns, row as Record<string, unknown>)
350350
})
351351
)
352352
);
@@ -358,7 +358,7 @@
358358
await tablesSDK.createRows({
359359
databaseId: page.params.database,
360360
tableId: page.params.table,
361-
rows
361+
rows: rows.map((row) => buildPayload(columns, row as Record<string, unknown>))
362362
});
363363
}
364364

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/bigint.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
import { page } from '$app/state';
33
import { sdk } from '$lib/stores/sdk';
44
import type { Models } from '@appwrite.io/console';
5+
6+
function normalizeBigInt(value) {
7+
if (value === undefined) return undefined;
8+
if (value === null) return null;
9+
return BigInt(value);
10+
}
511
612
export async function submitBigInt(
713
databaseId: string,
@@ -16,7 +22,7 @@
1622
required: data.required,
1723
min: data.min,
1824
max: data.max,
19-
xdefault: data.default,
25+
xdefault: normalizeBigInt(data.default),
2026
array: data.array
2127
});
2228
}
@@ -32,7 +38,7 @@
3238
tableId,
3339
key: originalKey,
3440
required: data.required,
35-
xdefault: data.default,
41+
xdefault: normalizeBigInt(data.default),
3642
min: data.min,
3743
max: data.max,
3844
newKey: data.key !== originalKey ? data.key : undefined

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/rows/create.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import { invalidate } from '$app/navigation';
1515
import { Dependencies } from '$lib/constants';
1616
import { tick } from 'svelte';
17-
import { isRelationship, isRelationshipToMany } from './store';
17+
import { isRelationship, isRelationshipToMany, buildPayload } from './store';
1818
import { hash } from '$lib/helpers/string';
1919
2020
type CreateRow = {
@@ -70,7 +70,7 @@
7070
function prepareRowPayload(createRowObject: CreateRow): object {
7171
const { row, columns } = createRowObject;
7272
73-
const payload = structuredClone(row);
73+
const payload = structuredClone(row) as Record<string, unknown>;
7474
7575
for (const column of columns) {
7676
if (isRelationship(column) && !isRelationshipToMany(column)) {
@@ -87,7 +87,7 @@
8787
}
8888
}
8989
90-
return payload;
90+
return buildPayload(columns, payload);
9191
}
9292
9393
async function create(): Promise<boolean> {

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/rows/edit.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
buildWildcardColumnsQuery,
1515
isRelationship,
1616
isRelationshipToMany,
17-
isSpatialType
17+
isSpatialType,
18+
buildPayload
1819
} from './store';
1920
import { Layout, Skeleton } from '@appwrite.io/pink-svelte';
2021
import { deepClone } from '$lib/helpers/object';
@@ -142,11 +143,13 @@
142143
if (!row || !work) return;
143144
144145
try {
146+
const payload = buildPayload(table.fields, $work as Record<string, unknown>);
147+
145148
await sdk.forProject(page.params.region, page.params.project).tablesDB.updateRow({
146149
databaseId: table.databaseId,
147150
tableId: table.$id,
148151
rowId: row.$id,
149-
data: $work,
152+
data: payload,
150153
permissions: $work.$permissions
151154
});
152155

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/rows/editRelated.svelte

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
import { invalidate } from '$app/navigation';
1111
import { type Columns, PROHIBITED_ROW_KEYS } from '../store';
1212
import ColumnItem from './columns/columnItem.svelte';
13-
import { buildWildcardColumnsQuery, isRelationship, isRelationshipToMany } from './store';
13+
import {
14+
buildWildcardColumnsQuery,
15+
isRelationship,
16+
isRelationshipToMany,
17+
buildPayload
18+
} from './store';
1419
import { Accordion, Layout, Skeleton } from '@appwrite.io/pink-svelte';
1520
import { deepClone } from '$lib/helpers/object';
1621
import { preferences } from '$lib/stores/preferences';
@@ -258,11 +263,15 @@
258263
const work = workData.get(rowId);
259264
260265
const workValue = get(work);
266+
const payload = buildPayload(
267+
relatedTable.fields,
268+
workValue as Record<string, unknown>
269+
);
261270
await sdk.forProject(page.params.region, page.params.project).tablesDB.updateRow({
262271
databaseId,
263272
tableId: relatedTable.$id,
264273
rowId: rowId,
265-
data: workValue,
274+
data: payload,
266275
permissions: workValue.$permissions
267276
});
268277
@@ -276,13 +285,17 @@
276285
if (!work) return;
277286
278287
const workValue = get(work);
288+
const payload = buildPayload(
289+
relatedTable.fields,
290+
workValue as Record<string, unknown>
291+
);
279292
return sdk
280293
.forProject(page.params.region, page.params.project)
281294
.tablesDB.updateRow({
282295
databaseId,
283296
tableId: relatedTable.$id,
284297
rowId: row.$id,
285-
data: workValue,
298+
data: payload,
286299
permissions: workValue.$permissions
287300
});
288301
});

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/rows/store.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,47 @@ export function isSpatialType(
5252
return spatialTypes.includes(field.type.toLowerCase());
5353
}
5454

55+
function castBigIntValue(value: unknown): unknown {
56+
if (value === null || value === undefined || value === '') {
57+
return value;
58+
}
59+
60+
if (typeof value === 'bigint') {
61+
return value;
62+
}
63+
64+
try {
65+
console.log({ value });
66+
return BigInt(value as string | number | boolean);
67+
} catch {
68+
return value;
69+
}
70+
}
71+
72+
export function buildPayload(
73+
fields: Field[] | undefined,
74+
row: Record<string, unknown>
75+
): Record<string, unknown> {
76+
const payload = structuredClone(row);
77+
78+
for (const field of fields ?? []) {
79+
if (field.type !== 'bigint') {
80+
continue;
81+
}
82+
83+
const value = payload[field.key];
84+
85+
if (field.array && Array.isArray(value)) {
86+
payload[field.key] = value.map((item) => castBigIntValue(item));
87+
continue;
88+
}
89+
90+
payload[field.key] = castBigIntValue(value);
91+
}
92+
93+
return payload;
94+
}
95+
5596
/**
5697
* Returns select queries for all main and related fields in an `Entity`.
5798
*/

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
buildWildcardColumnsQuery,
1818
isRelationship,
1919
isRelationshipToMany,
20+
buildPayload,
2021
isSpatialType,
2122
isTextType
2223
} from './rows/store';
@@ -645,11 +646,13 @@
645646
646647
async function updateRowContents(row: Models.Row) {
647648
try {
649+
const payload = buildPayload(table.fields, row as Record<string, unknown>);
650+
648651
await sdk.forProject(page.params.region, page.params.project).tablesDB.updateRow({
649652
databaseId,
650653
tableId: table.$id,
651654
rowId: row.$id,
652-
data: row,
655+
data: payload,
653656
permissions: row.$permissions
654657
});
655658

0 commit comments

Comments
 (0)