-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlSearchBar
51 lines (41 loc) · 1.23 KB
/
sqlSearchBar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
=== model ===
const findWineMatch = ({name}) => {
return dataBase.query(`SELECT * FROM Wines w INNER JOIN WinePairings wp ON w.id = wp.WineId INNER JOIN Dishes d on wp.DisheId = d.id WHERE w.name LIKE ?`, [`%${name}%`]);
};
=== router ===
cellarRouter.get('/search', async (req, res) => {
const [name] = await match.findWineMatch(req.query);
return res.json(name);
});
=== vue ===
components:
SearBar =>
<form action="/" method="get" onSubmit={onSubmit}>
<label htmlFor="header-search">
<span className="visually-hidden">Search blog posts</span>
</label>
<input
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
type="text"
id="header-search"
placeholder="Search wine matches"
/>
<button type="submit">Search</button>
</form>
=================
<Search
onSubmit={(e) => handleSubmit(e)}
searchQuery={searchQuery}
setSearchQuery={setSearchQuery}
/>
<span>
{searchQuery &&
wineMatch.map((match) => (
<WinePairing
image={match.image}
name={match.name}
type={match.type}
/>
))}
</span>