mirror of
https://github.com/evennia/evennia.git
synced 2026-04-01 13:37:17 +02:00
Updated HTML docs
This commit is contained in:
parent
91a584ba95
commit
4e3201f293
52 changed files with 210 additions and 174 deletions
|
|
@ -355,14 +355,15 @@ values into a string representation before storing it to the database. This is d
|
|||
</div></blockquote>
|
||||
<section id="storing-single-objects">
|
||||
<h3>Storing single objects<a class="headerlink" href="#storing-single-objects" title="Permalink to this headline">¶</a></h3>
|
||||
<p>With a single object, we mean anything that is <em>not iterable</em>, like numbers, strings or custom class
|
||||
instances without the <code class="docutils literal notranslate"><span class="pre">__iter__</span></code> method.</p>
|
||||
<p>With a single object, we mean anything that is <em>not iterable</em>, like numbers,
|
||||
strings or custom class instances without the <code class="docutils literal notranslate"><span class="pre">__iter__</span></code> method.</p>
|
||||
<ul class="simple">
|
||||
<li><p>You can generally store any non-iterable Python entity that can be <em>pickled</em>.</p></li>
|
||||
<li><p>Single database objects/typeclasses can be stored, despite them normally not being possible
|
||||
to pickle. Evennia will convert them to an internal representation using theihr classname,
|
||||
database-id and creation-date with a microsecond precision. When retrieving, the object
|
||||
instance will be re-fetched from the database using this information.</p></li>
|
||||
<li><p>Single database objects/typeclasses can be stored, despite them normally not
|
||||
being possible to pickle. Evennia will convert them to an internal
|
||||
representation using theihr classname, database-id and creation-date with a
|
||||
microsecond precision. When retrieving, the object instance will be re-fetched
|
||||
from the database using this information.</p></li>
|
||||
<li><p>If you ‘hide’ a db-obj as a property on a custom class, Evennia will not be
|
||||
able to find it to serialize it. For that you need to help it out (see below).</p></li>
|
||||
</ul>
|
||||
|
|
@ -416,7 +417,9 @@ serialize the db-objects you want to store.</p>
|
|||
<span class="k">def</span> <span class="nf">__deserialize_dbobjs__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="sd">"""This is called after deserialization and allows you to</span>
|
||||
<span class="sd"> restore the 'hidden' dbobjs you serialized before"""</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">mydbobj</span> <span class="o">=</span> <span class="n">dbserialize</span><span class="o">.</span><span class="n">dbunserialize</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mydbobj</span><span class="p">)</span>
|
||||
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mydbobj</span><span class="p">,</span> <span class="nb">bytes</span><span class="p">):</span>
|
||||
<span class="c1"># make sure to check if it's bytes before trying dbunserialize</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">mydbobj</span> <span class="o">=</span> <span class="n">dbserialize</span><span class="o">.</span><span class="n">dbunserialize</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mydbobj</span><span class="p">)</span>
|
||||
|
||||
<span class="c1"># let's assume myobj is a db-object</span>
|
||||
<span class="n">container</span> <span class="o">=</span> <span class="n">Container</span><span class="p">(</span><span class="n">myobj</span><span class="p">)</span>
|
||||
|
|
@ -424,6 +427,14 @@ serialize the db-objects you want to store.</p>
|
|||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<blockquote>
|
||||
<div><p>Note the extra check in <code class="docutils literal notranslate"><span class="pre">__deserialize_dbobjs__</span></code> to make sure the thing you
|
||||
are deserializing is a <code class="docutils literal notranslate"><span class="pre">bytes</span></code> object. This is needed because the Attribute’s
|
||||
cache reruns deserializations in some situations when the data was already
|
||||
once deserialized. If you see errors in the log saying
|
||||
<code class="docutils literal notranslate"><span class="pre">Could</span> <span class="pre">not</span> <span class="pre">unpickle</span> <span class="pre">data</span> <span class="pre">for</span> <span class="pre">storage:</span> <span class="pre">...</span></code>, the reason is
|
||||
likely that you forgot to add this check.</p>
|
||||
</div></blockquote>
|
||||
</section>
|
||||
<section id="storing-multiple-objects">
|
||||
<h3>Storing multiple objects<a class="headerlink" href="#storing-multiple-objects" title="Permalink to this headline">¶</a></h3>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue