Skip to content

Commit 4305e7e

Browse files
Merge pull request #19 from maxlshk/default
FIX 📍 "error: operator does not exist: json @> json"
2 parents e41146e + a50b54b commit 4305e7e

4 files changed

Lines changed: 21 additions & 132 deletions

File tree

package-lock.json

Lines changed: 1 addition & 128 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "finddevs",
33
"description": "Discover All Developers From The Programming World",
4-
"version": "0.1.6",
5-
"private": true,
4+
"version": "0.1.8",
5+
"private": false,
66
"scripts": {
77
"dev": "next dev",
88
"build": "next build",

src/components/contents/ProfileGrid.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import { db } from "@/database";
33
import { users } from "@/schemas";
44
import ProfileCard from "./ProfileCard";
55
import Paginations from "../pagination/Paginations";
6-
import { ilike, or, sql } from "drizzle-orm";
6+
import {
7+
ilike,
8+
or,
9+
sql,
10+
arrayContained,
11+
arrayContains,
12+
arrayOverlaps,
13+
} from "drizzle-orm";
714
import Notfound from "../shared/Notfound";
815
import Search from "../shared/search/Search";
916

@@ -16,6 +23,12 @@ const ProfileGrid = async ({ page, searchParams }: Props) => {
1623
const currentPage = parseInt(page); // like 1
1724
const itemPerPage = 5; // we want to show 5 item in per pages
1825
const offset = (currentPage - 1) * itemPerPage; // (1 - 1) * 3 = 0
26+
const searchSkills = searchParams ? searchParams.toLowerCase().split(/[\s,]+/) : []; // regular expression to accept inputs separated by comma, space or both
27+
28+
// In order to get rid of the "error: operator does not exist: json @> json" I mannually cast the skills column to JSONB
29+
const skillsCondition = searchSkills.length > 0
30+
? sql.raw(`lower("skills"::text)::JSONB @> '${JSON.stringify(searchSkills.map(skill => skill.toLowerCase()))}'::JSONB`)
31+
: undefined;
1932

2033
const [lengths, profiles] = await Promise.all([
2134
db.select({ count: sql<number>`count(*)` }).from(users),
@@ -27,6 +40,8 @@ const ProfileGrid = async ({ page, searchParams }: Props) => {
2740
or(
2841
ilike(users.name, `%${searchParams}%`),
2942
ilike(users.location, `%${searchParams}%`),
43+
ilike(users.description, `%${searchParams}%`),
44+
skillsCondition
3045
),
3146
)
3247
.limit(itemPerPage)
@@ -38,6 +53,7 @@ const ProfileGrid = async ({ page, searchParams }: Props) => {
3853
.limit(itemPerPage)
3954
.offset(offset),
4055
]);
56+
4157
const count = lengths[0].count;
4258
return (
4359
<div className="lg:mt-32 mt-[10rem] mb-8 border-t-orange-500 lg:ml-[20rem] px-4 lg:px-6 overflow-y-scroll relative">

src/components/forms/SearchProfiles.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const SearchProfiles = () => {
2929
type="text"
3030
value={queryString}
3131
className="text-lg p-6 text-gray-800 dark:text-white rounded-br-xl backdrop-blur-3xl bg-white/95 dark:bg-zinc-700 shadow-sm"
32-
placeholder="Search developer by name, and locations"
32+
placeholder="Search developer by name, skills or locations"
3333
/>
3434
<SearchIcon
3535
size={30}

0 commit comments

Comments
 (0)