Skip to content

Commit

Permalink
chore: add PostgreSQL dependency and implement search function
Browse files Browse the repository at this point in the history
  • Loading branch information
productdevbook committed Jan 30, 2024
1 parent dd51c89 commit cba08a0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"drizzle-orm": "^0.29.3",
"eslint": "^8.56.0",
"lint-staged": "^15.2.0",
"postgres": "^3.4.3",
"simple-git-hooks": "^2.9.0",
"tsup": "^8.0.1",
"typescript": "^5.3.3",
Expand Down
51 changes: 36 additions & 15 deletions playground/drizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {
or,
} from 'drizzle-orm'
import { pgTable, serial, varchar } from 'drizzle-orm/pg-core'
import postgres from 'postgres'
import { drizzle } from 'drizzle-orm/postgres-js'

const queryClient = postgres('postgres://postgres:[email protected]:5432/db')
const db = drizzle(queryClient)

export const user = pgTable('user', {
id: serial('id').primaryKey(),
Expand Down Expand Up @@ -47,18 +52,34 @@ const scopeTags = {

const scopeTagsArray = ['OR', 'AND', '<like>', '<ilike>', '>=', '<=', '>', '<', '!=', '=']

unSearch({
columKeys,
scopeTags,
scopeTagsArray,
search: 'username:admin AND',
default: {
filterText: Object.keys(columKeys).map((key) => {
return {
column: columKeys[key as keyof typeof columKeys],
filter: '<ilike>',
key,
}
}),
},
})
async function search(query: string) {
const { config } = await unSearch({
columKeys,
scopeTags,
scopeTagsArray,
search: query,
default: {
filterText: Object.keys(columKeys).map((key) => {
return {
column: columKeys[key as keyof typeof columKeys],
filter: '<ilike>',
key,
}
}),
},
})

const data = db.select().from(user)
.where(
or(
...config._data?.wheres || [],
),
)
.orderBy(
...config._data?.orderBy || [],
)

console.warn(data)
}

search('username:foo AND email:bar')
14 changes: 12 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cba08a0

Please sign in to comment.