https://github.com/razaghimahdi/sql-delight-example01
sql-delight example, a plugin by Square which is pure kotlin and it is useful in kmm
https://github.com/razaghimahdi/sql-delight-example01
android coroutines database kotlin sql sqldelight sqldelight-sample
Last synced: about 2 months ago
JSON representation
sql-delight example, a plugin by Square which is pure kotlin and it is useful in kmm
- Host: GitHub
- URL: https://github.com/razaghimahdi/sql-delight-example01
- Owner: razaghimahdi
- License: gpl-3.0
- Created: 2021-11-26T08:55:49.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-06-02T07:36:12.000Z (about 3 years ago)
- Last Synced: 2025-01-01T20:24:46.900Z (over 1 year ago)
- Topics: android, coroutines, database, kotlin, sql, sqldelight, sqldelight-sample
- Language: Kotlin
- Homepage:
- Size: 123 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SQL Delight Example01
## Developed by Mahdi Razzaghi Ghaleh
**simple example of sql-delight**
## Give a Star! ⭐
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
### What is SqlDelight?
Kotlin Multiplatform is one of the most interesting trends in mobile development this year.
It's dedicated to sharing the code between many different platforms, including mobile ones — Android and iOS.
SQLDelight generates typesafe kotlin APIs from your SQL statements. It verifies your schema, statements,
and migrations at compile-time and provides IDE features like autocomplete and refactoring which make writing and maintaining SQL simple.
### SqlDelight and Coroutine
One of the main reasons behind the success of the jetpack Room database library is that
it’s easy to use and compatible with popular frameworks like coroutines, and paging.
SQL Delight also has that benefit;
we only need to add the following line under the dependencies node inside the app level Gradle file to make it work.
**Look at these examples:**
```kotlin
/**
* we need to use AndroidSqliteDriver to write the data into the android database which persists across app launches.
* */
val context = LocalContext.current
val androidSqlDriver = AndroidSqliteDriver(
schema = Database.Schema,
context = context,
name = "user.db"
)
/**Then we need to get hold of the queries that we’ve created inside database.sql file.*/
val queries = Database(androidSqlDriver).userDbQueries
val users = queries.selectAll().executeAsList().map { it.toUser() }
```
#### Some Ideas:
- **https://cashapp.github.io/sqldelight/**
- **https://github.com/cashapp/sqldelight**
- **https://betterprogramming.pub/getting-started-with-sqldelight-in-android-development-eecd0ae9bbdd**
- **https://medium.com/xorum-io/migration-from-room-to-sqldelight-28d6f4aaf31e**