Skip to content

Commit

Permalink
Merge pull request #1715 from agrosner/develop
Browse files Browse the repository at this point in the history
5.0.0-alpha2
  • Loading branch information
agrosner committed Mar 13, 2021
2 parents e5aea43 + 9a57e27 commit 590f3dd
Show file tree
Hide file tree
Showing 325 changed files with 8,530 additions and 6,322 deletions.
2 changes: 2 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# .github

17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@

![Image](https://github.com/agrosner/DBFlow/blob/develop/dbflow_banner.png?raw=true)

[![JitPack.io](https://img.shields.io/badge/JitPack.io-5.0.0alpha1-red.svg?style=flat)](https://jitpack.io/#Raizlabs/DBFlow) [![Android Weekly](http:https://img.shields.io/badge/Android%20Weekly-%23129-2CB3E5.svg?style=flat)](http:https://androidweekly.net/issues/issue-129) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-DBFlow-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1134)
[![JitPack.io](https://img.shields.io/badge/JitPack.io-5.0.0-alpha2-red.svg?style=flat)](https://jitpack.io/#Raizlabs/DBFlow) [![Android Weekly](http:https://img.shields.io/badge/Android%20Weekly-%23129-2CB3E5.svg?style=flat)](http:https://androidweekly.net/issues/issue-129) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-DBFlow-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1134)

DBFlow is fast, efficient, and feature-rich Kotlin database library built on SQLite for Android. DBFlow utilizes annotation processing to generate SQLite boilerplate for you and provides a powerful SQLite query language that makes using SQLite a joy.

DBFlow is built from a collection of some of the best features of many database libraries. Don't let an ORM or library get in your way, let the code you write in your applications be the best as possible.

Supports:
DBFlow Contains:

**Kotlin:** Built using the language, the library is super-concise, null-safe and efficient.

**Annotation Processor**: Generates the necessary code that you don't need to write.

**Core:** Contains the main annotations and misc classes that are shared across all of DBFlow.

**DBFlow:** The main library artifact used in conjunction with the previous two artifacts.

**Coroutines:** Adds coroutine support for queries.

**RX Java:** Enable applications to be reactive by listening to DB changes and ensuring your subscribers are up-to-date.

**Paging:** Android architecture component paging library support for queries via `QueryDataSource`.

**LiveData:** Android architecture LiveData support for queries on table changes.

**SQLCipher:** Easy database encryption support in this library.

**SQLite Query Language:** Enabling autocompletion on sqlite queries combined with Kotlin language features means SQLite-like syntax.
Expand Down Expand Up @@ -50,7 +58,7 @@ Add artifacts to your project:
```groovy
apply plugin: 'kotlin-kapt' // only required for kotlin consumers.
def dbflow_version = "5.0.0-alpha1"
def dbflow_version = "5.0.0-alpha2"
// or 10-digit short-hash of a specific commit. (Useful for bugs fixed in develop, but not in a release yet)
dependencies {
Expand Down Expand Up @@ -80,6 +88,9 @@ Add artifacts to your project:
// Android Architecture Components Paging Library Support
implementation "com.github.agrosner.dbflow:paging:${dbflow_version}"
// Android Architecture Components LiveData Library Support
implementation "com.github.agrosner.dbflow:livedata:${dbflow_version}"
// adds generated content provider annotations + support.
implementation "com.github.agrosner.dbflow:contentprovider:${dbflow_version}"
Expand Down
17 changes: 9 additions & 8 deletions SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# Table of contents

* [README](README.md)
* [GettingStarted](gettingstarted.md)
* [Usage Docs](usage2/README.md)
* [Including In Project](usage2/including-in-project.md)
* [Getting Started](usage2/gettingstarted.md)
* [Proguard](usage2/proguard.md)
* [Advanced Usage](usage2/advanced-usage/README.md)
* [Caching](usage2/advanced-usage/caching.md)
* [List Queries](usage2/advanced-usage/listbasedqueries.md)
* [Multiple Modules](usage2/advanced-usage/multiplemodules.md)
* [QueryModels](usage2/advanced-usage/querymodels.md)
* [Indexing](usage2/advanced-usage/indexing.md)
* [SQLCipher](usage2/advanced-usage/sqlciphersupport.md)
* [Main Usage](usage2/usage/README.md)
* [Databases](usage2/usage/databases.md)
* [Models](usage2/usage/models.md)
Expand All @@ -17,14 +24,8 @@
* [TypeConverters](usage2/usage/typeconverters.md)
* [Observability](usage2/usage/observability.md)
* [RXJavaSupport](usage2/rxjavasupport.md)
* [Advanced Usage](usage2/advanced-usage/README.md)
* [Caching](usage2/advanced-usage/caching.md)
* [ListBasedQueries](usage2/advanced-usage/listbasedqueries.md)
* [MultipleModules](usage2/advanced-usage/multiplemodules.md)
* [QueryModels](usage2/advanced-usage/querymodels.md)
* [Indexing](usage2/advanced-usage/indexing.md)
* [SQLCipher](usage2/advanced-usage/sqlciphersupport.md)
* [ContentProviderGeneration](usage2/contentprovidergeneration.md)
* [5.0 Migration Guide](usage2/5.0-migration-guide.md)
* [Migration4Guide](usage2/migration4guide.md)
* [ISSUE\_TEMPLATE](issue_template.md)

45 changes: 0 additions & 45 deletions build.gradle

This file was deleted.

25 changes: 25 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
buildscript {
repositories {
jcenter()
google()
gradlePluginPortal()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.2")
classpath("com.github.dcendents:android-maven-gradle-plugin:2.1")
classpath("com.getkeepsafe.dexcount:dexcount-gradle-plugin:2.0.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Kotlin}")
}
}

allprojects {
repositories {
jcenter()
google()
maven(url = "https://www.jitpack.io")
}
}

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
7 changes: 7 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

repositories {
jcenter()
}
24 changes: 24 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
object Versions {
const val Kotlin = "1.4.21"
const val TargetSdk = 28
const val MinSdk = 7
const val MinSdkRX = 16
const val SQLCipherMin = 7
const val ArchMin = 14
}

object Dependencies {
const val SqlCipher = "net.zetetic:android-database-sqlcipher:4.4.2"
const val RX = "io.reactivex.rxjava3:rxjava:3.0.4"
const val Coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2"
const val JavaPoet = "com.squareup:javapoet:1.11.1"
const val KPoet = "com.github.agrosner:KPoet:1.0.0"
const val JavaXAnnotation = "org.glassfish:javax.annotation:10.0-b28"
const val JUnit = "junit:junit:4.12"

object AndroidX {
const val Annotations = "androidx.annotation:annotation:1.1.0"
const val LiveData = "androidx.lifecycle:lifecycle-livedata:2.2.0"
const val Paging = "androidx.paging:paging-runtime:2.1.2"
}
}
19 changes: 0 additions & 19 deletions contentprovider-annotations/build.gradle

This file was deleted.

17 changes: 17 additions & 0 deletions contentprovider-annotations/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
}

// project.ext.artifactId = bt_name

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

dependencies {
api(project(":core"))
}

apply(from = "../kotlin-artifacts.gradle")
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ annotation class ContentProvider(
/**
* @return The base content uri String to use for all paths
*/
val baseContentUri: String = "")
val baseContentUri: String = "",

/**
* @return the holder class to pass to constructor of the ContentProvider so it will initialize before using DB.
*/
val initializeHolderClass: KClass<*> = Any::class)
36 changes: 0 additions & 36 deletions contentprovider/build.gradle

This file was deleted.

33 changes: 33 additions & 0 deletions contentprovider/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
id("com.android.library")
kotlin("android")
}

// project.ext.artifactId = bt_name

android {
compileSdkVersion(Versions.TargetSdk)

defaultConfig {
minSdkVersion(Versions.MinSdk)
targetSdkVersion(Versions.TargetSdk)
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

sourceSets {
getByName("main").java.srcDirs("src/main/kotlin")
}
}

dependencies {
api(project(":lib"))
api(project(":contentprovider-annotations"))
api(Dependencies.AndroidX.Annotations)
}

apply(from = "../kotlin-artifacts.gradle")

Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ protected constructor(databaseHolderClass: Class<out DatabaseHolder>? = null) :

override fun onCreate(): Boolean {
// If this is a module, then we need to initialize the module as part
// of the creation process. We can assume the framework has been general
// framework has been initialized.
// of the creation process. We can assume the framework has been initialized.
moduleClass
?.let { FlowManager.initModule(it) }
?: context?.let { FlowManager.init(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.dbflow5.provider
import android.content.ContentProvider
import com.dbflow5.config.FlowManager
import com.dbflow5.database.DatabaseWrapper
import com.dbflow5.database.FlowCursor
import com.dbflow5.query.OperatorGroup
import com.dbflow5.structure.BaseModel
import com.dbflow5.structure.Model
Expand All @@ -16,31 +15,29 @@ import com.dbflow5.structure.Model
*/
abstract class BaseProviderModel : BaseModel(), ModelProvider {

override fun delete(wrapper: DatabaseWrapper): Boolean = ContentUtils.delete(FlowManager.context, deleteUri, this) > 0
override fun delete(wrapper: DatabaseWrapper): Boolean = ContentUtils.delete(FlowManager.contentResolver, deleteUri, this) > 0

override fun save(wrapper: DatabaseWrapper): Boolean {
val count = ContentUtils.update(FlowManager.context, updateUri, this)
val count = ContentUtils.update(FlowManager.contentResolver, updateUri, this)
return if (count == 0) {
insert(wrapper) > 0
} else {
count > 0
}
}

override fun update(wrapper: DatabaseWrapper): Boolean
= ContentUtils.update(FlowManager.context, updateUri, this) > 0
override fun update(wrapper: DatabaseWrapper): Boolean = ContentUtils.update(FlowManager.contentResolver, updateUri, this) > 0

override fun insert(wrapper: DatabaseWrapper): Long
= if (ContentUtils.insert(FlowManager.context, insertUri, this) != null) 1 else 0
override fun insert(wrapper: DatabaseWrapper): Long = if (ContentUtils.insert(FlowManager.contentResolver, insertUri, this) != null) 1 else 0

/**
* Runs a query on the [ContentProvider] to see if it returns data.
*
* @return true if this model exists in the [ContentProvider] based on its primary keys.
*/
override fun exists(wrapper: DatabaseWrapper): Boolean {
val cursor = ContentUtils.query(FlowManager.context.contentResolver,
queryUri, modelAdapter.getPrimaryConditionClause(this), "")
val cursor = ContentUtils.query(FlowManager.contentResolver,
queryUri, modelAdapter.getPrimaryConditionClause(this), "")
val exists = cursor != null && cursor.count > 0
cursor?.close()
return exists
Expand All @@ -51,14 +48,10 @@ abstract class BaseProviderModel : BaseModel(), ModelProvider {
orderBy: String?,
wrapper: DatabaseWrapper,
vararg columns: String?): T? {
val cursor = ContentUtils.query(FlowManager.context.contentResolver,
queryUri, whereOperatorGroup, orderBy, *columns)
if (cursor != null) {
val flowCursor = FlowCursor.from(cursor)
if (flowCursor.moveToFirst()) {
val model: T = modelAdapter.loadFromCursor(flowCursor, wrapper) as T
flowCursor.close()
return model
ContentUtils.query(FlowManager.contentResolver,
queryUri, whereOperatorGroup, orderBy, *columns)?.use { cursor ->
if (cursor.moveToFirst()) {
return modelAdapter.loadFromCursor(cursor, wrapper) as T
}
}
return null
Expand Down
Loading

0 comments on commit 590f3dd

Please sign in to comment.