-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
72 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
modules/persistence/src/commonMain/kotlin/com.sphereon.oid.fed.persistence/Persistence.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import com.sphereon.oid.fed.persistence.Database | ||
import com.sphereon.oid.fed.persistence.repositories.AccountRepository | ||
|
||
expect class Persistence { | ||
val database: Database | ||
val accountRepository: AccountRepository | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
.../src/commonMain/kotlin/com/sphereon/oid/fed/persistence/repositories/AccountRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package com.sphereon.oid.fed.persistence.repositories | ||
import com.sphereon.oid.fed.openapi.models.Account | ||
import com.sphereon.oid.fed.persistence.Database | ||
|
||
interface AccountRepository { | ||
fun findById(id: UInt): Account? | ||
fun findById(id: Int): Account? | ||
fun findByUsername(username: String): Account? | ||
fun create(account: Account) | ||
} | ||
|
||
expect fun AccountRepository(): AccountRepository | ||
expect fun AccountRepository(database: Database): AccountRepository |
27 changes: 27 additions & 0 deletions
27
modules/persistence/src/commonMain/sqldelight/Account/Account.sq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CREATE TABLE account ( | ||
id SERIAL PRIMARY KEY, | ||
username VARCHAR(255) UNIQUE NOT NULL, | ||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
deleted_at TIMESTAMP | ||
); | ||
|
||
CREATE INDEX account_username_index ON account (username); | ||
|
||
selectAll: | ||
SELECT * FROM account; | ||
|
||
create: | ||
INSERT INTO account (username) VALUES (?); | ||
|
||
delete: | ||
UPDATE account SET deleted_at = CURRENT_TIMESTAMP WHERE id = ?; | ||
|
||
findByUsername: | ||
SELECT * FROM account WHERE username = ?; | ||
|
||
findById: | ||
SELECT * FROM account WHERE id = ?; | ||
|
||
update: | ||
UPDATE account SET username = ? WHERE id = ?; |
10 changes: 0 additions & 10 deletions
10
modules/persistence/src/commonMain/sqldelight/com/sphereon/sqldelight/account/Account.sq
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
modules/persistence/src/commonMain/sqldelight/com/sphereon/sqldelight/kms/KmsEnum.sq
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 8 additions & 12 deletions
20
...src/jvmMain/kotlin/com.sphereon.oid.fed.persistence.repositories/AccountRepository.jvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
package com.sphereon.oid.fed.persistence.repositories | ||
|
||
import Account.AccountQueries | ||
import com.sphereon.oid.fed.persistence.Database | ||
import app.cash.sqldelight.Query | ||
import com.sphereon.oid.fed.openapi.models.Account | ||
|
||
private class JvmAccountRepository() : AccountRepository { | ||
|
||
override fun findById(id: UInt): Account? { | ||
return null | ||
} | ||
|
||
override fun findByUsername(username: String): Account? { | ||
return null | ||
} | ||
|
||
override fun create(account: Account) { | ||
private class JvmAccountRepository(database: Database) : AccountRepository { | ||
private val accountQueries: AccountQueries = database.accountQueries | ||
|
||
override fun findById(id: Int): Account? { | ||
return accountQueries.findById(id).executeAsOneOrNull() | ||
} | ||
} | ||
|
||
actual fun AccountRepository(): AccountRepository = JvmAccountRepository() | ||
actual fun AccountRepository(database: Database): AccountRepository = JvmAccountRepository(database) |
14 changes: 14 additions & 0 deletions
14
modules/persistence/src/jvmMain/kotlin/com.sphereon.oid.fed.persistence/Persistence.jvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import com.sphereon.oid.fed.persistence.Database | ||
import com.sphereon.oid.fed.persistence.repositories.AccountRepository | ||
|
||
actual class Persistence { | ||
actual val database: Database | ||
actual val accountRepository: AccountRepository | ||
|
||
init { | ||
println("Persistence created") | ||
val driver = PlatformSqlDriver().createPostgresDriver("jdbc:postgresql://localhost:5432/oid_fed", "oid_fed", "oid_fed") | ||
database = Database(driver) | ||
accountRepository = AccountRepository(database) | ||
} | ||
} |