Genie Discord forum

Author Avatarctl
10/26/2023, 10:09:22 AM

Once a backend is defined, is there a way to look into the actual SQL produced by the SearchLight API?

Author Avatarctl
10/26/2023, 11:45:12 AM

The query builder, any tutorials on that?

Author Avatarctl
10/26/2023, 11:56:06 AM

I understand I can do like: SearchLight.query("DESCRIBE <mytable>") But like before you run a migration for instance, is there a way to snoop into the generated SQL?

Author Avataressenciary
10/27/2023, 10:53:32 AM

there is no option to "preview" an operation before you run it - but you can use the lower level API inside SearchLight. The general flow is

Author Avataressenciary
10/27/2023, 10:53:59 AM

a) you set up your query objects b) these objects are converted to sql c) the resulting sql is run against the DB connection

Author Avataressenciary
10/27/2023, 10:55:04 AM

you can see them in action in SearchLight.jl

Author Avataressenciary
10/27/2023, 10:55:58 AM

but if you use the models interface, I never heard about generating incorrect queries - anything that could generate data loss for example

Author Avataressenciary
10/27/2023, 10:56:26 AM

and the OOP API is pretty clear: only deleting an object will remove rows. And saving objects will insert or update.

Author Avataressenciary
10/27/2023, 10:56:41 AM

a find operation will always be a pure SELECT

Author Avataressenciary
10/27/2023, 10:57:31 AM

and for migrations, again, you have to write the down method and put the deletion of the table/columns/indices there - it won't delete anything by itself

Author Avatarctl
10/27/2023, 11:52:20 AM

Thank you Adrian, my use case was more in the interest of previewing the right datatypes, relations and composite keys for instance -sort of like dryrun. I'm not, at this point, worried about data loss ๐Ÿ˜…