<commit_before>#EasySQLite [![Build Status](https://travis-ci.org/tonilopezmr/Android-EasySQLite.svg?branch=master)](https://travis-ci.org/tonilopezmr/Android-EasySQLite) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.tonilopezmr/easysqlite/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.tonilopezmr/easysqlite) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-EasySQLite-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/1592)

Use easily the database SQLite on android using the DAO and transformer design patterns, I modified the library of the professor [@jvprofe][11], I learned it from him.

Basic methods are already implemented in the class `SQLiteDelegate<T>`, if you need further queries you should extend from it.

#How to use

####Import EasySQLite dependency:

Grab via maven:

```xml
<dependency>
    <groupId>com.github.tonilopezmr</groupId>
    <artifactId>easysqlite</artifactId>
    <version>2.0.1</version>
</dependency>
```

or gradle:

```gradle
compile 'com.github.tonilopezmr:easysqlite:2.0.1'
````

####1. Create the object Transformer which implements SQLiteTransformer<T>

```java
	public class SubjectTransformer implements SQLiteTransformer<SubjectEntity>{

	    public static final String ID = "id";
	    public static final String NAME = "name";

	    public static final String TABLE_NAME = "subject";
	    public static final String[] FIELDS = {ID, NAME};

	    @Override
	    public SubjectEntity transform(Cursor cursor) throws Exception {
	        int id = cursor.getInt(0);
	        String name = cursor.getString(1);
	        return new SubjectEntity(id, name);
	    }

	    @Override
	    public ContentValues transform(SubjectEntity dto) throws Exception {
	        ContentValues values = new ContentValues();
			//values.put(ID, dto.getId());   it is not necessary, autoincrement!
	        values.put(NAME, dto.getName());

	        return values;
	    }

	    @Override
	    public String getWhereClause(SubjectEntity dto) throws Exception {
	        return  ID+"="+dto.getId();
	    }

	    @Override
	    public SubjectEntity setId(SubjectEntity dto, Object id) throws Exception {
	        dto.setId((Integer.valueOf(id.toString())));
	        return dto;
	    }

	    @Override
	    public String[] getFields() throws Exception {
	        return FIELDS;
	    }

	    @Override
	    public String getTableName() throws Exception {
	        return TABLE_NAME;
	    }
	}
```
####2. Create the object DAO which extends SQLiteDelegate<T>

The `SQLiteDelegate<T>` has implemented the following methods:

    //Default methods implement with SQLiteDelegate
    T create(T dto)
    boolean update(T dto)
    T read(T id)
    Collection<T> readAll()
    boolean delete(T dto)
    boolean deleteAll()

```java
	public class SubjectDAO extends SQLiteDelegate<SubjectEntity> {

	    public SubjectDAO(SQLiteDatabase db) {
	        super(db, new SubjectTransformer());
	    }
		
	    //In the case you need more querys, write this for example:
	    public List<T> getSubjectsApproved() {
	    	...	    
	    }
	    
	}<commit_msg>Update README.md changed the return types<commit_after>#EasySQLite [![Build Status](https://travis-ci.org/tonilopezmr/Android-EasySQLite.svg?branch=master)](https://travis-ci.org/tonilopezmr/Android-EasySQLite) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.tonilopezmr/easysqlite/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.tonilopezmr/easysqlite) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-EasySQLite-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/1592)

Use easily the database SQLite on android using the DAO and transformer design patterns, I modified the library of the professor [@jvprofe][11], I learned it from him.

Basic methods are already implemented in the class `SQLiteDelegate<T>`, if you need further queries you should extend from it.

#How to use

####Import EasySQLite dependency:

Grab via maven:

```xml
<dependency>
    <groupId>com.github.tonilopezmr</groupId>
    <artifactId>easysqlite</artifactId>
    <version>2.0.1</version>
</dependency>
```

or gradle:

```gradle
compile 'com.github.tonilopezmr:easysqlite:2.0.1'
````

####1. Create the object Transformer which implements SQLiteTransformer<T>

```java
	public class SubjectTransformer implements SQLiteTransformer<SubjectEntity>{

	    public static final String ID = "id";
	    public static final String NAME = "name";

	    public static final String TABLE_NAME = "subject";
	    public static final String[] FIELDS = {ID, NAME};

	    @Override
	    public SubjectEntity transform(Cursor cursor) throws Exception {
	        int id = cursor.getInt(0);
	        String name = cursor.getString(1);
	        return new SubjectEntity(id, name);
	    }

	    @Override
	    public ContentValues transform(SubjectEntity dto) throws Exception {
	        ContentValues values = new ContentValues();
			//values.put(ID, dto.getId());   it is not necessary, autoincrement!
	        values.put(NAME, dto.getName());

	        return values;
	    }

	    @Override
	    public String getWhereClause(SubjectEntity dto) throws Exception {
	        return  ID+"="+dto.getId();
	    }

	    @Override
	    public SubjectEntity setId(SubjectEntity dto, Object id) throws Exception {
	        dto.setId((Integer.valueOf(id.toString())));
	        return dto;
	    }

	    @Override
	    public String[] getFields() throws Exception {
	        return FIELDS;
	    }

	    @Override
	    public String getTableName() throws Exception {
	        return TABLE_NAME;
	    }
	}
```
####2. Create the object DAO which extends SQLiteDelegate<T>

The `SQLiteDelegate<T>` has implemented the following methods:

    //Default methods implement with SQLiteDelegate
    T create(T dto)
    int update(T dto)
    T read(T id)
    Collection<T> readAll()
    boolean delete(T dto)
    int deleteAll()

```java
	public class SubjectDAO extends SQLiteDelegate<SubjectEntity> {

	    public SubjectDAO(SQLiteDatabase db) {
	        super(db, new SubjectTransformer());
	    }
		
	    //In the case you need more querys, write this for example:
	    public List<T> getSubjectsApproved() {
	    	...	    
	    }
	    
	}
{'fraction_non_alphanumeric': 0.11214805441316039, 'fraction_numerical': 0.0060107560898449855, 'mean_word_length': 3.462244177840508, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1807525', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1845, 'n_words': 505}