Conf42 Golang 2021 - Online

Ent: Making Data Easy in Go

Video size:

Abstract

What do most applications do these days? They interact with data in one way or another. As your app’s scale increases, it becomes more challenging to manage databases, schemas, queries, and constraints. These challenges are why a technique called Object-Relational Mapping, or ORM, was created. At Facebook, we tend to think about data modeling in graph concepts and as we were working with Go, it led us to create a new open source project, Ent.

Ent is an entity framework built for Go programming language. This framework provides developers with a Graph-based, Object Relational Mapping. In this talk, we will learn how to use Ent when dealing with data schemas, including types, relations and constraints. It’s a hands-on talk, so get ready to follow along!

Summary

  • Today we'll talk about a project EnT and how it can make it easier for you to deal with data when working with go programming language. Mitrivinik is a developer advocate on the Facebook open source team.
  • Ent was originally open sourced by Facebook and it's Orm for go programming language. Orm is object relational mapping. It's a technique for converting data between incompatible type systems. Everything is about data, big or small. Most applications are data driven.
  • I hope that you will experiment with tools. Join these ent community. Don't just use it. More importantly, try to contribute back. That's the very nature of open source. Follow me on Twitter, go to my blog LinkedIn or email me direct.

Transcript

This transcript was autogenerated. To make changes, submit a PR.
Hello everyone, my name is Mitrivinik and I'm a developer advocate on the Facebook open source team. Today we'll talk about a project EnT and how it can make it easier for you to deal with data when working with go programming language. So let's go. As I said, today I'll talk about Ant and how it can make it easier for you to deal with data in go programming language. But before I do that, I'd like to introduce myself a bit more. And so what do I do? As I said, I'm an open source developer advocate and we are dealing with a massive portfolio of open source projects, more than 600 of them. And there are different pillars and areas of focus. And for myself personally, I focus on mobile development, Android, iOS and hybrid open source project like React native, lethal for Android, fresco for image management in Android, but also flipper which is extendable mobile apps, debugger and many more projects. But more importantly is that I'm very passionate about open source and that's why I'm talking about ANt and what is Ent? Ent was originally open sourced by Facebook and it's Orm for go programming language. What is OrM, you ask? Orm is object relational mapping. And again, it's a term, it's an acronym. And to define it I would use the most best online source ever. It's a technique for converting data between incompatible type systems using object oriented programming languages. It's a long sentence by was I said these best source on the web, Wikipedia. But ultimately in simple terms, what it does is imagine you have an entity user in your code with a certain number of attributes, user id, first name, last name and then you have a table in your database with the user id first name and last name. A stack that basically map to your object. In between. You would have orm that will connect your objects in your object created language which might be go or Java. With these table you don't have to called particular transactions deal with constraints. It will be handled for you in the Orm of your choice. And this Orm is what we're discussing today with and basically is that object relational mapping that we can use for go. And why is OrM important? Because why would we even discuss it if it wasn't? It's all about data. Everything is about data, big or small. Most applications are data driven. An example is for instance Google cloud integration. These simple diagram it's really driven by data. It has an important piece of these entire pipeline. If you talk about AWS, the startup use case that they have on their website. It's also all about data. They're dealing with data. And example of course was I'm working at Facebook, Facebook scribe, the log processor there alone were dealing with a massive amount of data. In this case logs, which is again a data. Data is extremely important. Was we just highlighted then OrM is important too. If you're dealing with something essential, whatever you're using was a tool for that. Data is important. And I've kind of talked about already theory quite a bit. And I personally do not like theory too much. That's why let's look at the code, let's look at ent in action, why it's so powerful. Again, they have great documentation that you can find on these website. And if you were to go to the simple intro page, you would find that the only thing you have to do is you have to run Goget and go to get the CLI installed. Then you initialize your project. In my case I call it endgotalk and it will produce you something like this. As you can see here, I have just a simple file for the project with a module name. Then if you run another operation to initialize simplest entity, simple file user in this case, because you remember that's like the easiest use case I can think of. And again, you can see that on a website as well. It will generate a schema for you, for the user with fields, just the placeholders initially. But if you wanted to take it further and let's say add age name or whatever else, you might decide to add those fields, after adding them, you will run generate operation with Ent. It will generate all sorts of files that necessary for you to use it. It's already fully functioning, so you can deploy it and start working with ent right away. If you wanted to create entities, for example, you create a client in the client, in this case I connect to sqlite three. And if I wanted to, as I said, create a user, the only thing I have to do is add this operation that sets name, h or whatever other attributes are required for my entity. In the situation, the way I showed before, I had first name and last name. Here I just have h name. It doesn't matter. It's just all about showing you how simple and quick it is to have something in your code that will allow you to interact with data as any other orm will allow you. And again, it's just a simple insight on how simple it is to start. And if you were to obviously not just create, but read something querying the entities again, you will add a query user function and that function you choose by what you're going to search for. It can be an id, it can be a name. In this case you can see that I just call a query function and specify a where clause. Similarly, as you were to do a query in these database directly, but here you can do it in the code and that's the only thing you really have to use. And again, if you want to go deeper, you'll find it on their website on endgo IO. And there is a lot more. If anything, Ent has a great deal of documentation you can pick and choose from and get started. There are many tutorials in there already. It teaches you how to set it up more than just intro, just step by step. It goes into more complex situations, how to create a to do, how to query and mutate your data. And more importantly, if you wanted to have some integrations, let's say with graphql or relay, it also goes into those details too. And of course there are more docs than that. There is the more complex documentation about schemas, about migration from the databases. How do you do graph traversal? And a lot, a lot more than that. And of course I'm really glad they have that here. It's about testing. No production code should be left untested, I believe. I'm not talking about 100% coverage built. You should have some tests to make sure something as important was dealing with data is tested. And fortunately this project has that writing in the documentation on the main page. If you really want to see the internals, you can see go to the godocs. It's available right on the website and it has all the information you need for that. But really it's all about the community. You want to join the community, don't just consume a project like this. And the community is great. It's growing. Right now they have a newsletter, a blog where these try to connect with the audience and discuss what the new features might be. They have a Twitter account. If you are following Twitter for the most part, and of course they have slack to discuss and do. The Q was whenever necessary. Or if you have a question about starting to use, go. And I always like to end my talks with quick call to action that gets you going after the presentation is over. I know it was a quick one, but I hope that you will experiment with tools. I haven't showed you much here, obviously. I just show you how to get started and why RM is important if you're not using one. But if you are directly dealing with data, you would find and a great project to deal with. A great tool to add to your toolkit. Join these ent community. Don't just use it. More importantly, try to contribute back. That's the very nature of open source. You join the community, you become a user, then you become a contributor, and then you might become a maintainer. Just try to engage and contribute back. Don't just consume. And with that, I'd like to say thank you. Follow me on Twitter, go to my blog LinkedIn or email me direct, likely for any questions. And thank you so much for listening.
...

Dmitry Vinnik

Developer Advocate @ Facebook

Dmitry Vinnik's LinkedIn account Dmitry Vinnik's twitter account



Awesome tech events for

Priority access to all content

Video hallway track

Community chat

Exclusive promotions and giveaways