<?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: Nicolas Lima</title>
    <description>The latest articles on DEV Community by Nicolas Lima (@delimanicolas).</description>
    <link>https://dev.to/delimanicolas</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%2F70425%2F24e38627-4a8e-4968-aad9-eb3419101c71.jpeg</url>
      <title>DEV Community: Nicolas Lima</title>
      <link>https://dev.to/delimanicolas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/delimanicolas"/>
    <language>en</language>
    <item>
      <title>Testing Apollo Server Graph API</title>
      <dc:creator>Nicolas Lima</dc:creator>
      <pubDate>Thu, 30 Apr 2020 18:06:36 +0000</pubDate>
      <link>https://dev.to/delimanicolas/testing-apollo-server-graph-api-29a4</link>
      <guid>https://dev.to/delimanicolas/testing-apollo-server-graph-api-29a4</guid>
      <description>&lt;h3&gt;
  
  
  I often see people on community complaining about testing Graph API's, So I decided to create this little template using apollo server and jest with Typescript! I hope you can use it as a base to make something just as good as you need! The idea is to separate the application from the server, this way you can use supertest npm module to make real requests and do not need to initiate a local server!
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/deLimaNicolas/graphql-typescript-test-boilerplate"&gt;https://github.com/deLimaNicolas/graphql-typescript-test-boilerplate&lt;/a&gt;&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>typescript</category>
      <category>jest</category>
    </item>
    <item>
      <title>Clickhouse over Postgresql?</title>
      <dc:creator>Nicolas Lima</dc:creator>
      <pubDate>Sat, 11 Jan 2020 22:17:51 +0000</pubDate>
      <link>https://dev.to/delimanicolas/clickhouse-over-postgresql-3f66</link>
      <guid>https://dev.to/delimanicolas/clickhouse-over-postgresql-3f66</guid>
      <description>&lt;h1&gt;
  
  
  About this post
&lt;/h1&gt;

&lt;p&gt;All right, fellows, I'm quite new to the data world, my entire career was development itself, but aren't we always trying to get better? That's why I'm taking my chances now, and my first challenge in my adventure is to decide between Postgres and Clickhouse (I'll explain at the problem section). Anyway, you can use this article as a source of knowledge but I beg you to don't skip the comments section because the main point of this writing is to help me discover all concept mistakes I have in my mind! So read this, but go check what te good coders have to say about it :).&lt;/p&gt;

&lt;h1&gt;
  
  
  The problem
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6Q2t84yN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ytimg.com/vi/rClNZLXSKA8/maxresdefault.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6Q2t84yN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ytimg.com/vi/rClNZLXSKA8/maxresdefault.jpg" alt="problem"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Now, the most important part of every task, understanding the problem.
&lt;/h5&gt;

&lt;p&gt;Although I need to store data for transactions and analysis, two different things, I still have all my application info stored in one Postgres DB. I guess for an app with a small amount of data that would be nothing to worry about, I mean, Postgres was not made for OLAP but it can handle the job. But in my case scenario, I have a Bigdata challenge, we're saving a considerable quantity of historical data along with daily transactional info and this is inflicting our performance.&lt;/p&gt;

&lt;p&gt;Another worthy thing to remember about my problem: The end-user can create his own queries, so it's a little bit difficult to predict how our DB it's gonna be used.&lt;/p&gt;

&lt;h1&gt;
  
  
  The solution
&lt;/h1&gt;

&lt;p&gt;Here is where I expose myself, I thought about some workarounds and the point is for you guys read and tell me when and if I got it wrong, if you agree and got extra tips or own experience stories, please tell me all about! Appreciate!&lt;/p&gt;

&lt;h2&gt;
  
  
  With Postgres
&lt;/h2&gt;

&lt;p&gt;I need to, at least, try to maintain Postgres in my system, after all, it seems easier when you compare to migrate your entire application to Clickhouse. Let's skip obvious things, such as updating hardware, isolating DB from application etc.&lt;/p&gt;

&lt;p&gt;The only way I figured out to continue with Postgres is by changing our system architecture. Since is quite impossible to predict all types of queries our users will create, indexing and SQL structures will not solve 100% of the problem. That's why I'm thinking about an approach where we store historical and transactional data into two different environments, this way when our end-user create his own query it wouldn't need to scan an entire big table, only a small piece of it and perhaps if he needs to access the oldest data we can redirect him to the other slower environment.&lt;br&gt;
But this will apply more complexity to our application and it goes against a hybrid OLAP/OLTP architecture, that I believe is a good bet to the future!&lt;br&gt;
Any tips here?&lt;/p&gt;

&lt;h2&gt;
  
  
  Clickhouse
&lt;/h2&gt;

&lt;p&gt;If you don't know much about Clickhouse, please check &lt;a href="https://hackernoon.com/clickhouse-an-analytics-database-for-the-21st-century-82d3828f79cc"&gt;this link&lt;/a&gt;, in short ClickHouse is a columnar DBMS for OLAP, it is great to run queries on a big amount of data, &lt;a href="https://www.percona.com/blog/2019/05/01/benchmark-clickhouse-database-and-clickhousedb_fdw/"&gt;here&lt;/a&gt; you can see a benchmark comparison between Postgres and Clickhouse.&lt;br&gt;
Clickhouse itself would easily solve our performance problem, bigdata is definitely not a problem for this guy, but still, not 100% good. &lt;/p&gt;

&lt;p&gt;"Specialized tools are specialized: just remember the limitations! - Bad with heterogeneous hardware (Cloudflare experience) - Non-throttled recovery (source replicas flooded with replication load) - No real delete/update support, and no transactions - No secondary keys - Own protocol (no MySQL protocol support) - Limited SQL support, and the joins implementation is different. If you are migrating from MySQL or Spark, you will probably have to re-write all queries with joins" - hnmullany from Hackernews&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DH-VZS1y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.redd.it/s7cs1d7c7zy21.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DH-VZS1y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.redd.it/s7cs1d7c7zy21.jpg" alt="solution"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All right, we kinda have a solution here, Clickhouse is for sure a good choice, but will not solve everything, that's the point when I started to think about combining the pros of Postgres and Clickhouse. Maybe a  Foreign Data Wrapper could save me here. This way I can use Clickhouse to handle all massive data queries, even those that my end-user will create himself and for operations like delete and update I can continue to use Postgres features.&lt;/p&gt;

&lt;p&gt;Using &lt;a href="https://www.percona.com/blog/2019/03/29/postgresql-access-clickhouse-one-of-the-fastest-column-dbmss-with-clickhousedb_fdw/"&gt;clickhousedb_fdw&lt;/a&gt; may be a good choice for that, but... Is not perfect as well, I don't have much experience using an FDW but I guess it would apply complexity to our application, mainly when we're talking about synching our foreign tables.&lt;/p&gt;

&lt;p&gt;That's what I have so far, what you guys think about?&lt;/p&gt;

&lt;p&gt;Thanks for stopping by! Good Luck and Good Code.&lt;/p&gt;

</description>
      <category>clickhouse</category>
      <category>discuss</category>
      <category>olap</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Building a Serverless REST API using MongoDB(mongoose), NodeJs and Serverless framework</title>
      <dc:creator>Nicolas Lima</dc:creator>
      <pubDate>Tue, 01 May 2018 20:32:03 +0000</pubDate>
      <link>https://dev.to/delimanicolas/building-a-serverless-rest-api-using-mongodbmongoose-nodejs-and-serverless-framework-27g0</link>
      <guid>https://dev.to/delimanicolas/building-a-serverless-rest-api-using-mongodbmongoose-nodejs-and-serverless-framework-27g0</guid>
      <description>&lt;h1&gt;
  
  
  Goals
&lt;/h1&gt;

&lt;p&gt;Build and test locally a Serverless API,  that can access a local MongoDB using mongoose&lt;/p&gt;

&lt;h1&gt;
  
  
  Requirements
&lt;/h1&gt;

&lt;p&gt;All right fellows, first I need to explain the reason that I created this post. I'm a young BackEnd developer, and I've encountered a lot of information about the creation of Serverless API's, but I realized a great lack of articles when it comes to build using mongoose and testing locally. Anyway, this is a quite simple tutorial, but if you're just like I was yesterday, maybe it can save you some hours.&lt;/p&gt;

&lt;p&gt;This lesson is specific for people who already know almost everything to set up this API, but is suffering because of two or three poorly explained things. So, if you don't know how to set up your AWS account, or don't  know how to use the serverless framework, here are some videos that helped me: &lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=71cd5XerKss&amp;amp;t=322s" rel="noopener noreferrer"&gt;How to create and deploy a simple Serverless API&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=PEatXsXIkLc&amp;amp;index=2&amp;amp;list=PLWYz5kbNpmYVOHUtCwWkRsDtjACI4NfGb" rel="noopener noreferrer"&gt;Understanding a little bit more about AWS LAMBDA&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=WH5GgHaEy7E&amp;amp;t=360s" rel="noopener noreferrer"&gt;Installing MongoDB&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Let's go to work!
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Ok, So let's start installing the Serverless package:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g serverless &lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Now let's create a default service using the aws-nodejs template&lt;br&gt;
&lt;/h3&gt;
&lt;br&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sls create -t aws-nodejs -p api &amp;amp;&amp;amp; cd api&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Now you can see inside the folder we just created named 'api', that we have 2 files:'handler.js' and 'serverless.yml'&lt;br&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Now, inside your api folder, let's initialize npm
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Now, let's install mongoose&lt;br&gt;
&lt;/h3&gt;
&lt;br&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo npm install mongoose --save&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Ok guys, above, in the "Requirements" session, I recommended this  &lt;a href="https://www.youtube.com/watch?v=71cd5XerKss&amp;amp;t=322s" rel="noopener noreferrer"&gt;Video&lt;/a&gt;, it will explain how the basic function inside our file works, re-watch if you feel needs, because we're gonna apply some changes on those files.&lt;br&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  First, make sure you run "mongod" command, because we need a local MongoDB service.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Okay... Now, let's create a new folder inside our api directory, let's name it "Schemas", inside it we're gonna create a new Schema for our MongoDB, if you're not used to work with schemas, check this mongoose &lt;a href="http://mongoosejs.com/docs/guide.html" rel="noopener noreferrer"&gt;Doc&lt;/a&gt; about them
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(inside our directory named 'api') mkdir schemas &lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Then&lt;br&gt;
&lt;/h3&gt;
&lt;br&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(inside schemas) touch user.js&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Using some editor(I like Atom), edit user.js structure inside a var and export a module with this one&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F98lp77l2rtekr7t78cor.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F98lp77l2rtekr7t78cor.png" alt="Just like this"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  All right, now inside "handler.js" let's modify the same "hello" function to connect with our running Mongod service and execute a simple query, but before we need to import "mongoose", start a connection, get our userSchema and create a model.
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(inside handler.js) var mongoose = require("mongoose");&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Then&lt;br&gt;
&lt;/h3&gt;
&lt;br&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var connectorMongodb =  mongoose.connect('mongodb://localhost/mynewDB');&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Almost there...&lt;br&gt;
&lt;/h3&gt;
&lt;br&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var userSchema = require('../api/schemas/userSchema.js');&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Okay...&lt;br&gt;
&lt;/h3&gt;
&lt;br&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var userModel = mongoose.model('user',userSchema,'user');&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Just to remember  you guys, this lesson isn't for total beginners, so if you don't know how to use mongoose and what is a model or schema, go work on it first. This lesson is specific for people that are getting into trouble because of the lack of information about create a Serverles Rest API using specifically mongoose.&lt;br&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Ok, now let's apply some changes inside our "handler.js", and remember that we must close our mongoose connection once it was open, otherwise our function will "timeout" (Lambda functions have a default amount of seconds until it stops)
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fu9mxbb8una6f7rkzt536.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fu9mxbb8una6f7rkzt536.png" alt="Like this"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Now, inside your api directory, run this command in order to test your function "hello" locally
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sls invoke local --function hello&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  It should returns you a Json with your  user's collection information&lt;br&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  I guess you should already have some user data stored inside your DB, just go to mongoshell and use db.user.insert
&lt;/h3&gt;

&lt;h1&gt;
  
  
  I hope i helped you guys, see you later.
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.instagram.com/delimanicolas/" rel="noopener noreferrer"&gt;My Instagram if you like to discuss anything with me&lt;/a&gt;&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>mongodb</category>
      <category>node</category>
      <category>api</category>
    </item>
  </channel>
</rss>
