Skip to content

Commit

Permalink
chore: add playground drizzle example
Browse files Browse the repository at this point in the history
  • Loading branch information
productdevbook committed Jan 30, 2024
1 parent 31ab604 commit 78b41d9
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 38 deletions.
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# Typescript Bundle Template
# unsearch

![Typescript Bundle Template](https://github.com/productdevbookcom/assets/blob/main/ts-bundle-template.jpg?raw=true)

This is a template for creating a Typescript bundle. It is based on the [Typescript](https://www.typescriptlang.org/) compiler with the [Tsup](https://github.com/egoist/tsup) bundler.
unsearch is a simple library designed to add flexible search functionality to your own APIs and databases.

## Features

- [x] [Typescript](https://www.typescriptlang.org/)
- [x] [Tsup](https://github.com/egoist/tsup)
- [x] [ESLint](https://eslint.org/) with [Antfu's ESLint Config](https://github.com/antfu/eslint-config)
- [x] [Bumpp](https://github.com/antfu/bumpp) github changelog generator
- [x] [Vitest](https://vitest.dev/)
- [x] [Pnpm](https://pnpm.io/)
- [x] [GitHub Actions]()
- [x] [NPM Local Registry]()
- [x] [Renovate]()

## Usage
- Pluggable architecture ([andScope, orScope, sortScope, limitScope, offsetScope])
- key:value scope search
- asc:key or desc:key sort search
- limit:count limit search (soon)
- offset:count offset search (soon)
- key:value OR key:value orScope search
- key:value AND key:value andScope search

## Installation

```bash
pnpm add unsearch
```

## Development

1. To use this template, click the "Use this template" button above.
2. Clone the repository to your local machine.
Expand Down
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
{
"name": "ts-bundle-template",
"name": "unsearch",
"type": "module",
"version": "0.0.0",
"packageManager": "pnpm@8.10.0",
"description": "add description",
"author": "add author",
"description": "Unsearch smart key:value scope all database search. Compatible with any database.",
"author": "Mehmet - productdevbook <hi@productdevbook.com>",
"license": "MIT",
"funding": "https://github.com/sponsors/productdevbook",
"homepage": "https://github.com/productdevbookcom/ts-bundle-template",
"homepage": "https://github.com/productdevbook/unsearch",
"repository": {
"type": "git",
"url": "https://github.com/productdevbookcom/ts-bundle-template.git"
"url": "https://github.com/productdevbook/unsearch.git"
},
"bugs": "https://github.com/productdevbookcom/ts-bundle-template/issues",
"bugs": "https://github.com/productdevbook/unsearch/issues",
"keywords": [
"add keywords"
"github search syntax",
"stackoverflow search syntax",
"key value search",
"global search",
"drizzle search"
],
"exports": {
".": {
Expand Down Expand Up @@ -47,6 +51,7 @@
"@antfu/eslint-config": "2.6.3",
"@vitest/coverage-v8": "^1.2.2",
"bumpp": "^9.3.0",
"drizzle-orm": "^0.29.3",
"eslint": "^8.56.0",
"lint-staged": "^15.2.0",
"simple-git-hooks": "^2.9.0",
Expand Down
64 changes: 64 additions & 0 deletions playground/drizzle.ts
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,
}
}),
},
})
6 changes: 0 additions & 6 deletions playground/index.ts

This file was deleted.

10 changes: 1 addition & 9 deletions playground/package.json
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:^"
}
}
77 changes: 76 additions & 1 deletion pnpm-lock.yaml

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

0 comments on commit 78b41d9

Please sign in to comment.