/
SqlModule.scala
67 lines (43 loc) · 1.92 KB
/
SqlModule.scala
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2016-2020 Association of Universities for Research in Astronomy, Inc. (AURA)
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause
package edu.gemini.grackle
package sql
import cats.{Monoid, Reducible}
/** These are the bits that are specific to the underlying database layer. */
trait SqlModule[F[_]] {
def monitor: SqlMonitor[F, Fragment]
/** The type of a codec that reads and writes column values of type `A`. */
type Codec
/** The type of an encoder that writes column values of type `A`. */
type Encoder
/** Extract an encoder from a codec. */
def toEncoder(c: Codec): Encoder
/** Typeclass for SQL fragments. */
trait SqlFragment[T] extends Monoid[T] {
def bind[A](encoder: Encoder, value: A): T
def const(s: String): T
/** Returns `(f1) AND (f2) AND ... (fn)` for all fragments. */
def and(fs: T*): T
/** Returns `(f1) AND (f2) AND ... (fn)` for all defined fragments. */
def andOpt(fs: Option[T]*): T
/** Returns `(f1) OR (f2) OR ... (fn)` for all defined fragments. */
def orOpt(fs: Option[T]*): T
/** Returns `WHERE (f1) AND (f2) AND ... (fn)` or the empty fragment if `fs` is empty. */
def whereAnd(fs: T*): T
/** Returns `WHERE (f1) AND (f2) AND ... (fn)` for defined `f`, if any, otherwise the empty fragment. */
def whereAndOpt(fs: Option[T]*): T
def in[G[_]: Reducible, A](f: T, fs: G[A], enc: Encoder): T
def parentheses(f: T): T
def needsCollation(codec: Codec): Boolean
def sqlTypeName(codec: Codec): Option[String]
}
/** The type of a fragment of SQL together with any interpolated arguments. */
type Fragment
implicit def Fragments: SqlFragment[Fragment]
def intEncoder: Encoder
def stringEncoder: Encoder
def booleanEncoder: Encoder
def doubleEncoder: Encoder
def intCodec: Codec
def fetch(fragment: Fragment, codecs: List[(Boolean, Codec)]): F[Vector[Array[Any]]]
}