Skip to content

Commit

Permalink
add reference in d1
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Oct 22, 2024
1 parent 778057b commit 5a2eed2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/connections/sqlite/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ export class CloudflareD1Connection extends SqliteBaseConnection {
});
}

const columnConstraint = fkConstraintData.find(
(fk) => fk.from === column.name
);

const currentColumn: TableColumn = {
name: column.name,
position: column.cid,
Expand All @@ -259,6 +263,12 @@ export class CloudflareD1Connection extends SqliteBaseConnection {
default: column.dflt_value,
primaryKey: column.pk === 1,
unique: column.pk === 1,
references: columnConstraint
? {
column: [columnConstraint.to],
table: columnConstraint.table,
}
: undefined,
},
};

Expand Down
9 changes: 9 additions & 0 deletions tests/connections/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ afterAll(async () => {
await db.disconnect();
});

afterEach(async () => {
if (
['cloudflare', 'bigquery'].includes(process.env.CONNECTION_TYPE ?? '')
) {
// 3 seconds delay on each operation
await new Promise((r) => setTimeout(r, 3000));
}
});

function cleanup(data: Record<string, unknown>[]) {
// Remove some database specified fields
return data.map((d) => {
Expand Down

0 comments on commit 5a2eed2

Please sign in to comment.