Commit Graph

61 Commits (b5f2deac0271c4c258f1895c0c465a76d8f7ba88)

Author SHA1 Message Date
Vinícius Garcia b5f2deac02 Add a few more tests to Transaction 2022-08-03 20:11:05 -03:00
Vinícius Garcia 84d523967b Improve godoc for Transaction method 2022-08-01 09:35:12 -03:00
Vinícius Garcia 752e6bb0a1 Add some tests for the Patch function with composite keys 2022-07-25 23:47:06 -03:00
Vinícius Garcia 0425eb1123 Add test for Patch with composite keys 2022-07-25 22:49:51 -03:00
Matheus de Oliveira db86670b6c Use sync.Map on global caches to avoid race-condition
As known, a map can't be accessed with read/write concurrently on
multiple goroutines. This just replaces all uses of global maps for
caches with sync.Map, which is safe to be used concurrently.
2022-07-04 17:28:27 -03:00
Vinícius Garcia cf93f7441a Update README by moving some specialized sections to the Wiki 2022-07-03 23:43:58 -03:00
Vinícius Garcia ed0327babe Very minor refactor for removing the use of init() 2022-05-18 17:07:05 -03:00
Vinícius Garcia 9792e11b16 Minor improvement on ksql.go 2022-05-11 17:13:45 -03:00
Vinícius Garcia e5d1de061b Since golint is deprecated we upgraded to staticheck instead 2022-04-20 15:37:26 -03:00
Vinícius Garcia 1eca192677 Fix linter complaints 2022-04-19 17:46:09 -03:00
Lonre Wang 01ce253442 Implements `io.Closer` for `DB`
Fix #18
2022-04-19 01:36:02 +08:00
Vinícius Garcia d229767d98 Add tls.Config to ksql.Config 2022-04-03 21:28:49 -03:00
Vinícius Garcia e920ef6216 Refactor adapter tests to a separated file 2022-02-26 11:52:44 -03:00
Vinícius Garcia 06b871a418 Deprecate kstructs in favor of ksqltest 2022-02-22 22:41:15 -03:00
Vinícius Garcia 2e1aa80770 Breaking Change: changes the Exec() signature so it returns an extra value
The signature was updated from

- `Exec(...) (rowsAffected int64, _ error)`

To:

- `Exec(...) (ksql.Result, error)`

Result is an interface, so it should be easy to mock, we are also
providing a new builtin mock struct + constructor to make it even easier:

Building new mock Result: `ksql.NewMockResult(lastInsertID int64, rowsAffected int64) Result`
2022-02-22 16:49:48 -03:00
Vinícius Garcia 7a57e38228 Deprecate Update() in favor of a better fn name: Patch() 2022-02-22 16:14:15 -03:00
Vinícius Garcia eb030b1d76 Refactor TestQuery() to use the `tt` package 2022-02-19 02:51:07 -03:00
Vinícius Garcia b1737c8c30 Refactor TestQueryOne to use the `tt` package 2022-02-19 02:30:06 -03:00
Vinícius Garcia 3e275804d0 Add a few more tests and error checks to Delete() 2022-02-12 11:50:32 -03:00
Vinícius Garcia a37b8382ee Refactor Delete() so the code is even simpler 2022-02-12 10:09:38 -03:00
Vinícius Garcia 07c6065a5b Add tests and simplify the Delete function with composite keys 2022-02-11 23:59:29 -03:00
Vinícius Garcia d1e97489ef Add some tests for invalid tables passed to Delete() 2022-02-11 17:30:42 -03:00
Vinícius Garcia 49f872fb84 Add more tests for inserting in tables with composite keys 2022-02-11 17:23:47 -03:00
Vinícius Garcia a394fd0815 Move some functions to the internal package 2022-01-11 19:00:22 -03:00
Vinícius Garcia 3102a3d4c4 Add tests to ParseInputFunc and move it to internal/ 2022-01-10 21:02:39 -03:00
Vinícius Garcia 6f2ecbef5a Write tests for two trivial functions for raising the test coverage 2021-12-28 22:09:28 -03:00
Vinícius Garcia 1e282717b7 Remove deprecated constructors ksql.New() and ksql.NewWithPgx()
It's recommended to use instead one of:

- kpgx.New(ctx, connURL, ksql.Config{})
- kmysql.New(ctx, connURL, ksql.Config{})
- ksqlserver.New(ctx, connURL, ksql.Config{})
- ksqlite3.New(ctx, connURL, ksql.Config{})
2021-12-28 21:37:07 -03:00
Vinícius Garcia 5fffde3d34 Ignore structs not tagged with tablename on joined structs 2021-12-23 23:06:29 -03:00
Vinícius Garcia 402a9e98ac Fix all queries to ignore untagged struct attributes 2021-12-23 22:56:25 -03:00
Vinícius Garcia 487e2aa6ac Fix error that did not ignore fields with no ksql tags on QueryOne
The original attempt of fixing this problem was on commit:

e970a3546a
2021-12-23 22:43:33 -03:00
Vinícius Garcia 82a43fda87 Add error check for structs with duplicated tag names
Closes #6
2021-12-22 19:36:39 -03:00
Vinícius Garcia 6a4ec2cd51 Update Exec signature to return the number of affected rows 2021-11-26 22:13:56 -03:00
Vinícius Garcia a1403dc9d3 Simplify the signature of the Delete() method
This change was finally made because the Delete function was the
only helper function that was not returning the ksql.ErrRecordNotFound
when no rows were found.

The other reason for this change is that we the most common use case is
by far for deleting a single element, and the philosophy of the library
is to optimize for the most common use-cases.

For making it easier to write queries for deleting many items
as well as many other less common use cases we
are already implementing the `kbuilder` package which is a
query builder.
2021-11-22 19:42:33 -03:00
Vinícius Garcia 25781352cb Add adapters for each possible db technology 2021-11-14 14:54:01 -03:00
Vinícius Garcia 4b75696bb4 Add SetDefaultValues() func to the ksql.Config struct 2021-10-30 12:08:03 -03:00
Vinícius Garcia 45cb57cfa8 Add kpgx.New()
This new package kpgx was created so that in the future we can
make it a separate module.

This will be important in order to prevent users from having to
import all the backend libraries even when they might only be
using one of them.
2021-10-27 22:58:35 -03:00
Vinícius Garcia 268e3d3c36 Remove unnecessary extra argument from ksql.NewWithAdapter
To be honest I don't know how it ended up there =P
2021-09-27 18:58:55 -03:00
Vinícius Garcia 8b897d8ca9 Add error check for nil pointers passed as arguments to Delete() 2021-09-18 21:00:22 -03:00
Vinícius Garcia dffba55a8b Add error check for nil pointers passed as arguments to Update() 2021-09-18 20:52:48 -03:00
Vinícius Garcia 1cf671cd33 Add error check for nil pointers passed as arguments to Insert() 2021-09-18 18:29:00 -03:00
Vinícius Garcia e7e404dc86 Small refactor on Insert() to avoid using reflect.TypeOf multiple times 2021-09-18 18:25:17 -03:00
Vinícius Garcia 889662c4e0 Add error check for nil pointers used as arguments to QueryOne() 2021-09-18 14:42:53 -03:00
Vinícius Garcia f68b71a0a1 Merge branch 'master' into kbuilder 2021-08-08 19:34:22 -03:00
Vinícius Garcia 37298e2c24 Simplify NewWithPGX() function 2021-08-01 15:04:47 -03:00
Vinícius Garcia 5d6f1d7d37 Improve NewWithPGX() constructor 2021-08-01 11:51:40 -03:00
Vinícius Garcia 657ed7414b Add first version of the pgx adapter 2021-08-01 10:23:10 -03:00
Vinícius Garcia e73db4a216 Abstract the DBAdapter so that we can support other sql adapters
This was done for a few different reasons:

1. This allows us to work on top of the pgx client in the future
2. This would allow our users to implement their own DBAdapters
   to use with our tool.
3. This gives the users the option of using advanced configs
   of any sql client they want to use and just feed us with it
   after the configuration is done, which means we will not have
   to worry about supporting a growing number of configurations
   as we try to add support to more drivers or if we get issues
   asking for more advanced config options.
2021-07-31 18:55:08 -03:00
Vinícius Garcia f420553e0b Remove risk of panic on Insert()
This panic used to happen if the user configured a table to use
a specific ID column then tried to insert to the database
with a struct that did not have that column.
2021-07-15 23:22:34 -03:00
Vinícius Garcia b6e6667a3f Improve the names of some public types *breaking change* 2021-06-28 17:35:46 -03:00
Vinícius Garcia 2a38ae3998 Improve Update method to return ErrRecordNotFound if no rows were updated 2021-06-13 15:11:17 -03:00