{"id":20308775,"url":"https://github.com/ologe/android-content-resolver-sql","last_synced_at":"2025-04-11T15:40:25.866Z","repository":{"id":98667239,"uuid":"186473095","full_name":"ologe/android-content-resolver-SQL","owner":"ologe","description":"One function library that allows to use SQL statements on ContentResolver class","archived":false,"fork":false,"pushed_at":"2020-04-11T14:09:19.000Z","size":166,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-25T11:49:20.616Z","etag":null,"topics":["android","android-library","contentprovider","sql","sqlite","sqlite-android"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ologe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-13T18:18:28.000Z","updated_at":"2023-09-08T17:53:45.000Z","dependencies_parsed_at":"2023-05-03T15:02:43.088Z","dependency_job_id":null,"html_url":"https://github.com/ologe/android-content-resolver-SQL","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ologe%2Fandroid-content-resolver-SQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ologe%2Fandroid-content-resolver-SQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ologe%2Fandroid-content-resolver-SQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ologe%2Fandroid-content-resolver-SQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ologe","download_url":"https://codeload.github.com/ologe/android-content-resolver-SQL/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248432867,"owners_count":21102458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","contentprovider","sql","sqlite","sqlite-android"],"created_at":"2024-11-14T17:23:55.229Z","updated_at":"2025-04-11T15:40:25.857Z","avatar_url":"https://github.com/ologe.png","language":"Kotlin","readme":"[github]:            https://github.com/ologe/android-content-resolver-SQL\n[paypal-url]:        https://paypal.me/nextmusicplayer\n\n[platform-badge]:   https://img.shields.io/badge/Platform-Android-F3745F.svg\n[paypal-badge]:     https://img.shields.io/badge/Donate-Paypal-F3745F.svg\n[minsdk-badge]:     https://img.shields.io/badge/minSdkVersion-16-F3745F.svg\n\n\n\u003c!-------------------------------------------------------------------------------------------------------\u003e\n\nContent Resolver SQL\n=\n\n[![platform-badge]][github]\n[![minsdk-badge]][github]\n[![paypal-badge]][paypal-url]\n[![](https://jitpack.io/v/ologe/android-content-resolver-SQL.svg)](https://jitpack.io/#ologe/android-content-resolver-SQL)\n\n\nAllows to write SQL statements instead of using `contentResolver.query(...)`. \nThe library add an extension function to ContentResolver named \n`querySql(query: String, selectionArgs: Array\u003cString\u003e? = null)`\n\n### Limitations\n- When using `LIMIT` keyword, you need to specify also `ORDER BY`.\u003cp\u003e\n- When using `GROUP BY` keyword, you need to specify also  `WHERE`.\u003cp\u003e\n- You can use `WHERE 1 GROUP BY` if you haven’t a `WHERE` condition\n- `JOIN` are not supported by android content provider itself.\n\n## Getting started\nStep 1. Add the JitPack repository to your build file\nAdd it in your root build.gradle at the end of repositories:\n```groovy\nallprojects {\n    repositories {\n        ...\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\nStep 2. Add the dependency\n```groovy\nimplementation 'com.github.ologe:android-content-resolver-SQL:1.2.2'\n```\n\n## Example 1\n**Get all songs**\n```kotlin\nval query = \"\"\" \n    SELECT *\n    FROM ${Media.EXTERNAL_CONTENT_URI}\n\"\"\" \ncontentResolver.querySql(query)\n```\n**instead of**\n```kotlin\ncontentResolver.query(Media.EXTERNAL_CONTENT_URI, null, null, null, null)\n```\n## Example 2\n\n**Get first 10 artists offsetted by 2, that have at least 5 tracks and 2 albums, excluding the podcast, ordered by artist desc**\n```kotlin\nval query = \"\"\"\n    SELECT distinct $ARTIST_ID, $ARTIST, count(*) as songs, count(distinct $ALBUM_ID) as albums\n    FROM ${Media.EXTERNAL_CONTENT_URI}\n    WHERE $IS_PODCAST = 0\n    GROUP BY $ARTIST_ID\n    HAVING songs \u003e= 5 AND albums \u003e= 2\n    ORDER BY $ARTIST_KEY DESC\n    LIMIT 10\n    OFFSET 2\n\"\"\"\ncontentResolver.querySql(query)\n```\n**instead of**\n```kotlin\ncontentResolver.query(\n    uri = Media.EXTERNAL_CONTENT_URI,\n    projection = arrayOf(\n        \"distinct $ARTIST_ID\", \n        ARTIST, \n        \"count(*) as songs\", \n        \"count(distinct $ALBUM_ID) as albums\"\n    ),\n    selection = \"$IS_PODCAST = 0 ) GROUP BY $ARTIST_ID HAVING (songs \u003e= 5 AND albums \u003e= 2\",\n    selectionArgs = null,\n    sortOrder = \"$ARTIST_KEY DESC LIMIT 20 OFFSET 2\"\n)\n```\n","funding_links":["https://paypal.me/nextmusicplayer"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fologe%2Fandroid-content-resolver-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fologe%2Fandroid-content-resolver-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fologe%2Fandroid-content-resolver-sql/lists"}