jet icon indicating copy to clipboard operation
jet copied to clipboard

Public APIs expose internal types

Open anuraaga opened this issue 3 years ago • 5 comments
trafficstars

Describe the bug A clear and concise description of what the bug is.

There are some public APIs that expose internal tyeps, for example Table.INSERT

https://github.com/go-jet/jet/blob/master/mysql/table.go#L10

jet.Column is internal.

Expected behavior

All public APIs should only use public types. For example, it doesn't seem to be possible for a user to pass in a slice of columns with the current signature.

anuraaga avatar May 16 '22 08:05 anuraaga

To pass a custom column list to insert or update query, you can use ColumnList:

https://github.com/go-jet/jet/blob/6babd43e3a1af2a7bdff78c32423d0c5e601a644/tests/postgres/update_test.go#L288-L294

I'll add this to wiki.

go-jet avatar May 16 '22 09:05 go-jet

Thanks @go-jet - would it be possible to use that type in the function definitions? I think it can be confusing to use the API when it references the internal instead of public type there.

anuraaga avatar May 17 '22 04:05 anuraaga

We can't use ColumnList in definition because UPDATE should work with single Column, comma separated list of columns and ColumnList. Now, we could expose jet.Column, but I don't see how this type would be ever used.

go-jet avatar May 17 '22 10:05 go-jet

@go-jet I found another API that seems to use public types, Statement.Rows() returns jet.Rows (I can't pass Statement either for similar reason). I can't pass this to another function because jet.Rows is internal. Is there an alternative type for this? In general I suspect there will be less sharp edges if the public API was audited to remove all the internal types somehow.

anuraaga avatar May 24 '22 05:05 anuraaga

Yeah, it seems jet.Rows is not exposed. Contributions are welcomed. Statement is exposed here.

go-jet avatar May 25 '22 09:05 go-jet

@go-jet Wouldn't it be better to expose all the internal APIs? If I understand it correctly, doing so would enable the users of this library to write their own implementations of given interfaces, rather than relying on and waiting for some types being implemented in go-jet.

amanbolat avatar Jan 19 '23 07:01 amanbolat

I think I'm running into this with some other types.

While trying to create a simple SELECT query that takes in a variable to equal check against the lastname field the internal jet package is imported. This prevents the code from working at all due to the following error:

app.go:10:2: use of internal package github.com/go-jet/jet/v2/internal/jet not allowed
stmt := Users.SELECT(Users.AllColumns).FROM(Users).WHERE(Users.Lastname.LIKE(jet.String("")))

Do you have any way around that besides fixing this in the jet repo?

galexrt avatar Mar 05 '23 17:03 galexrt

String is already exported. You are importing the wrong package. You need to import a dialect-specific package. For instance: github.com/go-jet/jet/v2/postgres

houten11 avatar Mar 05 '23 18:03 houten11

String is already exported. You are importing the wrong package. You need to import a dialect-specific package. For instance: github.com/go-jet/jet/v2/postgres

Thanks for the help! I just realized that as well as I don't use the dot imports as shown in the READMe at the moment.

galexrt avatar Mar 05 '23 20:03 galexrt

I have run into the same problem. I might try creating a pull request unless some is working on this.

rowland66 avatar Apr 03 '23 00:04 rowland66

Rows is now exposed on master branch.

go-jet avatar Apr 17 '23 10:04 go-jet

Fixed with Release v2.10.1.

go-jet avatar Jul 24 '23 09:07 go-jet