Release v0.7.0 notes
February 19, 2023 by qbart ‐ 2 min read
Latest release adds additional functions to Krab’s built-in templating engine (provided by Go standard library). At this point there were only two functions
quote- for escaping valuesquote_indent- for escaping PostgreSQL identifiers
Use of such function can be demostrated with a simple action:
action "view" "refresh" {
arguments {
arg "name" {
description = "Materialized view to be refreshed"
}
}
sql = "REFRESH MATERIALIZED VIEW {{ .Args.name | quote_ident }}"
}
which allows to refresh materiazlied views from CLI by specifing name argument and propery escaping it in SQL:
krab action view refresh -name cached_animals
The newest version extends Krab’s template functions library with fake data generator, think of this as a fixture / faker. To provide this functionallity jaswdr/faker library is used. Currently supported generators are:
Address.CountryAddress.CountryCodeColor.NameColor.HexColor.RGBCompany.NameEmoji.EmojiEmoji.EmojiCodeFile.PathFile.ExtensionFile.FilenameWithExtensionFile.MimeTypeFood.FruitFood.VegetableHash.MD5Hash.SHA256Internet.DomainInternet.EmailInternet.Ipv4Internet.Ipv6Internet.MacAddressInternet.SafeEmailInternet.SlugInternet.URLInternet.UserAgentLorem.ParagraphLorem.WordPerson.FirstNamePerson.LastNamePerson.NameTime.ISO8601Time.Timezone
For implementation details see here. If you need more, you can open discussion about it.
Consider following action:
action "seed" "company" {
sql = <<-SQL
INSERT INTO companies (name) VALUES ({{ fake "Company.Name" | quote }})
SQL
}
All you need to do right now is to run the command:
krab action seed company
And that’s all. Fakes are still at early stage, when more features are added they will be integrated into more functionalities.
