Skip to content

Commit

Permalink
fix(core): solve TupleType when converting Powersync types
Browse files Browse the repository at this point in the history
  • Loading branch information
guillempuche committed Jun 18, 2024
1 parent 5dce1d5 commit 9cfad46
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/core/src/to_schema.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,22 @@ export function toPowerSyncColumnType(ast: AST.AST): ColumnType {
throw new Error(`Unsupported union of column types: ${types.join(', ')}`)
}
case 'TupleType': {
if (ast.elements.length === 0) {
// throw new Error('Empty tuple types are not supported')
const allTypes = [
...ast.elements.map(e => toPowerSyncColumnType(e.type)),
...ast.rest.map(a => toPowerSyncColumnType(a)),
]
if (allTypes.length === 0) {
throw new Error('Empty tuple types are not supported')
}
// Map each element's type and determine the column type accordingly
const elementTypes = ast.elements.map(e => toPowerSyncColumnType(e.type))
const uniqueTypes = Array.from(new Set(elementTypes))
const uniqueTypes = Array.from(new Set(allTypes))

if (uniqueTypes.length === 1) {
return uniqueTypes[0]
}

// throw new Error(
// `Unsupported tuple of mixed column types: ${uniqueTypes.join(', ')}`,
// )
return ColumnType.TEXT
throw new Error(
`Unsupported tuple of mixed column types: ${uniqueTypes.join(', ')}`,
)
}
default:
return unknownColumnTypeError(ast)
Expand Down

0 comments on commit 9cfad46

Please sign in to comment.