Genie Discord forum
![Author Avatar](https://cdn.discordapp.com/avatars/839529644863520768/148ac081970ddcbfa3df9f6e5a1beb01.png?size=512)
Once a backend is defined, is there a way to look into the actual SQL produced by the SearchLight API?
![Author Avatar](https://cdn.discordapp.com/avatars/839529644863520768/148ac081970ddcbfa3df9f6e5a1beb01.png?size=512)
The query builder, any tutorials on that?
![Author Avatar](https://cdn.discordapp.com/avatars/839529644863520768/148ac081970ddcbfa3df9f6e5a1beb01.png?size=512)
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 Avatar](https://cdn.discordapp.com/avatars/738049963250155580/13375362e7047976b44a466ef441a20f.png?size=512)
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 Avatar](https://cdn.discordapp.com/avatars/738049963250155580/13375362e7047976b44a466ef441a20f.png?size=512)
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 Avatar](https://cdn.discordapp.com/avatars/738049963250155580/13375362e7047976b44a466ef441a20f.png?size=512)
but if you use the models interface, I never heard about generating incorrect queries - anything that could generate data loss for example
![Author Avatar](https://cdn.discordapp.com/avatars/738049963250155580/13375362e7047976b44a466ef441a20f.png?size=512)
and the OOP API is pretty clear: only deleting an object will remove rows. And saving objects will insert or update.
![Author Avatar](https://cdn.discordapp.com/avatars/738049963250155580/13375362e7047976b44a466ef441a20f.png?size=512)
a find
operation will always be a pure SELECT
![Author Avatar](https://cdn.discordapp.com/avatars/738049963250155580/13375362e7047976b44a466ef441a20f.png?size=512)
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 Avatar](https://cdn.discordapp.com/avatars/839529644863520768/148ac081970ddcbfa3df9f6e5a1beb01.png?size=512)
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 ๐