All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.appwrite.Query.kt Maven / Gradle / Ivy

Go to download

Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Kotlin SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)

There is a newer version: 6.1.0
Show newest version
package io.appwrite

class Query {
  companion object {
    fun equal(attribute: String, value: Any) = addQuery(attribute, "equal", value)

    fun notEqual(attribute: String, value: Any) = Query.addQuery(attribute, "notEqual", value)

    fun lessThan(attribute: String, value: Any) = Query.addQuery(attribute, "lessThan", value)

    fun lessThanEqual(attribute: String, value: Any) = Query.addQuery(attribute, "lessThanEqual", value)

    fun greaterThan(attribute: String, value: Any) = Query.addQuery(attribute, "greaterThan", value)

    fun greaterThanEqual(attribute: String, value: Any) = Query.addQuery(attribute, "greaterThanEqual", value)
    
    fun search(attribute: String, value: String) = Query.addQuery(attribute, "search", value)

    fun isNull(attribute: String) = "isNull(\"${attribute}\")"

    fun isNotNull(attribute: String) = "isNotNull(\"${attribute}\")"

    fun between(attribute: String, start: Int, end: Int) = Query.addQuery(attribute, "between", listOf(start, end))

    fun between(attribute: String, start: Double, end: Double) = Query.addQuery(attribute, "between", listOf(start, end))

    fun between(attribute: String, start: String, end: String) = Query.addQuery(attribute, "between", listOf(start, end))

    fun startsWith(attribute: String, value: String) = Query.addQuery(attribute, "startsWith", value)

    fun endsWith(attribute: String, value: String) = Query.addQuery(attribute, "endsWith", value)

    fun select(attributes: List) = "select([${attributes.joinToString(",") { "\"$it\"" }}])"

    fun orderAsc(attribute: String) = "orderAsc(\"${attribute}\")"

    fun orderDesc(attribute: String) = "orderDesc(\"${attribute}\")"

    fun cursorBefore(documentId: String) = "cursorBefore(\"${documentId}\")"

    fun cursorAfter(documentId: String) = "cursorAfter(\"${documentId}\")"

    fun limit(limit: Int) = "limit(${limit})"

    fun offset(offset: Int) = "offset(${offset})"

    private fun addQuery(attribute: String, method: String, value: Any): String {
      return when (value) {
        is List<*> -> "${method}(\"${attribute}\", [${value.map{it -> parseValues(it!!)}.joinToString(",")}])"
    	  else -> "${method}(\"${attribute}\", [${Query.parseValues(value)}])"
      }
    }
    private fun parseValues(value: Any): String {
      return when (value) {
        is String -> "\"${value}\""
    	  else -> "${value}"
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy