All values of query result are of type string

I I use Drizzle as query builder

    let query = qb
        .select( {
            Time: sql<string>`${ schema.goals.time }`.as( 'Time' ),
            Period: sql<number>`${ schema.goals.period }`.as( 'Period' ),
            GoalType: sql<string>`${ schema.goals.goalType }`.as( 'GoalType' ),
            GameId: sql<number>`${ schema.goals.gameId }`.as( 'GameId' ),
            IsJunior: sql<boolean>`${ schema.leagues.isJunior }`.as( 'IsJunior' ),
            IsFemale: sql<boolean>`${ schema.leagues.isFemale }`.as( 'IsFemale' ),
            FieldSize: sql<string>`${ schema.leagues.fieldSize }`.as( 'FieldSize' ),
            LeagueId: sql<number>`${ schema.leagues.id }`.as( 'LeagueId' ),
        } )
        .from( schema.goals )
        .leftJoin( schema.games, eq( schema.goals.gameId, schema.games.id ) )
        .leftJoin( schema.leagues, eq( schema.leagues.id, schema.games.leagueId ) )

    const data = await fetchFromMyDb( query.$dynamic(), serverLoadEvent.fetch )
    const result = data as unknown as typeof data._.result

    // somehow IsFemale is string!?
    console.dir( result )
    console.log( result[ 0 ].IsFemale , typeof result[ 0 ].IsFemale )
    console.log( result[ 0 ].Period, typeof result[ 0 ].Period )


Output:
  {
    Time: '0:41',
    Period: '1',
    GoalType: 'regular',
    GameId: '35463',
    IsJunior: '0',
    IsFemale: '1',
    FieldSize: 'KF',
    LeagueId: '1541'
  }
]
1 string
1 string


The intellisense in VSCode shows me the correct types on hover (as specified in the sql template strings)

However the actual data in result is all string

I know it is a bit of a hacky solution, as I use Drizzle to generate a raw SQL query with typings applied later on.

Since there is currently no other way of getting the types otherwise () am I doing something wrong here that I do not get the types right
(anylinger - it seemed to work up until now or I haven't checked it thorough)
Was this page helpful?