 Thank you Hello everybody I will try to Summarize a new part of the video library just called with the dbo in around 15 minutes. I will mostly show some code examples Since I think that the real benefit or the real added value of this Library is how you can concisely interface with the database from C++ code And I think the most important aspect there is just how Intuitive the code works so Why would we want to have an ORM for C++? Not only because there is one for every language Out there and really good a library is lacking for C++. So that would be one reason That doesn't make a lot of sense But the real reason is that we want to simplify our development and and have to keep in mind that using sequel I don't think it's very difficult sequel is a very simple language and So we should make sure that we don't complicate using sequel But what makes sequel a bit? Hard to use from a programming language is that you have to Didiously map every field from your relational tables on to members of your classes and you want to keep you want to have a way of traversing relationships in your relational database using concepts that you're familiar from or familiar with in C++ which is using pointers and collections so In order to keep it simple and to keep it very intuitive We decided that we would don't want to use any code generation because just code generation usually is a step Where you have very little control over so our library doesn't use any code generation? We also Don't have any XML mapping definitions. I think adding an extra XML file separate from your relational database schema and separate from your C++ code only complicates things So we also decided to avoid any macro hacks So the whole library doesn't have any Macro which tries to hide the C++ from you you get exposed to all the C++ that is there and Of course, we try to be concise because we want to actually Save you from typing and save you from making errors rather than making things more complicated So this whole Effort started in only in September last year so that's when we got the idea that this should be possible in C++ and We had a first release in December and it's already being used online in our Home page where we use a blog that is implemented using DBO and that blog already get slash dotted So and it survived it very well. So I think it's already been a bit tested as well so Going straight to the code. This is how you would map fields in DBO onto a table. So imagine that you have a an entity user which you where you want to store user information and in C++ you want to describe this user class using Using Tree fields, for example, there's a string where we keep the name. There is a role which is an enum and There is a some karma that we assign to every user And the only thing that DBO adds to your class definition and you can use public or private fields or whatever But just to keep all my examples simple I'm going to use public fields, but you can obviously you can hide them and use Accessors so the only thing that you have to add that is DBO specific to your class definition is a persist method which takes a class an action class as a template argument and In that persist method you will simply declare how you map particular information from your class on to fields in your database So once you've done that for a particular class you can use it even the database so currently so here. I'm going to use our SQLite backend, which is a back in the DBO which is basically the only backend we currently have and Everything in DBO will Happen within the scope of a session and I will later talk a bit about why that is the case So in our session we're going to assign it to this Backend connection and then here is the actual mapping statement So you just say I want to map the class user on to the table user so this Together with the information on the previous slides provides all the mapping information and then one thing that we could already do is ask the session to create the tables in our database and This will Execute some SQL that looks like this based on the information from your class. So this is just to a Complete example the previous class in declaration together with this Statements you don't need any other code generation or other tool no XML mapping no Build time information. This will just work so Obviously we do not only want to create a table, but we also want to see how we can use the interaction between our Database and our program. So here we will persist a new object so Everything will happen within the scope of a transaction. So so this is a Transaction boundary and then here we simply create our new object So because we used public members regarding to just assign some information there and then here we're going to add our user to our session that we previously created and This statement will when we commit a transaction will insert the see will insert our user into the database and We are going to keep track of a user that is stored in the database using the special smart pointer class DBO pointer and This pointer class not only allows us to use it as a regular pointer But it also provides some meta information on our object that has been saved and for example one of this is the Database ID that was assigned to this object. So then we can keep track of that for other users Same thing for updating an object. So again, we're going to do this within a transaction So suppose that we have some DBO pointer that we accessed or that we retrieved or that we just saved from the database then we can just Inspect some property. So here we see the smart pointer use It behaves like a regular pointer to for reading information. However to modify information. We use the modify method which is available on our smart pointer to access a non writable copy of our object and So this modify operator will just mark that object is dirty and the next time you transmit Do you commit your transaction? It's going to flush this modifications to the database So this is again the sequel that will be generated. So in our sequel statements, you will see the typical sequel syntax for prepared statements. That's because all of our Generated sequel will use prepared statements and will use the real binding methods that are available in our in your database layer Same thing for queries. So again within a transaction This is how for example, you would find a single user with name Joe So from our session, we will use the find method which is templatized with the class of the objects that we want to retrieve and here we can specify the remaining part of the sequel query So everything after the select from part you can specify here and here we say where we want to have a name again, we use prepared statements and we will bind the parameter Joe to this first question mark Since we expect only one particular user that matches this query. We already Coerced the result into a DBO pointer If you had if this query would have resulted in many results You would it would throw an exception if there is no Joe With this that matches this criteria It will return a null DBO pointer, which just behaves like a normal null pointer Same thing for retrieving a collection. So here we start a result in a DBO collection and a DBO collection together with DBO point or the two main smart or the two classes in DBO that you will need to use to interact with Database objects So let's say that we find all the users with karma less than five so same thing we bind five to this positional parameter and We we retrieve the result in this DBO collection and this DBO collection really acts like an STL collection So we can use boost for each to iterate on all results and print some information on it So again, we commit our transaction In this case, this will not do really anything But the database mandates that you do everything within the scope of a transaction or actually or the DBO does that all right, so To give some more information on these two classes pointer and collection. So pointer is really a smart pointer class for objects and it facilitates a number of Features for our class. So an important thing of the smart pointer class is that it does memory management since in sequel you don't really have a good hierarchy of this objects has ownership of or this Table has ownership of records of this table. So this is not really part of sequel But this is how you would typically Implemented in C++ if you wouldn't use smart pointers With smart pointers, you don't have to bother about when a particular object should be deleted the date The the DBO will do that for you as soon as no references are no longer held in in your session So this memory management works in conjunction with the session object there is a right access using the Modified method which marks an object dirty and then there are several persistence method Methods available on the smart pointer. So you can explicitly flush a particular object You can remove the object which makes it transient again So the object is removed from the database, but your in-memory object can still be used And maybe you want to resave it later You can reread the latest database version from a particular object and we already saw how we could use the ID so same thing for a collection collection is an STL like container for query results and It's iterators implemented the lowest form of requirements for an STL iterator, which is an input iterator So the more interesting part or the actual more useful part of DBO is how you can map relations and Here we show how you can map a many to one relation. So Suppose that we want to allow our user to alter posts for example in a blog and most Most examples are about blocks these days. So this is not exception So what we do in our class user we're going to add a DBO collection of DBO pointers to posts and in our persistence method we will say that a user has many posts and are many posts so posts many to one user and user will be the field that corresponds to this User and so in class post we're simply going to say so a post is owned by a user here again We use the DBO pointer to just have a reference to the user and then in our persistence method We will state that this post belongs to a particular user user So obviously this string and this string has to match and that's how the library knows that they are At the two ends of the relation But other than that, there's nothing special about this. So after you've done this you can just assign values to the user you can inspect the user you can iterate through all the posts that that belong to a user and The database or the DBO layer will generate the necessary sequel to manipulate and to interact with these two Fields in your classes So this is almost the same. So it's even if you look at the effect. It's quite nice. So you can I can skip most of the Information because it's actually the same to do a many to many relationship. However here obviously this is going to be symmetrical so here instead of a Point to we also have a collection So now we will say that a post can have many tags and tags can be reused over posts So we have just a collection of tags We have just a collection of posts and he will say that a post has many tags and there are many too many tags To a post and then this particular field now has the meaning of the name of the joint table that we're going to use in Our database to connect these two information. So here you see exactly the same So how does this work? all of the magic really happens within this persist method and The library will Define several actions at the moment are nine to ten actions defined by the library and each action is responsible for a particular Action so there is One action that is responsible to load an event. There is one for saving an object is one to examine the transaction come out outcome and so on and so The DBO layer will visit your objects using this persist method and it will pass the right action That is applicable to what it wants to achieve. There are also traits classes specialized specialized for field types and We will avoid any loops of pointer objects in relations and this is how our shared pointer Memory management will work So there are some other features which I will briefly list So we already I already told you that we were using prepare statements throughout queries can also be More complex than the ones that we showed you can have composite results and it works together with a boost tuple to Result to start the results in currently only have a SQLite back end and I Welcome any questions about that There's built in There's built in an optimistic locking scheme for concurrency It's you a licensed and it's part of witty and If you want to see more information or a more extended tutorial, I recommend to just google for it on the or go to this URL on our website Thank you in minutes