Skip to content

Commit e3916b7

Browse files
committed
Migrate database logic to Kotlin
Room has been convereted into a KMP library in the latest stable releases and annotation processing requires KSP which only generates kotlin classes Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
1 parent f3ca5f6 commit e3916b7

62 files changed

Lines changed: 1750 additions & 1973 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/schemas/org.schabi.newpipe.database.AppDatabase/9.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"formatVersion": 1,
33
"database": {
44
"version": 9,
5-
"identityHash": "7591e8039faa74d8c0517dc867af9d3e",
5+
"identityHash": "ab341245d5bddd358d50bd73ef2a8c56",
66
"entities": [
77
{
88
"tableName": "subscriptions",
@@ -443,7 +443,7 @@
443443
},
444444
{
445445
"tableName": "remote_playlists",
446-
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `service_id` INTEGER NOT NULL, `name` TEXT, `url` TEXT, `thumbnail_url` TEXT, `uploader` TEXT, `display_index` INTEGER NOT NULL, `stream_count` INTEGER)",
446+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `thumbnail_url` TEXT, `service_id` INTEGER NOT NULL, `url` TEXT, `uploader` TEXT, `display_index` INTEGER, `stream_count` INTEGER)",
447447
"fields": [
448448
{
449449
"fieldPath": "uid",
@@ -452,26 +452,26 @@
452452
"notNull": true
453453
},
454454
{
455-
"fieldPath": "serviceId",
456-
"columnName": "service_id",
457-
"affinity": "INTEGER",
455+
"fieldPath": "orderingName",
456+
"columnName": "name",
457+
"affinity": "TEXT",
458458
"notNull": true
459459
},
460460
{
461-
"fieldPath": "name",
462-
"columnName": "name",
461+
"fieldPath": "thumbnailUrl",
462+
"columnName": "thumbnail_url",
463463
"affinity": "TEXT",
464464
"notNull": false
465465
},
466466
{
467-
"fieldPath": "url",
468-
"columnName": "url",
469-
"affinity": "TEXT",
470-
"notNull": false
467+
"fieldPath": "serviceId",
468+
"columnName": "service_id",
469+
"affinity": "INTEGER",
470+
"notNull": true
471471
},
472472
{
473-
"fieldPath": "thumbnailUrl",
474-
"columnName": "thumbnail_url",
473+
"fieldPath": "url",
474+
"columnName": "url",
475475
"affinity": "TEXT",
476476
"notNull": false
477477
},
@@ -485,7 +485,7 @@
485485
"fieldPath": "displayIndex",
486486
"columnName": "display_index",
487487
"affinity": "INTEGER",
488-
"notNull": true
488+
"notNull": false
489489
},
490490
{
491491
"fieldPath": "streamCount",
@@ -724,7 +724,7 @@
724724
"views": [],
725725
"setupQueries": [
726726
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
727-
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7591e8039faa74d8c0517dc867af9d3e')"
727+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ab341245d5bddd358d50bd73ef2a8c56')"
728728
]
729729
}
730730
}

app/src/main/java/org/schabi/newpipe/NewPipeDatabase.java

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2017-2024 NewPipe contributors <https://newpipe.net>
3+
* SPDX-FileCopyrightText: 2025 NewPipe e.V. <https://newpipe-ev.de>
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
package org.schabi.newpipe
8+
9+
import android.content.Context
10+
import androidx.room.Room.databaseBuilder
11+
import org.schabi.newpipe.database.AppDatabase
12+
import org.schabi.newpipe.database.Migrations.MIGRATION_1_2
13+
import org.schabi.newpipe.database.Migrations.MIGRATION_2_3
14+
import org.schabi.newpipe.database.Migrations.MIGRATION_3_4
15+
import org.schabi.newpipe.database.Migrations.MIGRATION_4_5
16+
import org.schabi.newpipe.database.Migrations.MIGRATION_5_6
17+
import org.schabi.newpipe.database.Migrations.MIGRATION_6_7
18+
import org.schabi.newpipe.database.Migrations.MIGRATION_7_8
19+
import org.schabi.newpipe.database.Migrations.MIGRATION_8_9
20+
import kotlin.concurrent.Volatile
21+
22+
object NewPipeDatabase {
23+
24+
@Volatile
25+
private var databaseInstance: AppDatabase? = null
26+
27+
private fun getDatabase(context: Context): AppDatabase {
28+
return databaseBuilder(
29+
context.applicationContext,
30+
AppDatabase::class.java,
31+
AppDatabase.Companion.DATABASE_NAME
32+
).addMigrations(
33+
MIGRATION_1_2,
34+
MIGRATION_2_3,
35+
MIGRATION_3_4,
36+
MIGRATION_4_5,
37+
MIGRATION_5_6,
38+
MIGRATION_6_7,
39+
MIGRATION_7_8,
40+
MIGRATION_8_9
41+
).build()
42+
}
43+
44+
@JvmStatic
45+
fun getInstance(context: Context): AppDatabase {
46+
var result = databaseInstance
47+
if (result == null) {
48+
synchronized(NewPipeDatabase::class.java) {
49+
result = databaseInstance
50+
if (result == null) {
51+
databaseInstance = getDatabase(context)
52+
result = databaseInstance
53+
}
54+
}
55+
}
56+
57+
return result!!
58+
}
59+
60+
@JvmStatic
61+
fun checkpoint() {
62+
checkNotNull(databaseInstance) { "database is not initialized" }
63+
val c = databaseInstance!!.query("pragma wal_checkpoint(full)", null)
64+
if (c.moveToFirst() && c.getInt(0) == 1) {
65+
throw RuntimeException("Checkpoint was blocked from completing")
66+
}
67+
}
68+
69+
@JvmStatic
70+
fun close() {
71+
if (databaseInstance != null) {
72+
synchronized(NewPipeDatabase::class.java) {
73+
if (databaseInstance != null) {
74+
databaseInstance!!.close()
75+
databaseInstance = null
76+
}
77+
}
78+
}
79+
}
80+
}

app/src/main/java/org/schabi/newpipe/database/AppDatabase.java

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2017-2024 NewPipe contributors <https://newpipe.net>
3+
* SPDX-FileCopyrightText: 2025 NewPipe e.V. <https://newpipe-ev.de>
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
package org.schabi.newpipe.database
8+
9+
import androidx.room.Database
10+
import androidx.room.RoomDatabase
11+
import androidx.room.TypeConverters
12+
import org.schabi.newpipe.database.feed.dao.FeedDAO
13+
import org.schabi.newpipe.database.feed.dao.FeedGroupDAO
14+
import org.schabi.newpipe.database.feed.model.FeedEntity
15+
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
16+
import org.schabi.newpipe.database.feed.model.FeedGroupSubscriptionEntity
17+
import org.schabi.newpipe.database.feed.model.FeedLastUpdatedEntity
18+
import org.schabi.newpipe.database.history.dao.SearchHistoryDAO
19+
import org.schabi.newpipe.database.history.dao.StreamHistoryDAO
20+
import org.schabi.newpipe.database.history.model.SearchHistoryEntry
21+
import org.schabi.newpipe.database.history.model.StreamHistoryEntity
22+
import org.schabi.newpipe.database.playlist.dao.PlaylistDAO
23+
import org.schabi.newpipe.database.playlist.dao.PlaylistRemoteDAO
24+
import org.schabi.newpipe.database.playlist.dao.PlaylistStreamDAO
25+
import org.schabi.newpipe.database.playlist.model.PlaylistEntity
26+
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity
27+
import org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity
28+
import org.schabi.newpipe.database.stream.dao.StreamDAO
29+
import org.schabi.newpipe.database.stream.dao.StreamStateDAO
30+
import org.schabi.newpipe.database.stream.model.StreamEntity
31+
import org.schabi.newpipe.database.stream.model.StreamStateEntity
32+
import org.schabi.newpipe.database.subscription.SubscriptionDAO
33+
import org.schabi.newpipe.database.subscription.SubscriptionEntity
34+
35+
@TypeConverters(Converters::class)
36+
@Database(
37+
version = Migrations.DB_VER_9,
38+
entities = [
39+
SubscriptionEntity::class,
40+
SearchHistoryEntry::class,
41+
StreamEntity::class,
42+
StreamHistoryEntity::class,
43+
StreamStateEntity::class,
44+
PlaylistEntity::class,
45+
PlaylistStreamEntity::class,
46+
PlaylistRemoteEntity::class,
47+
FeedEntity::class,
48+
FeedGroupEntity::class,
49+
FeedGroupSubscriptionEntity::class,
50+
FeedLastUpdatedEntity::class
51+
]
52+
)
53+
abstract class AppDatabase : RoomDatabase() {
54+
55+
abstract fun searchHistoryDAO(): SearchHistoryDAO
56+
57+
abstract fun streamDAO(): StreamDAO
58+
59+
abstract fun streamHistoryDAO(): StreamHistoryDAO
60+
61+
abstract fun streamStateDAO(): StreamStateDAO
62+
63+
abstract fun playlistDAO(): PlaylistDAO
64+
65+
abstract fun playlistStreamDAO(): PlaylistStreamDAO
66+
67+
abstract fun playlistRemoteDAO(): PlaylistRemoteDAO
68+
69+
abstract fun feedDAO(): FeedDAO
70+
71+
abstract fun feedGroupDAO(): FeedGroupDAO
72+
73+
abstract fun subscriptionDAO(): SubscriptionDAO
74+
75+
companion object {
76+
const val DATABASE_NAME: String = "newpipe.db"
77+
}
78+
}

0 commit comments

Comments
 (0)