Issue with json object prop query
This will work but I cant make the 'slug' dynamic
``ts
// This works
sqlcategories_subquery.categories::jsonb @> jsonb_build_array(jsonb_build_object('slug', ${filter.value}::text))`;...How do I order by average rating?
I have a table of facilities and reviews for facilities which I can join via the facilityTable.id = review.facilityId columns. I want to select the top ten according to average reviews. How can I do that? Here's what I have so far:
```ts
const facilities = await db
.select({...
How to type a generic selection function
I've been trying to implement a generic select function but can't figure out how to type it
Something like this:
```ts
async function select<T extends Something>(selectFields: T, limit: number): SomethingReturn> {...
Getting an object instead of an array.
im using Query syntax to get a an array of things based on a relations. the problem is one of the coloums is being sent like this which is wired.
` postsPicture: {
"0": {
postId: "352aaabb-8402-4771-829f-f68d563cf275",
url: "test",...
drizzle-kit generate doesn't run custom sql
In addition to my
schema.ts file to define tables, I also have functions_and_triggers.ts to create functions and triggers for Supabase
``
export const customAccessTokenHook = async () => {
await db.execute(sql
CREATE OR REPLACE FUNCTION public.custom_access_token_hook(event jsonb)...DrizzleORM with JSDoc (insert problem)
Hi, I am trying to use drizzle with jsdoc in my project. I created the schema and everything works when I run it but for some reason jsdoc in VSCode is complaining when I try to insert anything besides the fields that must be specified like primary keys and fields with
.notNull().unique(). Any ideas why this might happen?
Here is a part of my schema:
```js
// @ts-check...Is this a bug or I am just an idiot
So basically I have 3 tables named as chapter, volume and novel.
I was trying to get all the novels (which is 8 right now), and latest 5 chapters of these novels.
To achieve this I was trying to use subquery of volume and chapter combined and then giving them a row number.
Because volume and chapter both have a column name as number somehow it is causing issue 😕 .
...
Solution:
@Shashank Hi, I'm pretty sure the issue is to do with the chapter number and volume number, and the fix should be as simple as this:
...
chapterNumber: capterTable.number.getSQL().as('chapter_number'),
volumeNumber: volumeTable.number.getSQL().as('volume_number')
chapterNumber: capterTable.number.getSQL().as('chapter_number'),
volumeNumber: volumeTable.number.getSQL().as('volume_number')

DrizzleKit "tablesFilter" not working as expected
Hello! I am trying to use the "tablesFilter" feature in DrizzleKit, but I may be misunderstanding how it works? When I run "drizzle-kit push" with the following configuration it still tries to drop and/or reconcile tables that do not have the defined prefixes. I thought that it would create a sandbox in which it would not try to touch anything that does not match the filter? Am I doing it wrong?
```typescript
import { defineConfig } from 'drizzle-kit'
import { dbUrl } from './src/db-url'...
Aggregating the count of a relationship
Hi there,
In my data model I have "reflections" which are basically "posts" and I have "reactions".
One reflection can have many reactions by multiple users. Basically like a facebook post and the reactions would be the emoji reactions you can do.
This is my current query to get a paged list of reflections...
How do I use the with statement when inserting with select?
How can I get this insert built with drizzle?
Insert only has "values", and I am not sure how to construct this in drizzle
```sql...
old/stale data
Hi, I have built a full-stack billing software.
Now in my deployment, when my API calls drizzle queries, they sometimes get old data.
For example here I had 1
canteenBill. which I then deleted.
so doing this should give an empty array, which I do get....Introspection fails sonb_build_array(" is not valid JSON
I'm trying to switch from prisma to drizzle.
To begin, I've tried introspecting my database, but it fails with an error sonb_build_array(" is not valid JSON.
No logs either. Any idea what could be causing this
```...
invalid input either "url" or "host
1 it says i have to upgrade orm to latest even im up to date , it doesnt work and still says update orm
2 i saw a post go for 0.21.0 it worked so i did downgrade
3. it worked and can run db:studio and says Invalid input Please specify 'dialect' param in config, either of 'pg', 'mysql' or 'sqlite'
4 i put a dialect postgresql
5 it has 2 error one is driver and two is the url thingy...

Select All from Sub-query
Hi,
I'm trying to figure out if it's possible for me to select all the columns from a sub-query.
I imagine if it were possible it'd be something like this:...
Query based on nested relation
I need help modifying the query code to properly query the chat where it has the the two members.
```ts
export const findOrCreateChat = async (fromID: number, toID: number) => {
const existingchat = await db.query.chats.findFirst({
with: { members: true },...
Is it possible to create a query without having a (postgres) db instance?
I can do this:
``
const query = sqlSELECT ... FROM...`;
const db = drizzle(..., {schema});
db.execute(query);...Alias join doesn't seem to work
I have a simple alias:
```
const parent = aliasedTable(contact, "parent")
...
