-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package bob_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aldy505/bob" | ||
) | ||
|
||
// TODO - do more test | ||
|
||
func TestHas(t *testing.T) { | ||
t.Run("should be able to create a hasTable query", func(t *testing.T) { | ||
sql, args, err := bob.HasTable("users").ToSql() | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
result := "SELECT * FROM information_schema.tables WHERE table_name = ? AND table_schema = current_schema();" | ||
if sql != result { | ||
t.Fatal("sql is not equal with result:", sql) | ||
} | ||
|
||
if len(args) != 1 { | ||
t.Fatal("args is not equal with argsResult:", args) | ||
} | ||
}) | ||
|
||
t.Run("should be able to create a hasColumn query", func(t *testing.T) { | ||
sql, args, err := bob.HasTable("users").HasColumn("name").ToSql() | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
result := "SELECT * FROM information_schema.columns WHERE table_name = ? AND column_name = ? AND table_schema = current_schema();" | ||
if sql != result { | ||
t.Fatal("sql is not equal with result:", sql) | ||
} | ||
|
||
if len(args) != 2 { | ||
t.Fatal("args is not equal with argsResult:", args) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
package bob | ||
|
||
// TODO | ||
import "strings" | ||
|
||
const ( | ||
Question = "?" | ||
Dollar = "$" | ||
Colon = ":" | ||
AtP = "@p" | ||
) | ||
|
||
type PlaceholderFormat interface { | ||
ReplacePlaceholders(sql string) (string, error) | ||
} | ||
|
||
// TODO - test this one | ||
func ReplacePlaceholder(sql string, format string) string { | ||
if format == "" { | ||
format = Question | ||
} | ||
return strings.ReplaceAll(sql, "?", format) | ||
} |