<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: arvelt</title>
    <description>The latest articles on DEV Community by arvelt (@arvelt).</description>
    <link>https://dev.to/arvelt</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F41481%2F81ac5af3-d353-429c-85d9-a207e860b0ac.jpg</url>
      <title>DEV Community: arvelt</title>
      <link>https://dev.to/arvelt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arvelt"/>
    <language>en</language>
    <item>
      <title>Use ndb.tasklet in GAE</title>
      <dc:creator>arvelt</dc:creator>
      <pubDate>Wed, 15 Nov 2017 06:47:40 +0000</pubDate>
      <link>https://dev.to/arvelt/use-ndbtasklet-in-gae-89m</link>
      <guid>https://dev.to/arvelt/use-ndbtasklet-in-gae-89m</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;time&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sleep&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;google.appengine.ext&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ndb&lt;/span&gt;


&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;ndb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tasklet&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;do_some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="n"&gt;ndb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="n"&gt;ndb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;ndb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tasklet&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
  &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;do_some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;do_some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="n"&gt;ndb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
  &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_result&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;

&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;#Execution time is 3 not 6
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
    </item>
    <item>
      <title>When use ancestor query in GAE, you don't have to be use a existed entity.</title>
      <dc:creator>arvelt</dc:creator>
      <pubDate>Wed, 15 Nov 2017 06:28:10 +0000</pubDate>
      <link>https://dev.to/arvelt/when-use-ancestor-query-in-gae-you-dont-have-to-be-use-a-existed-entity-2kb</link>
      <guid>https://dev.to/arvelt/when-use-ancestor-query-in-gae-you-dont-have-to-be-use-a-existed-entity-2kb</guid>
      <description>&lt;p&gt;But it is better to use a existed entity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from google.appengine.ext import ndb

class Customer(ndb.Model):
    name = ndb.StringProperty()

class Purchase(ndb.Model):
   price = ndb.IntegerProperty()

customer_entity = Customer(name='me', id='aaa@example.com')
purchase1 = Purchase(parent=customer_entity.key, price=100)
purchase2 = Purchase(parent=customer_entity.key, price=200)
purchase1.put()
purchase2.put()
print Purchase.query(ancestor=customer_entity.key).fetch()
#[Purchase(key=Key('Customer', 'aaa@example.com', 'Purchase', 5414888608366592), price=200), Purchase(key=Key('Customer', 'aaa@example.com', 'Purchase', 5977838561787904), price=100)]

key = ndb.Key('user', 'bbb@example.com')
purchase3 = Purchase(parent=key, price=100)
purchase4 = Purchase(parent=key, price=200)
purchase3.put()
purchase4.put()
print Purchase.query(ancestor=key).fetch()
#[Purchase(key=Key('user', 'bbb@example.com', 'Purchase', 4711201166589952), price=200), Purchase(key=Key('user', 'bbb@example.com', 'Purchase', 6540788515209216), price=100)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
    </item>
  </channel>
</rss>
