It saves us many of the things that make working with databases really painful, so it’s a good alternative for simple databases. While it’s true that there are libraries that simplify much more the work with databases, for simple things Anko can be more than enough. With this parser and map delegate, you can parse directly the values from a map to a class. One interesting is the MapRowParser, which maps the columns to a map. To deal with the resulting cursor, Anko also provides us with different functions, such as parseSingle (for one result) or parseList (for several). You can see all the operations in Anko documentation. You can also apply all regular database operations such as limit, orderBy, having or groupBy. Personally in this case I find the second option simpler. All of them must be String in this case: select("Person") If you use this class, which extends SQLiteOpenHelper, you can create blocks of code where you will execute the database operations, as follows: e )",Īnd there is another, more similar to that used in the Android framework, which allows to include interrogation sign and values more later. Anko does this for you.įor this you need to include SQLite dependency for Anko: compile ':anko-sqlite:0.10.0' You’ll then need to remember to close after the requests. On Android, you’ll need a SQLiteOpenHelper, which you use to retrieve the database. You’ll see here how to create your database from scratch. With Anko, however, we can continue to work as low-level as when we use the framework, but get rid of some of the more tedious parts of its implementation. Truth to be told: writing databases in Android is quite boring.Īll the boilerplate required to work with SQLite is far from being the most delightful thing in the world.įortunately, there are already enough libraries that simplify this task, one of them announced during the latest Google I/O, called Room.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |