diff options
author | rtz12 <koenig@fagott.pw> | 2016-11-15 17:29:02 (UTC) |
---|---|---|
committer | rtz12 <koenig@fagott.pw> | 2016-11-15 17:29:02 (UTC) |
commit | 0ad174d7329e02b3f644614de0758789bb3677d4 (patch) | |
tree | e49a659c0b89bdec07cde778850b7fe002ac27ea /util/postgres.go | |
parent | e02ad854383265db216ed92b10c4f12408999d6a (diff) |
Verrückter Anilist Import
Bestes Feature 2k16.
Hashtag Make Grilist Great Again.
Diffstat (limited to 'util/postgres.go')
-rw-r--r-- | util/postgres.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/util/postgres.go b/util/postgres.go new file mode 100644 index 0000000..a108446 --- /dev/null +++ b/util/postgres.go | |||
@@ -0,0 +1,31 @@ | |||
1 | package util | ||
2 | |||
3 | import ( | ||
4 | "regexp" | ||
5 | "strings" | ||
6 | ) | ||
7 | |||
8 | var ( | ||
9 | pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`) | ||
10 | pgValueIdx int | ||
11 | ) | ||
12 | |||
13 | func init() { | ||
14 | for i, subexp := range pgArrayReg.SubexpNames() { | ||
15 | if subexp == "value" { | ||
16 | pgValueIdx = i | ||
17 | break | ||
18 | } | ||
19 | } | ||
20 | } | ||
21 | |||
22 | func PGArray(array []byte) []string { | ||
23 | var results []string | ||
24 | matches := pgArrayReg.FindAllStringSubmatch(string(array), -1) | ||
25 | for _, match := range matches { | ||
26 | s := match[pgValueIdx] | ||
27 | s = strings.Trim(s, "\"") | ||
28 | results = append(results, s) | ||
29 | } | ||
30 | return results | ||
31 | } | ||