78 Commits

Author SHA1 Message Date
Vinícius Garcia
211fddf4ee Small refactor to the Patch() function 2022-12-13 22:36:23 -03:00
Vinícius Garcia
83cf354f35 Add TDD tests for checking if context was cancelled 2022-11-29 09:18:34 -03:00
Vinícius Garcia
5bfb5cd92a Improve error messages for scan errors on all adapters 2022-11-12 15:20:06 -03:00
Vinícius Garcia
dd8a45c5d5 Rename kmodifiers to ksqlmodifiers 2022-10-18 12:57:27 -03:00
Vinícius Garcia
4890563c27 Expose some public types and functions so users can register new modifiers 2022-10-18 12:53:25 -03:00
Vinícius Garcia
f41edb427d Add three new modifiers and fix a couple bugs
This commit adds these modifiers:

1. skipUpdates (with unit tests)
2. skipInserts (with unit tests)
3. skipQueries (no tests yet) (and not really working yet)

And handles two situations previously not considered:

1. Updates with no attributes will now return a properly formatted
   error instead of returning a syntax error.
2. Inserts with no values will now work on SQLite, Postgres and
   SQLServer
2022-10-12 22:47:33 -03:00
Vinícius Garcia
57c0f4cade Add timeNowUTC and timeNowUTC/skipUpdates modifiers 2022-10-09 21:49:21 -03:00
Vinícius Garcia
ae76cd5768 Merge branch 'master' of github.com:VinGarcia/ksql into add-attr-middlewares 2022-10-08 22:35:40 -03:00
Vinícius Garcia
8538d99468 Remove unnecessary dependency on github.com/pkg/errors 2022-10-08 14:56:30 -03:00
Vinícius Garcia
8cba3efa2d Refactor modifiers so it is represented by a struct 2022-09-26 01:37:23 -03:00
Vinícius Garcia
41f4d5487b Refactor modifiers into its own package 2022-09-21 22:30:20 -03:00
Vinícius Garcia
cb15295e46 Rename serializers to modifiers 2022-09-21 21:38:30 -03:00
Vinícius Garcia
f95cd2b7b2 Refactor code so that users can add their own serializers 2022-09-14 23:03:33 -03:00
Vinícius Garcia
67ad75242a Improve some error messages 2022-08-27 12:33:18 -03:00
Vinícius Garcia
86dd623eac Improve some error messages 2022-08-27 12:28:39 -03:00
Vinícius Garcia
8620600d01 Revert "Decouple ksql.DB from TagInfoCache so we can replace it during tests"
This reverts commit 74cb87bea027e7924e614a8f2ff0c9719f8dd4b6.

This was done because I noticed this first commit was unnecessary.

This original commit was written in order to allow tests where
the cache would return errors, but I noticed there is a way
of provoking these errors without the need of an extra layer
of abstraction.

Thus, in order to keep the code simpler and also avoid an extra
level of indirection I am undoing this change.
2022-08-27 12:18:02 -03:00
Vinícius Garcia
74cb87bea0 Decouple ksql.DB from TagInfoCache so we can replace it during tests 2022-08-24 22:45:24 -03:00
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:

e970a3546a0635989d27e68d9741118d99d11490
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