diff options
| author | Simeon Simeonov | 2021-03-16 11:03:38 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2021-03-16 11:03:38 +0100 |
| commit | 85c1bd41d6b3b985bb6794ebe066128c51e7c8fd (patch) | |
| tree | 9cd33b733b1e11b8fedf88c7e31213d29c4cb9ac /reveal.js/sqlalchemy.html | |
| parent | f5b94931274107ae70587a4c1ac0c3756b7f16ab (diff) | |
Improve reveal.js/sqlalchemy.html and start working on the Statnett theme
Diffstat (limited to 'reveal.js/sqlalchemy.html')
| -rwxr-xr-x | reveal.js/sqlalchemy.html | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/reveal.js/sqlalchemy.html b/reveal.js/sqlalchemy.html index 578fc13..6acd9b7 100755 --- a/reveal.js/sqlalchemy.html +++ b/reveal.js/sqlalchemy.html | |||
| @@ -48,7 +48,7 @@ | |||
| 48 | <h2>What is SQLAlchemy?</h2> | 48 | <h2>What is SQLAlchemy?</h2> |
| 49 | </br> | 49 | </br> |
| 50 | <p><em>SQLAlchemy</em> is a Python library created by Mike Bayer to provide a high-level Pythonic interface to RDBMS such as <em>PostgreSQL</em>, <em>SQLite</em>, <em>MySQL</em>, <em>Oracle</em>, <em>DB2</em>.</p> | 50 | <p><em>SQLAlchemy</em> is a Python library created by Mike Bayer to provide a high-level Pythonic interface to RDBMS such as <em>PostgreSQL</em>, <em>SQLite</em>, <em>MySQL</em>, <em>Oracle</em>, <em>DB2</em>.</p> |
| 51 | <p><em>SQLAlchemy</em> includes RDBMS-independent SQL expression language and an <em>object-relational mapper (ORM)</em>.</p> | 51 | <p><em>SQLAlchemy</em> includes RDBMS-independent <em>SQL expression language</em> and an <em>object-relational mapper (ORM)</em>.</p> |
| 52 | </section> | 52 | </section> |
| 53 | 53 | ||
| 54 | <section> | 54 | <section> |
| @@ -59,7 +59,7 @@ | |||
| 59 | <li><p>portability - the programming interface is independent of the type of RDBMS and connector used</p></li> | 59 | <li><p>portability - the programming interface is independent of the type of RDBMS and connector used</p></li> |
| 60 | <li><p>security - no more SQL injections</p></li> | 60 | <li><p>security - no more SQL injections</p></li> |
| 61 | <li><p>abstraction - no need to bother with complex JOINs</p></li> | 61 | <li><p>abstraction - no need to bother with complex JOINs</p></li> |
| 62 | <li><p>object-orientation - you work with objects and NOT tables and rows</p></li> | 62 | <li><p>object-orientation - you work with objects instead of tables and rows</p></li> |
| 63 | <li><p>performance - exploits the likehood of reusing a particular query</p></li> | 63 | <li><p>performance - exploits the likehood of reusing a particular query</p></li> |
| 64 | <li><p>flexibility - you can override almost anything</p></li> | 64 | <li><p>flexibility - you can override almost anything</p></li> |
| 65 | <li><p>0.0125 karma points for each MB transferred (2021)</p></li> | 65 | <li><p>0.0125 karma points for each MB transferred (2021)</p></li> |
| @@ -72,9 +72,9 @@ | |||
| 72 | <ul> | 72 | <ul> |
| 73 | <li><em>Engine</em>- manages the connection pool and the RDBMS-independent SQL dialect layer</li> | 73 | <li><em>Engine</em>- manages the connection pool and the RDBMS-independent SQL dialect layer</li> |
| 74 | <li><em>MetaData</em> - used to collect and organize information about your table layout (schema)</li> | 74 | <li><em>MetaData</em> - used to collect and organize information about your table layout (schema)</li> |
| 75 | <li><em>Session</em> - establishes all conversations with the RDBMS and represents a "holding zone" for all the objects which you've loaded or associated with it during its lifespan</li> | ||
| 76 | <li><em>SQL expression language</em> - provides an API to execute your queries and updates against your tables, all from Python, and all in a database-independent way (low-level interface)</li> | 75 | <li><em>SQL expression language</em> - provides an API to execute your queries and updates against your tables, all from Python, and all in a database-independent way (low-level interface)</li> |
| 77 | <li><em>ORM</em> - provides a convenient way to add database persistence to your Python objects withoutrequiring you to design your objects around the database, or the database around the objects (high-level interface)</li> | 76 | <li><em>ORM</em> - provides a convenient way to add database persistence to your Python objects without requiring you to design your objects around the database, or the database around the objects (high-level interface)</li> |
| 77 | <li><em>Session</em> - establishes all conversations with the RDBMS and represents a "holding zone" for all the objects which you've loaded or associated with it during its lifespan</li> | ||
| 78 | </ul> | 78 | </ul> |
| 79 | <img src="images/sqlalchemy/sqla_arch.png"></img> | 79 | <img src="images/sqlalchemy/sqla_arch.png"></img> |
| 80 | </section> | 80 | </section> |
| @@ -86,6 +86,7 @@ | |||
| 86 | <code class="python" data-trim data-line-numbers type="text/template"> | 86 | <code class="python" data-trim data-line-numbers type="text/template"> |
| 87 | import sqlalchemy | 87 | import sqlalchemy |
| 88 | sqlalchemy.__version__ | 88 | sqlalchemy.__version__ |
| 89 | # Out: '1.3.23' | ||
| 89 | 90 | ||
| 90 | from sqlalchemy import create_engine | 91 | from sqlalchemy import create_engine |
| 91 | 92 | ||
| @@ -95,7 +96,6 @@ | |||
| 95 | # and driver the name of a DBAPI, such as psycopg2, pyodbc, cx_oracle | 96 | # and driver the name of a DBAPI, such as psycopg2, pyodbc, cx_oracle |
| 96 | # The echo flag is a shortcut to setting up SQLAlchemy logging, | 97 | # The echo flag is a shortcut to setting up SQLAlchemy logging, |
| 97 | # which is accomplished via Python’s standard logging module. | 98 | # which is accomplished via Python’s standard logging module. |
| 98 | # With it enabled, we’ll see all the generated SQL produced. | ||
| 99 | # engine = create_engine("sqlite:///library.db", echo=True) | 99 | # engine = create_engine("sqlite:///library.db", echo=True) |
| 100 | engine = create_engine("sqlite:///:memory:", echo=True) | 100 | engine = create_engine("sqlite:///:memory:", echo=True) |
| 101 | 101 | ||
| @@ -296,7 +296,8 @@ | |||
| 296 | session.query(Book).join(Author).filter(Author.name == "Richard Dawkins").all() | 296 | session.query(Book).join(Author).filter(Author.name == "Richard Dawkins").all() |
| 297 | session.query(Book).\ | 297 | session.query(Book).\ |
| 298 | from_statement("SELECT b.* FROM books b, authors a WHERE b.author_id = a.author_id AND a.name=:name").\ | 298 | from_statement("SELECT b.* FROM books b, authors a WHERE b.author_id = a.author_id AND a.name=:name").\ |
| 299 | params(name="Richard Dawkins").all() | 299 | params(name="Richard Dawkins").all() |
| 300 | session.query(Book).filter(Book.author == author_1).all() | ||
| 300 | </code> | 301 | </code> |
| 301 | </pre> | 302 | </pre> |
| 302 | </section> | 303 | </section> |
| @@ -336,6 +337,7 @@ | |||
| 336 | # Out: [<__main__.Book at 0x7f132bdf0130>] | 337 | # Out: [<__main__.Book at 0x7f132bdf0130>] |
| 337 | # WHERE (abs(books.book_id) > ?) IS 1 ... in the case of func.abs | 338 | # WHERE (abs(books.book_id) > ?) IS 1 ... in the case of func.abs |
| 338 | 339 | ||
| 340 | # with Pandas | ||
| 339 | df = pd.read_sql_table("my_table", con=session.get_bind()) # or con=engine | 341 | df = pd.read_sql_table("my_table", con=session.get_bind()) # or con=engine |
| 340 | 342 | ||
| 341 | df = pd.read_sql_query(query.statement, engine) | 343 | df = pd.read_sql_query(query.statement, engine) |
| @@ -370,7 +372,8 @@ | |||
| 370 | // Learn about plugins: https://revealjs.netlify.app/plugins/ | 372 | // Learn about plugins: https://revealjs.netlify.app/plugins/ |
| 371 | plugins: [ RevealZoom, RevealNotes, RevealSearch, RevealMarkdown, RevealHighlight ] | 373 | plugins: [ RevealZoom, RevealNotes, RevealSearch, RevealMarkdown, RevealHighlight ] |
| 372 | }); | 374 | }); |
| 373 | 375 | Reveal.configure({ pdfSeparateFragments: false }); | |
| 376 | |||
| 374 | </script> | 377 | </script> |
| 375 | 378 | ||
| 376 | </body> | 379 | </body> |
