Coder Social home page Coder Social logo

parsekt's Introduction

ParseKt [EXPERIMENTAL]

Android CI

For more information about the ParseKt and its features, see the public documentation

Getting started

Initialize Parse using:

Parse.initialize(context,"appId", "clientKey", "masterKey", "http://127.0.0.1:1337/parse")

Objects

Extend ParseClass and annotate with @Serializable and @ParseClassName. Attach ParseClassCompation.

@Serializable
@ParseClassName("GameScore")
class GameScore(var score: Int, 
                var cheatMode: Boolean? = false, 
                var playerName: String? = null) : ParseClass() {
  companion object : ParseClassCompanion()
}

No further setup is required.

CRUD

Save using;

GameScore(100, false, "Test Player").save()

Fetch using:

GameScore(100, false, "Test Player").fetch()

Queries

You can call query builder on ParseObject or on all ParseClasses which have ParseClassCompanion object

Create simple queries using:

GameScore.query { greaterThanOrEqualTo(GameScore::score.name, 50) }

If you want to get by id:

ParseObject.query{}.get<GameScore>("objectId")

You can make compound queries by:

GameScore.query { lessThanOrEqualTo(GameScore::score.name, 50) }
  .or(GameScore.query { greaterThanOrEqualTo("score", 100) })

and queries:

GameScore.query { lessThanOrEqualTo(GameScore::score.name, 50) }
  .and(GameScore.query { greaterThanOrEqualTo("score", 100) })

Then get the result by one of the following:

val query = ParseObject.query { lessThanOrEqualTo(GameScore::score.name, 50) }

val scores = query.find<GameScore>() // Find all matching
val score = query.first<GameScore>() // Find first matching
val count = query.count<GameScore>() // Count matching

Live Queries

subscribe method on ParseQuery returns a Flow which can te observed. For example by collecting, new list matching the given query will be returned when there are changes.

query.subscribe<GameScore>().collect { 
    Log.i("ParseLiveQuery", it.toTypedArray().contentToString())
}

You can use map, reduce, filter and all other methods from the Flow over the list of matching the query items.

User

You can extend the default user to provide your own fields:

@Serializable
@ParseClassName("_User")
class AppParseUser(var phone: String? = null, var address: String? = null) : ParseUser() {
    companion object : ParseClassCompanion()
}

Then you can create user, assign all the data and sign up. New logins will save the user's data.

val user = AppParseUser().signup("john", "pass")

To login:

val user = AppParseUser().login("john", "pass")

The user is also an ParseObject so you can use save and fetch on it. And by attaching it ParseClassCompanion you can query over it like this:

val user = AppParseUser.query { equalsTo("username", "john")}.first()

parsekt's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.