Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation for code generation #182

Open
rkrishnasanka opened this issue Feb 15, 2024 · 8 comments
Open

Update documentation for code generation #182

rkrishnasanka opened this issue Feb 15, 2024 · 8 comments
Labels
documentation Improvements or additions to documentation

Comments

@rkrishnasanka
Copy link

It would be great if there was a full example for:

  1. Code Generation Config with all the options and explicitly listed so that we don't need to piece it together
  2. Full example of using the generated code (CRUD). The documentation is a little ambiguous right now in terms of how I should establish the database connections, etc.
@stephenafamo
Copy link
Owner

I would appreciate a PR on this, or other documentation improvements in general.

@stephenafamo stephenafamo added the documentation Improvements or additions to documentation label Feb 16, 2024
@jacobmolby
Copy link
Contributor

@rkrishnasanka Simply call bob.New(db)

@rkrishnasanka
Copy link
Author

Yeah I figured it out shortly after commenting. I missed the link for bob executors. I'll do a PR once I'm done implementing stuff.

@rkrishnasanka
Copy link
Author

Is there a discord for this ? I feel like its better to get some direct feedback. The query parameters are confusing. For example:

	queuesView := psql.NewView[*models.Queue]("core", "queues")
	// Check if the queue already exists
	row, err := queuesView.Query(
		context.Background(),
		bob.NewDB(db),
		models.SelectWhere.Queues.QueueName.EQ(queuename),
	).One()

In this scenario, I get:

"pq: missing FROM-clause entry for table \"queues\"" bob golang

as the error

@jacobmolby
Copy link
Contributor

If you are using the code generation, the view/table is already created for you.

Simply use:

queue, err := models.Queues.Query(
		context.Background(),
		bob.NewDB(db),
		models.SelectWhere.Queues.QueueName.EQ(queuename),
	).One()

//queue is of type models.Queues now

@rkrishnasanka
Copy link
Author

@jacobmolby So turns out that there are a couple more errors happening here that made this complicated #187 . so thats why I've just been dealing with bugs.

@pcriv
Copy link

pcriv commented May 27, 2024

@rkrishnasanka I couldn't find any documentationion of how to use the CLI to generate the code, could you maybe share how you did it?

@rkrishnasanka
Copy link
Author

Here's the command I use

go run github.com/stephenafamo/bob/gen/bobgen-psql@latest -c ./config/bobgen.yaml

Here's the config


psql:
  dsn: "postgres://postgres:@localhost:5432/postgres?sslmode=disable"

  schemas: ["application","core"]
  shared_schema: "public"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants