generated from productdevbookcom/ts-bundle-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add playground drizzle example
- Loading branch information
1 parent
31ab604
commit 78b41d9
Showing
6 changed files
with
170 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { unSearch } from 'unsearch' | ||
import type { Column } from 'drizzle-orm' | ||
import { | ||
and, | ||
asc, | ||
desc, | ||
eq, | ||
gt, | ||
gte, | ||
ilike, | ||
like, | ||
lt, | ||
lte, | ||
ne, | ||
or, | ||
} from 'drizzle-orm' | ||
import { pgTable, serial, varchar } from 'drizzle-orm/pg-core' | ||
|
||
export const user = pgTable('user', { | ||
id: serial('id').primaryKey(), | ||
username: varchar('username').unique(), | ||
name: varchar('name'), | ||
email: varchar('email'), | ||
}) | ||
|
||
const columKeys = { | ||
username: user.username, | ||
email: user.email, | ||
id: user.id, | ||
name: user.name, | ||
} | ||
|
||
const scopeTags = { | ||
'=': (key: Column, value: string) => eq(key, value), | ||
'!=': (key: Column, value: string) => ne(key, value), | ||
'>': (key: Column, value: string) => gt(key, value), | ||
'>=': (key: Column, value: string) => gte(key, value), | ||
'<': (key: Column, value: string) => lt(key, value), | ||
'<=': (key: Column, value: string) => lte(key, value), | ||
'<like>': (key: Column, value: string) => like(key, `%${value}%`), | ||
'<ilike>': (key: Column, value: string) => ilike(key, `%${value}%`), | ||
'OR': (...args: any[]) => or(...args), | ||
'AND': (...args: any[]) => and(...args), | ||
'asc': (key: Column) => asc(key), | ||
'desc': (key: Column) => desc(key), | ||
} | ||
|
||
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, | ||
} | ||
}), | ||
}, | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
{ | ||
"name": "playground", | ||
"version": "1.0.0", | ||
"description": "", | ||
"author": "", | ||
"license": "ISC", | ||
"keywords": [], | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"devDependencies": { | ||
"ts-bundle-template": "workspace:^" | ||
"unsearch": "workspace:^" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.