Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Can't access table config column index information #451

Closed
asutula opened this issue Apr 14, 2023 · 2 comments
Closed

[BUG]: Can't access table config column index information #451

asutula opened this issue Apr 14, 2023 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@asutula
Copy link

asutula commented Apr 14, 2023

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,

@asutula asutula added the bug Something isn't working label Apr 14, 2023
@asutula
Copy link
Author

asutula commented Apr 14, 2023

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?

@asutula asutula changed the title [BUG]: Can't access table config index column information [BUG]: Can't access table config column index information Apr 17, 2023
@dankochetov
Copy link
Contributor

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.

@dankochetov dankochetov self-assigned this Apr 19, 2023
@dankochetov dankochetov added question Further information is requested and removed bug Something isn't working labels Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants