drizzle-orm
drizzle-orm copied to clipboard
[BUG]: Can't access table config column index information
What version of drizzle-orm
are you using?
0.23.11
Describe the Bug
I'm writing a Drizzle adaptor for Tableland (https://tableland.xyz) and need to implement table creation myself because Tableland doesn't yet support migrations in the way drizzle-kit does them. Getting the table config using getTableConfig
has worked well and allows me to get the information I need to construct a create table...
statement, except for I can't seem to access information about the columns within indexes defined in the schema. If I write the following code:
const foo = sqliteTable(
"foo",
{
id: integer("id"),
},
(foo) => {
return {
idIndex: uniqueIndex("idUniqueIdx").on(foo.id),
};
}
);
const config = getTableConfig(foo);
const column = config.indexes[0].config.columns[0]
the column
value only has this _
property on it which is undefined
. I don't have access to any of the other properties of AnySQLiteColumn
like name
.
If I console.log(column)
, I see all that information:
<ref *1> SQLiteInteger {
table: SQLiteTable {
id: [Circular *1],
[Symbol(OriginalName)]: 'foo',
[Symbol(Name)]: 'foo',
[Symbol(Schema)]: undefined,
[Symbol(BaseName)]: 'foo',
[Symbol(InlineForeignKeys)]: [],
[Symbol(ExtraConfigBuilder)]: [Function (anonymous)],
[Symbol(Columns)]: { id: [Circular *1] }
},
config: {
name: 'id',
notNull: false,
default: undefined,
primaryKey: false,
autoIncrement: false
},
name: 'id',
notNull: false,
default: undefined,
hasDefault: undefined,
primary: false,
autoIncrement: false
}
Is there some way to get that information I'm not seeing? Thanks,
Oh interesting, this seems to work:
const column = config.indexes[0].config.columns[0] as any;
console.log(column.name);
Outputs id
.
So maybe this is just a typing issue?
If you check the column
type, you'll see that it is IndexColumn
, which is an alias for AnySQLiteColumn | SQL
. That's because you can make indexes on SQL expressions, not just columns. So you need something like column instanceof SQLiteColumn
.