aboutsummaryrefslogtreecommitdiff
path: root/lib/sql/client.go
AgeCommit message (Collapse)Author
8 dayslib/sql: add method Meta to ClientShulhan
The Meta method returns new instance of [Meta] based on the current client driver and kind arugment. While at it, update comments on most methods to use adjectives.
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2024-08-09lib/sql: replace [http.FileSystem] with [memfs.MemFS]Shulhan
Accepting the [http.FileSystem] means that the parameter can receive an instance of [embed.FS], but in most cases, it will fail. Case example, when we embed SQL files for migration under "db/migration" using the "go:embed" directive, //go:embed db/migration/*.sql var DBMigrationFS embed.FS and then call the [Migrate] function, it will not found any ".sql" files inside the "/" directory because the files is stored under "db/migration/" prefix (also there is no "/" when using embed.FS).
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2022-04-06all: replace any usage of ioutil package with os or ioShulhan
Since Go 1.16, the ioutil package has been deprecated. This changes replace any usage that use functions from ioutil package with their replacement from package os or package io.
2022-01-19lib/sql: make the table migration customizableShulhan
In the method Migrate() we add parameter "tableMigration" which define the name of table where the state of migration will be saved. If its empty default to "_migration".
2021-12-26lib/sql: make the TruncateTable run with cascade and restart identityShulhan
On table that contains foreign key, truncate without cascade may cause the method fail. Also, since TruncateTable is, and should be only, used on testing, any identity columns, for example serial, should be reset back to its initial value. On PostgreSQL this means the truncate table is with "RESTART IDENTITY".
2021-12-16lib/sql: check for EOF on loadSQLShulhan
There is probably a regression in Go that cause ioutil.ReadAll return io.EOF, while it should not, because the documentation said that A successful call returns err == nil, not err == EOF. But in this, using http.FileSystem, the ioutil.ReadAll now return EOF and we need to check it to make the migration can run without an error.
2021-08-17lib/sql: do not run migration if the last file not exist on the listShulhan
Previously, if the last migrated file name not found on the migration directory, we start executing migration start from the first file. This changes this behaviour to not run any migration at all. Since we cannot return it as an error, we only log it. In the future we may return it.
2021-04-27sql: make the column filename on table _migration as primary keyShulhan
This will allow deleting the record by filename instead of requiring all columns.
2021-01-08sql: check nil on Migrate parameter "fs" using reflect.IsNilShulhan
If we pass nil pointer of type to fs, the if condition will not true and this cause panic because fs is not nil.
2020-12-17sql: use the options MigrationDir if the argument fs is nilShulhan
If case the file-system argument is not provided, the function will assume that the migration script is stored in the MigrationDir which defined in ClientOptions.
2020-12-17sql: change the new client function parameter into struct of optionsShulhan
While at it, rename the function from "New" to "NewClient" for clarity.
2020-06-10all: update email addressShulhan
2020-05-16all: fix and suppress linter warningsShulhan
2020-05-06sql: add method to migrate database schemaShulhan
The Migrate method migrate the database using list of SQL files inside a directory. Each SQL file in directory will be executed in alphabetical order based on the last state. The state of migration will be saved in table "_migration" with the SQL file name that has been executed and the timestamp.
2020-02-13sql: a new package as an extension to "database/sql"Shulhan