lxd/db/generate/db/mapping: Add field-to-sql clause conversion helpers
lxd/db/generate/db/mapping: Add field-to-sql clause conversion helpers

Adds methods on Field to convert the field to a SQL column, or create a
SQL clause from the Field and its tags.

These are expected to replace the current logic for creating statements,
and will allow manual intervention by way of the `sql=<table>.<column>`
tag, to specify our own table and column per struct field, rather than
relying on string manipulation from the struct name and field name.

JOIN clause generation in particular is changed to be smarter about
indirect joins. Rather than relying on a `via` tag (which is now
removed), an indirect join can use a `joinon` tag with a table name
that is different from the one in the `join` tag. This will make the
generator assume that the field doesn't map directly to a column,
and the field will be correctly omitted from INSERT, UPDATE, and
DELETE statements.

Additionally, when inserting the ID column of a joined table to the
current table, rather than generating a whole new SELECT statement
from inferences made about the table from the `join` tag, lxd-generate
will parse the current package (and fall-back to the package specified
by `--database`) for the `<entity>ID` SQL statement of the joining table,
and reuse that.

Signed-off-by: Max Asnaashari <291db2cb5046c5ac435c5cc205a1b9bc80a27f4b@canonical.com>

stgraber/lxd,lxc/lxd,stgraber/lxd,lxc/lxd,lxc/lxd,stgraber/lxd,stgraber/lxd,stgraber/lxd,lxc/lxd,lxc/lxd,stgraber/lxd,stgraber/lxd,lxc/lxd,lxc/lxd