DT
Drizzle Team•15mo ago
Hortasha

Query issue - Syntax error at or near "$1"

Hello, I currently got this error recently: PostgresError: syntax error at or near "$1" This is the query i am trying to make. Note that this worked fine very recently.
const [ latestOppdatering, ] = await client.select()
.from( oppdateringTable )
.orderBy( desc( oppdateringTable.oppdateringsid ) )
.limit( 1 );
const [ latestOppdatering, ] = await client.select()
.from( oppdateringTable )
.orderBy( desc( oppdateringTable.oppdateringsid ) )
.limit( 1 );
If i use "toSQL()" in order to see what is being queried. I get the following:
{
sql: 'select from $1 order by $2 desc limit $3',
params: [
PgTable {
dato: [PgTimestamp],
endringstype: [PgText],
oppdateringsid: [PgInteger],
organisasjonsnummer: [PgText],
createdAt: [PgTimestamp],
updatedAt: [PgTimestamp],
[Symbol(IsAlias)]: false,
[Symbol(ExtraConfigBuilder)]: undefined,
[Symbol(IsDrizzleTable)]: true,
[Symbol(OriginalName)]: 'oppdatering',
[Symbol(Name)]: 'oppdatering',
[Symbol(Schema)]: 'brreg',
[Symbol(BaseName)]: 'oppdatering',
[Symbol(InlineForeignKeys)]: [],
[Symbol(Columns)]: [Object]
},
PgInteger {
table: [PgTable],
config: [Object],
name: 'oppdateringsid',
notNull: true,
default: undefined,
hasDefault: undefined,
primary: true
},
1
]
}
{
sql: 'select from $1 order by $2 desc limit $3',
params: [
PgTable {
dato: [PgTimestamp],
endringstype: [PgText],
oppdateringsid: [PgInteger],
organisasjonsnummer: [PgText],
createdAt: [PgTimestamp],
updatedAt: [PgTimestamp],
[Symbol(IsAlias)]: false,
[Symbol(ExtraConfigBuilder)]: undefined,
[Symbol(IsDrizzleTable)]: true,
[Symbol(OriginalName)]: 'oppdatering',
[Symbol(Name)]: 'oppdatering',
[Symbol(Schema)]: 'brreg',
[Symbol(BaseName)]: 'oppdatering',
[Symbol(InlineForeignKeys)]: [],
[Symbol(Columns)]: [Object]
},
PgInteger {
table: [PgTable],
config: [Object],
name: 'oppdateringsid',
notNull: true,
default: undefined,
hasDefault: undefined,
primary: true
},
1
]
}
I was expecting it to do 'select * from $1 order by $2 desc limit $3' Using 0.26.5 Trying to upgrade to 0:27 gives a bunch of type errors for some reason: Like: '[isDrizzleTable]' is missing in type 'pgTable<{name: "enhet"; schema: "brreg"; columns: { ... }; ...}>' Find that type error strange since i do not expect isDrizzleTable to be required in a schema i define? Anyone familiar with any of this, or what might be occuring here?
1 Reply
Hortasha
Hortasha•15mo ago
Currently retracing back to older versions of the repo / dependencies where it all worked. Update: Turns out to be a user issue like always. I happen to work in two different workspaces. Database workspace: Where i handle migrations and define my schemas Provider workspace: Where use the schemas in order to do operations towards the db. I happened to install drizzle-orm as dependency on both workspaces. But i should only use one instance of the drizzle-orm dependency. So when i foolishly saw the dependency was missing in the provider workspace and installed it. Breaking everything 😉 Maybe my mistakes is helpful to someone else in the future.
Want results from more Discord servers?
Add your server