kysley + sqlite how to handle "numeric" boolean types with anonymous plugin and additionalFields?

when using the anonymous plugin and specifying additional fields its unclear which data type to use for sqlite booleans.

  • sqlite stores booleans as ints (0, 1)
  • i set a default of 0
CREATE TABLE users (
    ...
    isAnonymous INTEGER NOT NULL DEFAULT 0, -- for anonymous users that havent authenticated yet
    emailVerified INTEGER NOT NULL DEFAULT 0, -- SQLite uses INTEGER for boolean: 0 = false, 1 = true
    ...
);

...

ALTER TABLE users ADD COLUMN hasCompletedOrder INTEGER NOT NULL DEFAULT 0;


kysely codegen generates the type Generated<number> (since it has a default value)

export interface Users {
  // these are all "integer" booleans with defaults
  emailVerified: Generated<number>;
  hasCompletedOrder: Generated<number>;
  isAnonymous: Generated<number>;
}


better auth needs a data type for the additional fields. im not sure which type to specify - boolean or number?

    user: {
      // using plural names in the DB
      modelName: 'users',
      additionalFields: {
        hasCompletedOrder: {
          type: 'number', // or boolean?
          defaultValue: 0, // or false?
          input: false,
        }
      }
    }
Was this page helpful?