-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
89 changed files
with
17,463 additions
and
1,258 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
<!DOCTYPE html> | ||
<html class="writer-html5" lang="en" > | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>bento_meta.mdb.writeable — bento-meta documentation</title> | ||
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" /> | ||
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" /> | ||
<link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" /> | ||
<!--[if lt IE 9]> | ||
<script src="../../../_static/js/html5shiv.min.js"></script> | ||
<![endif]--> | ||
|
||
<script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script> | ||
<script src="../../../_static/jquery.js"></script> | ||
<script src="../../../_static/underscore.js"></script> | ||
<script src="../../../_static/_sphinx_javascript_frameworks_compat.js"></script> | ||
<script src="../../../_static/doctools.js"></script> | ||
<script src="../../../_static/sphinx_highlight.js"></script> | ||
<script src="../../../_static/js/theme.js"></script> | ||
<link rel="index" title="Index" href="../../../genindex.html" /> | ||
<link rel="search" title="Search" href="../../../search.html" /> | ||
</head> | ||
|
||
<body class="wy-body-for-nav"> | ||
<div class="wy-grid-for-nav"> | ||
<nav data-toggle="wy-nav-shift" class="wy-nav-side"> | ||
<div class="wy-side-scroll"> | ||
<div class="wy-side-nav-search" > | ||
|
||
|
||
|
||
<a href="../../../index.html" class="icon icon-home"> | ||
bento-meta | ||
</a> | ||
<div role="search"> | ||
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get"> | ||
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" /> | ||
<input type="hidden" name="check_keywords" value="yes" /> | ||
<input type="hidden" name="area" value="default" /> | ||
</form> | ||
</div> | ||
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> | ||
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p> | ||
<ul> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../mdb-principles.html">Metamodel Database (MDB) Principles</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../mdb-conventions.html">MDB Maintenance Principles and Conventions</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../the_object_model.html">The Object Model</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../meta_and_mdf.html">bento_meta and MDF</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../model_versioning.html">Model Versioning</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../object_mapping.html">Object Map Specifications</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../autoapi/index.html">API Reference</a></li> | ||
</ul> | ||
|
||
</div> | ||
</div> | ||
</nav> | ||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > | ||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i> | ||
<a href="../../../index.html">bento-meta</a> | ||
</nav> | ||
|
||
<div class="wy-nav-content"> | ||
<div class="rst-content"> | ||
<div role="navigation" aria-label="Page navigation"> | ||
<ul class="wy-breadcrumbs"> | ||
<li><a href="../../../index.html" class="icon icon-home" aria-label="Home"></a></li> | ||
<li class="breadcrumb-item"><a href="../../index.html">Module code</a></li> | ||
<li class="breadcrumb-item active">bento_meta.mdb.writeable</li> | ||
<li class="wy-breadcrumbs-aside"> | ||
</li> | ||
</ul> | ||
<hr/> | ||
</div> | ||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> | ||
<div itemprop="articleBody"> | ||
|
||
<h1>Source code for bento_meta.mdb.writeable</h1><div class="highlight"><pre> | ||
<span></span><span class="sd">"""</span> | ||
<span class="sd">mdb.writeable: subclass of `class:bento_meta.MDB` to support writing to an MDB</span> | ||
<span class="sd">"""</span> | ||
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">wraps</span> | ||
<span class="kn">from</span> <span class="nn">bento_meta.mdb</span> <span class="kn">import</span> <span class="n">make_nanoid</span> | ||
<span class="kn">from</span> <span class="nn">bento_meta.mdb</span> <span class="kn">import</span> <span class="n">MDB</span> | ||
|
||
<div class="viewcode-block" id="write_txn"><a class="viewcode-back" href="../../../autoapi/bento_meta/mdb/writeable/index.html#bento_meta.mdb.write_txn">[docs]</a><span class="k">def</span> <span class="nf">write_txn</span><span class="p">(</span><span class="n">func</span><span class="p">):</span> | ||
<span class="w"> </span><span class="sd">"""Decorates a query function to run a write transaction based</span> | ||
<span class="sd"> on its query.</span> | ||
<span class="sd"> Query function should return a tuple (qry_string, param_dict)."""</span> | ||
<span class="nd">@wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span> | ||
<span class="k">def</span> <span class="nf">wr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | ||
<span class="k">def</span> <span class="nf">txn_q</span><span class="p">(</span><span class="n">tx</span><span class="p">):</span> | ||
<span class="p">(</span><span class="n">qry</span><span class="p">,</span><span class="n">parms</span><span class="p">)</span><span class="o">=</span><span class="n">func</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> | ||
<span class="n">result</span> <span class="o">=</span> <span class="n">tx</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">qry</span><span class="p">,</span><span class="n">parameters</span><span class="o">=</span><span class="n">parms</span><span class="p">)</span> | ||
<span class="k">return</span> <span class="p">[</span><span class="n">rec</span> <span class="k">for</span> <span class="n">rec</span> <span class="ow">in</span> <span class="n">result</span><span class="p">]</span> | ||
<span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">driver</span><span class="o">.</span><span class="n">session</span><span class="p">()</span> <span class="k">as</span> <span class="n">session</span><span class="p">:</span> | ||
<span class="n">result</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="n">write_transaction</span><span class="p">(</span><span class="n">txn_q</span><span class="p">)</span> | ||
<span class="k">return</span> <span class="n">result</span> | ||
<span class="k">return</span> <span class="n">wr</span></div> | ||
|
||
<div class="viewcode-block" id="WriteableMDB"><a class="viewcode-back" href="../../../autoapi/bento_meta/mdb/writeable/index.html#bento_meta.mdb.WriteableMDB">[docs]</a><span class="k">class</span> <span class="nc">WriteableMDB</span><span class="p">(</span><span class="n">MDB</span><span class="p">):</span> | ||
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | ||
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> | ||
|
||
<div class="viewcode-block" id="WriteableMDB.put_with_statement"><a class="viewcode-back" href="../../../autoapi/bento_meta/mdb/writeable/index.html#bento_meta.mdb.WriteableMDB.put_with_statement">[docs]</a> <span class="nd">@write_txn</span> | ||
<span class="k">def</span> <span class="nf">put_with_statement</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">qry</span><span class="p">,</span> <span class="n">parms</span><span class="o">=</span><span class="p">{}):</span> | ||
<span class="w"> </span><span class="sd">"""Run an arbitrary write statement."""</span> | ||
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">qry</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> | ||
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">"qry= must be a string"</span><span class="p">)</span> | ||
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">parms</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span> | ||
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">"parms= must be a dict"</span><span class="p">)</span> | ||
<span class="k">return</span> <span class="p">(</span><span class="n">qry</span><span class="p">,</span> <span class="n">parms</span><span class="p">)</span></div> | ||
|
||
|
||
<div class="viewcode-block" id="WriteableMDB.put_term_with_origin"><a class="viewcode-back" href="../../../autoapi/bento_meta/mdb/writeable/index.html#bento_meta.mdb.WriteableMDB.put_term_with_origin">[docs]</a> <span class="nd">@write_txn</span> | ||
<span class="k">def</span> <span class="nf">put_term_with_origin</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">term</span><span class="p">,</span> <span class="n">commit</span><span class="o">=</span><span class="s2">""</span><span class="p">,</span> <span class="n">_from</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span> | ||
<span class="w"> </span><span class="sd">"""Merge a bento-meta Term object, that has an Origin object set,</span> | ||
<span class="sd"> into an MDB. If a new term is created, assign a random 6-char nanoid </span> | ||
<span class="sd"> to it. The Origin must already be represented in the database.</span> | ||
<span class="sd"> :param Term term: Term object</span> | ||
<span class="sd"> :param str commit: GitHub commit SHA1 associated with the term (if any)"""</span> | ||
<span class="n">qry</span> <span class="o">=</span> <span class="p">(</span> | ||
<span class="s2">"match (o:origin {name:$o_name, nanoid:$o_id}) "</span> | ||
<span class="s2">"where not exists(o._to) "</span> | ||
<span class="s2">"merge (t:term {"</span> | ||
<span class="s2">" value:$t_value,"</span> | ||
<span class="s2">" origin_id:$t_oid,"</span> | ||
<span class="s2">" origin_version:$t_oversion,"</span> | ||
<span class="s2">" origin_definition:$t_odefn,"</span> | ||
<span class="s2">" _from:$from, _commit:$commit}) "</span> | ||
<span class="s2">"merge (o)<-[:has_origin]-(t) "</span> | ||
<span class="s2">"on create set t.nanoid = $t_id "</span> | ||
<span class="s2">"return t.nanoid"</span> | ||
<span class="p">)</span> | ||
<span class="n">parms</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"o_name"</span><span class="p">:</span> <span class="n">term</span><span class="o">.</span><span class="n">origin</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s2">"o_id"</span><span class="p">:</span> <span class="n">term</span><span class="o">.</span><span class="n">origin</span><span class="o">.</span><span class="n">nanoid</span><span class="p">,</span> | ||
<span class="s2">"t_value"</span><span class="p">:</span> <span class="n">term</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="s2">"t_oid"</span><span class="p">:</span> <span class="n">term</span><span class="o">.</span><span class="n">origin_id</span><span class="p">,</span> | ||
<span class="s2">"t_oversion"</span><span class="p">:</span> <span class="n">term</span><span class="o">.</span><span class="n">origin_version</span><span class="p">,</span> | ||
<span class="s2">"t_odefn"</span><span class="p">:</span> <span class="n">term</span><span class="o">.</span><span class="n">origin_definition</span><span class="p">,</span> | ||
<span class="s2">"t_id"</span><span class="p">:</span> <span class="n">make_nanoid</span><span class="p">(),</span> <span class="s2">"commit"</span><span class="p">:</span> <span class="n">commit</span><span class="p">,</span> | ||
<span class="s2">"from"</span><span class="p">:</span><span class="n">_from</span><span class="p">}</span> | ||
<span class="k">return</span> <span class="p">(</span><span class="n">qry</span><span class="p">,</span> <span class="n">parms</span><span class="p">)</span></div></div> | ||
</pre></div> | ||
|
||
</div> | ||
</div> | ||
<footer> | ||
|
||
<hr/> | ||
|
||
<div role="contentinfo"> | ||
<p>© Copyright 2020, FNLCR.</p> | ||
</div> | ||
|
||
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a | ||
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> | ||
provided by <a href="https://readthedocs.org">Read the Docs</a>. | ||
|
||
|
||
</footer> | ||
</div> | ||
</div> | ||
</section> | ||
</div> | ||
<script> | ||
jQuery(function () { | ||
SphinxRtdTheme.Navigation.enable(true); | ||
}); | ||
</script> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.