• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

snowplow / sql-runner / 15063404311

16 May 2025 07:46AM UTC coverage: 27.73% (+1.0%) from 26.721%
15063404311

push

github

jbeemster
Prepared for release

353 of 1273 relevant lines covered (27.73%)

2.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/sql_runner/sql_provider.go
1
// Copyright (c) 2015-2025 Snowplow Analytics Ltd. All rights reserved.
2
//
3
// This program is licensed to you under the Apache License Version 2.0,
4
// and you may not use this file except in compliance with the Apache License Version 2.0.
5
// You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
6
//
7
// Unless required by applicable law or agreed to in writing,
8
// software distributed under the Apache License Version 2.0 is distributed on an
9
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
// See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
11
package main
12

13
import (
14
        "io/ioutil"
15
        "path"
16
)
17

18
// SQLProvider is the interface that wraps the ResolveKey and GetSQL methods.
19
type SQLProvider interface {
20
        ResolveKey(key string) string
21
        GetSQL(key string) (string, error)
22
}
23

24
// FileSQLProvider represents a file as a SQL provider.
25
type FileSQLProvider struct {
26
        rootPath string
27
}
28

29
// NewFileSQLProvider returns a ptr to a FileSQLProvider.
30
func NewFileSQLProvider(rootPath string) *FileSQLProvider {
×
31
        return &FileSQLProvider{
×
32
                rootPath: rootPath,
×
33
        }
×
34
}
×
35

36
// GetSQL implements SQLProvider.
37
func (p FileSQLProvider) GetSQL(scriptPath string) (string, error) {
×
38
        return readScript(p.ResolveKey(scriptPath))
×
39
}
×
40

41
// ResolveKey implements SQLProvider.
42
func (p FileSQLProvider) ResolveKey(scriptPath string) string {
×
43
        return path.Join(p.rootPath, scriptPath)
×
44
}
×
45

46
// Reads the file ready for executing
47
func readScript(file string) (string, error) {
×
48
        scriptBytes, err := ioutil.ReadFile(file)
×
49
        if err != nil {
×
50
                return "", err
×
51
        }
×
52
        return string(scriptBytes), nil
×
53
}
54

55
// ConsulSQLProvider represents Consul as a SQL provider.
56
type ConsulSQLProvider struct {
57
        consulAddress string
58
        keyPrefix     string
59
}
60

61
// NewConsulSQLProvider returns a pts to a ConsulSQLProvider.
62
func NewConsulSQLProvider(consulAddress, keyPrefix string) *ConsulSQLProvider {
×
63
        return &ConsulSQLProvider{
×
64
                consulAddress: consulAddress,
×
65
                keyPrefix:     keyPrefix,
×
66
        }
×
67
}
×
68

69
// GetSQL implements SQLProcider.
70
func (p ConsulSQLProvider) GetSQL(key string) (string, error) {
×
71
        return GetStringValueFromConsul(p.consulAddress, p.ResolveKey(key))
×
72
}
×
73

74
// ResolveKey implements SQLProvider.
75
func (p ConsulSQLProvider) ResolveKey(key string) string {
×
76
        return path.Join(p.keyPrefix, key)
×
77
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc