|
|
@ -1600,7 +1600,7 @@ CompletedProcess(args=[<span class="hljs-string">'bc'</span>, <span class="hljs- |
|
|
|
|
|
|
|
<div><h3 id="sqlalchemy">SqlAlchemy</h3><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install sqlalchemy</span> |
|
|
|
<span class="hljs-keyword">from</span> sqlalchemy <span class="hljs-keyword">import</span> create_engine, text |
|
|
|
<engine> = create_engine(<span class="hljs-string">'<url>'</span>).connect() <span class="hljs-comment"># Url: 'dialect://user:password@host/dbname'.</span> |
|
|
|
<engine> = create_engine(<span class="hljs-string">'<url>'</span>) <span class="hljs-comment"># Url: 'dialect://user:password@host/dbname'.</span> |
|
|
|
<conn> = <engine>.connect() <span class="hljs-comment"># Creates a connection. Also <conn>.close().</span> |
|
|
|
<cursor> = <conn>.execute(text(<span class="hljs-string">'<query>'</span>), …) <span class="hljs-comment"># Replaces ':<key>'s with keyword arguments.</span> |
|
|
|
<span class="hljs-keyword">with</span> <conn>.begin(): ... <span class="hljs-comment"># Exits the block with commit or rollback.</span> |
|
|
|