|
1 |
| -extension PostgreSQLDatabase { |
2 |
| - public enum ColumnType { |
3 |
| - /// `BOOL`. |
4 |
| - public static var bool: String { |
5 |
| - return "BOOL" |
6 |
| - } |
7 |
| - |
8 |
| - /// `CHAR` |
9 |
| - public static var char: String { |
10 |
| - return "CHAR" |
11 |
| - } |
12 |
| - |
13 |
| - /// `VARCHAR` |
14 |
| - public static var varchar: String { |
15 |
| - return "VARCHAR" |
16 |
| - } |
17 |
| - |
18 |
| - /// `TEXT` |
19 |
| - public static var text: String { |
20 |
| - return "TEXT" |
21 |
| - } |
22 |
| - |
23 |
| - /// `SMALLINT` |
24 |
| - public static var smallint: String { |
25 |
| - return "SMALLINT" |
26 |
| - } |
27 |
| - |
28 |
| - /// `INT` |
29 |
| - public static var int: String { |
30 |
| - return "INT" |
31 |
| - } |
32 |
| - |
33 |
| - /// `BIGINT` |
34 |
| - public static var bigint: String { |
35 |
| - return "BIGINT" |
36 |
| - } |
37 |
| - |
38 |
| - /// `SMALLSERIAL` |
39 |
| - public static var smallserial: String { |
40 |
| - return "SMALL SERIAL" |
41 |
| - } |
42 |
| - |
43 |
| - /// `SERIAL` |
44 |
| - public static var serial: String { |
45 |
| - return "SERIAL" |
46 |
| - } |
47 |
| - |
48 |
| - /// `BIGSERIAL` |
49 |
| - public static var bigserial: String { |
50 |
| - return "BIGSERIAL" |
51 |
| - } |
52 |
| - |
53 |
| - /// `REAL` |
54 |
| - public static var real: String { |
55 |
| - return "REAL" |
56 |
| - } |
57 |
| - |
58 |
| - /// `DOUBLE PRECISION` |
59 |
| - public static var doublePrecision: String { |
60 |
| - return "DOUBLE PRECISION" |
61 |
| - } |
62 |
| - |
63 |
| - /// `DATE` |
64 |
| - public static var date: String { |
65 |
| - return "DATE" |
66 |
| - } |
67 |
| - |
68 |
| - /// `TIMESTAMP` |
69 |
| - public static var timestamp: String { |
70 |
| - return "TIMESTAMP" |
71 |
| - } |
72 |
| - |
73 |
| - /// `UUID` |
74 |
| - public static var uuid: String { |
75 |
| - return "UUID" |
76 |
| - } |
77 |
| - |
78 |
| - /// `POINT` |
79 |
| - public static var point: String { |
80 |
| - return "POINT" |
81 |
| - } |
82 |
| - |
83 |
| - /// `JSON` |
84 |
| - public static var json: String { |
85 |
| - return "JSON" |
86 |
| - } |
87 |
| - |
88 |
| - /// `JSONB` |
89 |
| - public static var jsonb: String { |
90 |
| - return "JSONB" |
91 |
| - } |
92 |
| - |
93 |
| - /// `BYTEA` |
94 |
| - public static var bytea: String { |
95 |
| - return "BYTEA" |
96 |
| - } |
| 1 | +public struct PostgreSQLColumnType { |
| 2 | + public var name: String |
| 3 | + public var parameters: [String] |
| 4 | + |
| 5 | + public init(_ name: String, _ parameters: String...) { |
| 6 | + self.name = name |
| 7 | + self.parameters = parameters |
| 8 | + } |
| 9 | + |
| 10 | + /// `BOOL`. |
| 11 | + public static var bool: PostgreSQLColumnType { |
| 12 | + return "BOOL" |
| 13 | + } |
| 14 | + |
| 15 | + /// `CHAR` |
| 16 | + public static var char: PostgreSQLColumnType { |
| 17 | + return "CHAR" |
| 18 | + } |
| 19 | + |
| 20 | + /// `VARCHAR(n)` |
| 21 | + public static func varchar(_ n: Int) -> PostgreSQLColumnType { |
| 22 | + return .init("VARCHAR", n.description) |
| 23 | + } |
| 24 | + |
| 25 | + /// `TEXT` |
| 26 | + public static var text: PostgreSQLColumnType { |
| 27 | + return "TEXT" |
| 28 | + } |
| 29 | + |
| 30 | + /// `SMALLINT` |
| 31 | + public static var smallint: PostgreSQLColumnType { |
| 32 | + return "SMALLINT" |
| 33 | + } |
| 34 | + |
| 35 | + /// `INT` |
| 36 | + public static var int: PostgreSQLColumnType { |
| 37 | + return "INT" |
| 38 | + } |
| 39 | + |
| 40 | + /// `BIGINT` |
| 41 | + public static var bigint: PostgreSQLColumnType { |
| 42 | + return "BIGINT" |
| 43 | + } |
| 44 | + |
| 45 | + /// `SMALLSERIAL` |
| 46 | + public static var smallserial: PostgreSQLColumnType { |
| 47 | + return "SMALL SERIAL" |
| 48 | + } |
| 49 | + |
| 50 | + /// `SERIAL` |
| 51 | + public static var serial: PostgreSQLColumnType { |
| 52 | + return "SERIAL" |
| 53 | + } |
| 54 | + |
| 55 | + /// `BIGSERIAL` |
| 56 | + public static var bigserial: PostgreSQLColumnType { |
| 57 | + return "BIGSERIAL" |
| 58 | + } |
| 59 | + |
| 60 | + /// `REAL` |
| 61 | + public static var real: PostgreSQLColumnType { |
| 62 | + return "REAL" |
| 63 | + } |
| 64 | + |
| 65 | + /// `DOUBLE PRECISION` |
| 66 | + public static var doublePrecision: PostgreSQLColumnType { |
| 67 | + return "DOUBLE PRECISION" |
| 68 | + } |
| 69 | + |
| 70 | + /// `DATE` |
| 71 | + public static var date: PostgreSQLColumnType { |
| 72 | + return "DATE" |
| 73 | + } |
| 74 | + |
| 75 | + /// `TIMESTAMP` |
| 76 | + public static var timestamp: PostgreSQLColumnType { |
| 77 | + return "TIMESTAMP" |
| 78 | + } |
| 79 | + |
| 80 | + /// `UUID` |
| 81 | + public static var uuid: PostgreSQLColumnType { |
| 82 | + return "UUID" |
| 83 | + } |
| 84 | + |
| 85 | + /// `POINT` |
| 86 | + public static var point: PostgreSQLColumnType { |
| 87 | + return "POINT" |
| 88 | + } |
| 89 | + |
| 90 | + /// `JSON` |
| 91 | + public static var json: PostgreSQLColumnType { |
| 92 | + return "JSON" |
| 93 | + } |
| 94 | + |
| 95 | + /// `JSONB` |
| 96 | + public static var jsonb: PostgreSQLColumnType { |
| 97 | + return "JSONB" |
| 98 | + } |
| 99 | + |
| 100 | + /// `BYTEA` |
| 101 | + public static var bytea: PostgreSQLColumnType { |
| 102 | + return "BYTEA" |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +extension PostgreSQLColumnType: ExpressibleByStringLiteral { |
| 107 | + /// See `ExpressibleByStringLiteral`. |
| 108 | + public init(stringLiteral value: String) { |
| 109 | + self.init(value) |
97 | 110 | }
|
98 | 111 | }
|
0 commit comments