bob icon indicating copy to clipboard operation
bob copied to clipboard

Update documentation for code generation

Open rkrishnasanka opened this issue 1 year ago • 8 comments

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.

rkrishnasanka avatar Feb 15 '24 20:02 rkrishnasanka

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

stephenafamo avatar Feb 16 '24 09:02 stephenafamo

@rkrishnasanka Simply call bob.New(db)

jacobmolby avatar Feb 19 '24 11:02 jacobmolby

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 avatar Feb 19 '24 11:02 rkrishnasanka

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

rkrishnasanka avatar Feb 19 '24 16:02 rkrishnasanka

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

jacobmolby avatar Feb 20 '24 07:02 jacobmolby

@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.

rkrishnasanka avatar Feb 29 '24 11:02 rkrishnasanka

@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?

pcriv avatar May 27 '24 12:05 pcriv

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"

rkrishnasanka avatar May 27 '24 12:05 rkrishnasanka

My PR #469 should address some of this. I will also update the configuration options documentation in a follow up. Feel free to assign this to me @stephenafamo

singhsays avatar Jul 01 '25 10:07 singhsays

Thank you

stephenafamo avatar Jul 01 '25 14:07 stephenafamo