The PyCharm table view

In the previous subsection, we saw that when using a query console we can execute queries to a database included in a given data source in PyCharm. This means that we can retrieve data as well as submit changes to our connected database tables using the console. Alternatively, as we will see in this subsection, PyCharm offers another way to work with database tables—the table view—that is more graphical and thus more intuitive:

  1. To evoke the table view and apply it to a given table in our database, we can simply double-click on the table in the PyCharm Database panel, and the table view will be opened in the editor. For example, I obtained the following screenshot after double-clicking on the Album table in the Database panel:

The table view in PyCharm

Notice that the corresponding executed query is displayed in the Database Console panel (at the bottom of the project window). Since I opened the whole Album table in my table view, the query executed was SELECT t.* FROM Album t.

You might have noticed that this table view is identical to the output we obtain by running queries from the console in the Database Console panel, discussed in the previous subsection. In fact, all the features included in the following discussion also apply to that table view as well.

  1. Now, using the toolbar at the top of the table view, we have multiple ways to display the result table we have in our view. For example, we can transpose the result table, sort the rows using ORDER BY, or apply a custom filter, using the following options:

Different options to manipulate a table in the table view
  1. Specifically, we can insert a new row or remove a row from the table, using the buttons in the following console toolbar, highlighted:

Adding/removing a row in the table view
Similar to how we can make changes to a database table via queries, we can also achieve the same results via this graphical interface of the table view.
  1. We can also double-click on a specific cell to alter the content of that cell. Simply try this feature with any cell in the current table in our table view.
  2. Note that by changing the content of a cell, we have not made any actual changes to the corresponding database table. To manually submit the changes we have made to the actual database, click on the Submit icon, also included in the console toolbar.
You will also see the corresponding query to mutate the database in the Database Console panel.
  1. With that said, you can also tell PyCharm that you want all changes made to the table in the table view to also be applied to the actual database. To do this, go to the settings and navigate to Tools | Database | Data Views, and enable the Submit changes immediately box.

Now, you might think submitting changes automatically made to database tables is a convenient feature. However, doing so would prevent us from being able to revert any unintentional changes made in the table view. Specifically, we can use the keyboard shortcut ⌥ ⌘ Z in macOS (or Ctrl + Alt + Z in Windows) to revert a change that has not been applied to the actual database yet.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.174.95