]> Git — Sourcephile - gargantext.git/blob - patches/opaleye/PR-563.patch
build: add nix flake support
[gargantext.git] / patches / opaleye / PR-563.patch
1 From a5693a2010e6d13f51cdc576fa1dc9985e79ee0e Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Przemys=C5=82aw=20Kaminski?= <pk@intrepidus.pl>
3 Date: Mon, 27 Feb 2023 06:17:12 +0100
4 Subject: [PATCH] [FTS] full text search implementation
5
6 ---
7 src/Opaleye/Internal/HaskellDB/PrimQuery.hs | 1 +
8 src/Opaleye/Internal/HaskellDB/Sql/Default.hs | 1 +
9 src/Opaleye/Internal/PGTypesExternal.hs | 14 ++++++++++++++
10 src/Opaleye/Operators.hs | 7 +++++++
11 src/Opaleye/SqlTypes.hs | 7 +++++++
12 5 files changed, 30 insertions(+)
13
14 diff --git a/src/Opaleye/Internal/HaskellDB/PrimQuery.hs b/src/Opaleye/Internal/HaskellDB/PrimQuery.hs
15 index e9d5c71c..2e85e2ba 100644
16 --- a/src/Opaleye/Internal/HaskellDB/PrimQuery.hs
17 +++ b/src/Opaleye/Internal/HaskellDB/PrimQuery.hs
18 @@ -64,6 +64,7 @@ data BinOp = (:==) | (:<) | (:<=) | (:>) | (:>=) | (:<>)
19 | (:->) | (:->>) | (:#>) | (:#>>)
20 | (:@>) | (:<@) | (:?) | (:?|) | (:?&)
21 | (:&&) | (:<<) | (:>>) | (:&<) | (:&>) | (:-|-)
22 + | (:@@)
23 deriving (Show,Read)
24
25 data UnOp = OpNot
26 diff --git a/src/Opaleye/Internal/HaskellDB/Sql/Default.hs b/src/Opaleye/Internal/HaskellDB/Sql/Default.hs
27 index 4fb964fd..9258d2db 100644
28 --- a/src/Opaleye/Internal/HaskellDB/Sql/Default.hs
29 +++ b/src/Opaleye/Internal/HaskellDB/Sql/Default.hs
30 @@ -205,6 +205,7 @@ showBinOp (:>>) = ">>"
31 showBinOp (:&<) = "&<"
32 showBinOp (:&>) = "&>"
33 showBinOp (:-|-) = "-|-"
34 +showBinOp (:@@) = "@@"
35
36 data UnOpType = UnOpFun | UnOpPrefix | UnOpPostfix
37
38 diff --git a/src/Opaleye/Internal/PGTypesExternal.hs b/src/Opaleye/Internal/PGTypesExternal.hs
39 index c8f18760..632980cc 100644
40 --- a/src/Opaleye/Internal/PGTypesExternal.hs
41 +++ b/src/Opaleye/Internal/PGTypesExternal.hs
42 @@ -182,6 +182,15 @@ pgRange pgEl start end =
43 oneEl R.NegInfinity = HPQ.NegInfinity
44 oneEl R.PosInfinity = HPQ.PosInfinity
45
46 +-- Full Text Search
47 +
48 +pgTSVector :: Field SqlText -> Field SqlTSVector
49 +pgTSVector (C.Column e) = C.Column (HPQ.FunExpr "tsvector" [e])
50 +
51 +pgTSQuery :: Field SqlText -> Field SqlTSQuery
52 +pgTSQuery (C.Column e) = C.Column (HPQ.FunExpr "tsquery" [e])
53 +
54 +
55 instance IsSqlType SqlBool where
56 showSqlType _ = "boolean"
57 instance IsSqlType SqlDate where
58 @@ -246,6 +255,9 @@ instance IsRangeType SqlTimestamptz where
59 instance IsRangeType SqlDate where
60 showRangeType _ = "daterange"
61
62 +instance IsSqlType SqlTSQuery where
63 + showSqlType _ = "tsquery"
64 +
65 -- * SQL datatypes
66
67 data SqlBool
68 @@ -287,6 +299,8 @@ data SqlBytea
69 data SqlJson
70 data SqlJsonb
71 data SqlRange a
72 +data SqlTSQuery
73 +data SqlTSVector
74
75 type PGBool = SqlBool
76 type PGDate = SqlDate
77 diff --git a/src/Opaleye/Operators.hs b/src/Opaleye/Operators.hs
78 index cee26942..892b2b18 100644
79 --- a/src/Opaleye/Operators.hs
80 +++ b/src/Opaleye/Operators.hs
81 @@ -39,6 +39,7 @@ module Opaleye.Operators
82 , (.<)
83 , (.<=)
84 , (.>=)
85 + , (@@)
86 -- * Numerical operators
87 , quot_
88 , rem_
89 @@ -212,6 +213,12 @@ infix 4 .>=
90 (.>=) :: Ord.SqlOrd a => Field a -> Field a -> F.Field T.SqlBool
91 (.>=) = C.binOp (HPQ.:>=)
92
93 +infix 4 @@
94 +(@@) :: Field T.SqlTSVector -> Field T.SqlTSQuery -> F.Field T.SqlBool
95 +(@@) = C.binOp (HPQ.:@@)
96 +
97 +-- * Numerical operators
98 +
99 -- | Integral division, named after 'Prelude.quot'. It maps to the
100 -- @/@ operator in Postgres.
101 quot_ :: C.SqlIntegral a => Field a -> Field a -> Field a
102 diff --git a/src/Opaleye/SqlTypes.hs b/src/Opaleye/SqlTypes.hs
103 index 1dc86ee2..196b12e5 100644
104 --- a/src/Opaleye/SqlTypes.hs
105 +++ b/src/Opaleye/SqlTypes.hs
106 @@ -90,6 +90,10 @@ module Opaleye.SqlTypes (
107 SqlBytea,
108 -- * @IsSqlType@
109 P.IsSqlType(P.showSqlType),
110 +
111 + P.SqlTSQuery,
112 + P.SqlTSVector,
113 + sqlTSQuery
114 ) where
115
116 import qualified Opaleye.Field as F
117 @@ -207,6 +211,9 @@ sqlLazyJSON = P.pgLazyJSON
118 sqlValueJSON :: Ae.ToJSON a => a -> F.Field SqlJson
119 sqlValueJSON = P.pgValueJSON
120
121 +sqlTSQuery :: String -> F.Field P.SqlTSQuery
122 +sqlTSQuery = P.pgTSQuery . sqlString
123 +
124 -- The jsonb data type was introduced in PostgreSQL version 9.4
125 -- JSONB values must be SQL string quoted
126 --