@@ -12,20 +12,20 @@ import (
12
12
13
13
var _ repository.URL = (* URLSql )(nil )
14
14
15
- // URLSql accesses URL information in url table through SQL.
15
+ // URLSql accesses ShortLink information in short_link table through SQL.
16
16
type URLSql struct {
17
17
db * sql.DB
18
18
}
19
19
20
- // IsAliasExist checks whether a given alias exist in url table.
20
+ // IsAliasExist checks whether a given alias exist in short_link table.
21
21
func (u URLSql ) IsAliasExist (alias string ) (bool , error ) {
22
22
query := fmt .Sprintf (`
23
23
SELECT "%s"
24
24
FROM "%s"
25
25
WHERE "%s"=$1;` ,
26
- table .URL .ColumnAlias ,
27
- table .URL .TableName ,
28
- table .URL .ColumnAlias ,
26
+ table .ShortLink .ColumnAlias ,
27
+ table .ShortLink .TableName ,
28
+ table .ShortLink .ColumnAlias ,
29
29
)
30
30
31
31
err := u .db .QueryRow (query , alias ).Scan (& alias )
@@ -38,18 +38,18 @@ WHERE "%s"=$1;`,
38
38
return true , nil
39
39
}
40
40
41
- // Create inserts a new URL into url table.
41
+ // Create inserts a new ShortLink into short_link table.
42
42
// TODO(issue#698): change to CreateURL
43
43
func (u * URLSql ) Create (url entity.URL ) error {
44
44
statement := fmt .Sprintf (`
45
45
INSERT INTO "%s" ("%s","%s","%s","%s","%s")
46
46
VALUES ($1, $2, $3, $4, $5);` ,
47
- table .URL .TableName ,
48
- table .URL .ColumnAlias ,
49
- table .URL . ColumnOriginalURL ,
50
- table .URL .ColumnExpireAt ,
51
- table .URL .ColumnCreatedAt ,
52
- table .URL .ColumnUpdatedAt ,
47
+ table .ShortLink .TableName ,
48
+ table .ShortLink .ColumnAlias ,
49
+ table .ShortLink . ColumnLongLink ,
50
+ table .ShortLink .ColumnExpireAt ,
51
+ table .ShortLink .ColumnCreatedAt ,
52
+ table .ShortLink .ColumnUpdatedAt ,
53
53
)
54
54
_ , err := u .db .Exec (
55
55
statement ,
@@ -62,17 +62,17 @@ VALUES ($1, $2, $3, $4, $5);`,
62
62
return err
63
63
}
64
64
65
- // UpdateURL updates a URL that exists within the url table.
65
+ // UpdateURL updates a ShortLink that exists within the short_link table.
66
66
func (u * URLSql ) UpdateURL (oldAlias string , newURL entity.URL ) (entity.URL , error ) {
67
67
statement := fmt .Sprintf (`
68
68
UPDATE "%s"
69
69
SET "%s"=$1, "%s"=$2, "%s"=$3, "%s"=$4
70
70
WHERE "%s"=$5;` ,
71
- table .URL .TableName ,
72
- table .URL .ColumnAlias ,
73
- table .URL . ColumnOriginalURL ,
74
- table .URL .ColumnExpireAt ,
75
- table .URL .ColumnUpdatedAt ,
71
+ table .ShortLink .TableName ,
72
+ table .ShortLink .ColumnAlias ,
73
+ table .ShortLink . ColumnLongLink ,
74
+ table .ShortLink .ColumnExpireAt ,
75
+ table .ShortLink .ColumnUpdatedAt ,
76
76
oldAlias ,
77
77
)
78
78
@@ -92,19 +92,19 @@ WHERE "%s"=$5;`,
92
92
return newURL , nil
93
93
}
94
94
95
- // GetByAlias finds an URL in url table given alias.
95
+ // GetByAlias finds an ShortLink in short_link table given alias.
96
96
func (u URLSql ) GetByAlias (alias string ) (entity.URL , error ) {
97
97
statement := fmt .Sprintf (`
98
98
SELECT "%s","%s","%s","%s","%s"
99
99
FROM "%s"
100
100
WHERE "%s"=$1;` ,
101
- table .URL .ColumnAlias ,
102
- table .URL . ColumnOriginalURL ,
103
- table .URL .ColumnExpireAt ,
104
- table .URL .ColumnCreatedAt ,
105
- table .URL .ColumnUpdatedAt ,
106
- table .URL .TableName ,
107
- table .URL .ColumnAlias ,
101
+ table .ShortLink .ColumnAlias ,
102
+ table .ShortLink . ColumnLongLink ,
103
+ table .ShortLink .ColumnExpireAt ,
104
+ table .ShortLink .ColumnCreatedAt ,
105
+ table .ShortLink .ColumnUpdatedAt ,
106
+ table .ShortLink .TableName ,
107
+ table .ShortLink .ColumnAlias ,
108
108
)
109
109
110
110
row := u .db .QueryRow (statement , alias )
@@ -128,7 +128,7 @@ WHERE "%s"=$1;`,
128
128
return url , nil
129
129
}
130
130
131
- // GetByAliases finds URLs for a list of aliases
131
+ // GetByAliases finds ShortLinks for a list of aliases
132
132
func (u URLSql ) GetByAliases (aliases []string ) ([]entity.URL , error ) {
133
133
if len (aliases ) == 0 {
134
134
return []entity.URL {}, nil
@@ -149,13 +149,13 @@ func (u URLSql) GetByAliases(aliases []string) ([]entity.URL, error) {
149
149
SELECT "%s","%s","%s","%s","%s"
150
150
FROM "%s"
151
151
WHERE "%s" IN (%s);` ,
152
- table .URL .ColumnAlias ,
153
- table .URL . ColumnOriginalURL ,
154
- table .URL .ColumnExpireAt ,
155
- table .URL .ColumnCreatedAt ,
156
- table .URL .ColumnUpdatedAt ,
157
- table .URL .TableName ,
158
- table .URL .ColumnAlias ,
152
+ table .ShortLink .ColumnAlias ,
153
+ table .ShortLink . ColumnLongLink ,
154
+ table .ShortLink .ColumnExpireAt ,
155
+ table .ShortLink .ColumnCreatedAt ,
156
+ table .ShortLink .ColumnUpdatedAt ,
157
+ table .ShortLink .TableName ,
158
+ table .ShortLink .ColumnAlias ,
159
159
parameterStr ,
160
160
)
161
161
0 commit comments