Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Sugar ORM?

I am developing one application and now I need to use database in my application. I wanna use Sugar ORM, but I didn't find "actual" documentation and "actual" version on Maven (I found 1.3 and 1.4 versions). Can somebody share information or links about Sugar ORM?

For example, when I create a model I take error cause class SugarRecord doesn't exist

like image 879
Alex.Marynovskyi Avatar asked Mar 15 '23 00:03

Alex.Marynovskyi


2 Answers

You can find all informations in the Getting started documentation. For the maven repository see here .

like image 54
lifeisfoo Avatar answered Mar 23 '23 13:03

lifeisfoo


You can follow the simple steps in this webiste: http://satyan.github.io/sugar/

I'm assuming you are using Android Studio, add this line to your build.gradle (Module app) file under dependencies. compile 'com.github.satyan:sugar:1.4'

Then add the following lines to your AndroidManifest file:

<application android:label="@string/app_name" android:icon="@drawable/icon"
android:name="com.orm.SugarApp">
.
.
<meta-data android:name="DATABASE" android:value="sugar_example.db" />
<meta-data android:name="VERSION" android:value="2" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.example" />
.
.
</application>

Then all your object classes must extend SugarRecord.

When you create a new object, it creates the entity by itself. Remember to add an empty constructor because for some reason, if you dont have it wont store it. Also remember to add the permissions required in case you are reading from the internet a JSON service. Once you have an object created, you can use .save() to store it in the datebase, but when you update use .commit()

The oficial steps are in their website: http://satyan.github.io/sugar/getting-started.html

I hope it helps you.

like image 31
Isaac Urbina Avatar answered Mar 23 '23 13:03

Isaac Urbina