Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
* Update `Kotlin`'s version to `2.2.20`
* Remove the Desuger configuration

### sqllin-dsl

* Optimized performance for SQL assembly
* New experimental API: `DatabaseScope#CREATE`
* New experimental API: `DatabaseScope#DROP`
* New experimental API: `DatabaseSceop#ALERT`

### sqllin-driver

* Update the `sqlite-jdbc`'s version to `3.50.3.0`
Expand Down
15 changes: 15 additions & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SQLlin Roadmap

## High Priority

* Support the key word REFERENCE
* Support JOIN sub-query
* Fix the bug of storing ByteArray in DSL

## Medium Priority

* Support WASM platform

## Low Priority

* Support store instances of kotlinx.datetime
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=1.4.4
VERSION=2.0.0
GROUP_ID=com.ctrip.kotlin

#Maven Publishing Information
Expand Down
26 changes: 14 additions & 12 deletions sample/src/commonMain/kotlin/com/ctrip/sqllin/sample/Sample.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

package com.ctrip.sqllin.sample

import com.ctrip.sqllin.driver.DatabaseConfiguration
import com.ctrip.sqllin.dsl.DSLDBConfiguration
import com.ctrip.sqllin.dsl.Database
import com.ctrip.sqllin.dsl.annotation.DBRow
import com.ctrip.sqllin.dsl.annotation.PrimaryKey
import com.ctrip.sqllin.dsl.sql.clause.*
import com.ctrip.sqllin.dsl.sql.clause.OrderByWay.DESC
import com.ctrip.sqllin.dsl.sql.statement.SelectStatement
Expand All @@ -30,34 +31,33 @@ import kotlinx.serialization.Serializable

/**
* Sample
* @author yaqiao
* @author Yuang Qiao
*/

object Sample {

private val db by lazy {
Database(
DatabaseConfiguration(
DSLDBConfiguration(
name = "Person.db",
path = databasePath,
version = 1,
create = {
// You must write SQL to String when the database is created or upgraded
it.execSQL("CREATE TABLE person (id INTEGER PRIMARY KEY AUTOINCREMENT, age INTEGER, name TEXT);")
it.execSQL("CREATE TABLE transcript (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, math INTEGER NOT NULL, english INTEGER NOT NULL);")
PersonTable {
CREATE()
}
this CREATE TranscriptTable
},
upgrade = { _, _, _ ->
// You must write SQL to String when the database is created or upgraded
}
upgrade = { _, _ -> }
),
enableSimpleSQLLog = true,
)
}

fun sample() {
val tom = Person(age = 4, name = "Tom")
val jerry = Person(age = 3, name = "Jerry")
val jack = Person(age = 8, name = "Jack")
val tom = Person(id = 0, age = 4, name = "Tom")
val jerry = Person(id = 1, age = 3, name = "Jerry")
val jack = Person(id = 2, age = 8, name = "Jack")

lateinit var selectStatement: SelectStatement<Person>
db {
Expand Down Expand Up @@ -113,13 +113,15 @@ object Sample {
@DBRow("person")
@Serializable
data class Person(
@PrimaryKey val id: Long?,
val age: Int?,
val name: String?,
)

@DBRow("transcript")
@Serializable
data class Transcript(
@PrimaryKey val id: Long?,
val name: String?,
val math: Int,
val english: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ package com.ctrip.sqllin.driver

/**
* SQLite Cursor common abstract
* @author yaqiao
* @author Yuang Qiao
*/

@OptIn(ExperimentalStdlibApi::class)
public interface CommonCursor : AutoCloseable {

public fun getInt(columnIndex: Int): Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.ctrip.sqllin.dsl.test

import com.ctrip.sqllin.driver.DatabaseConfiguration
import com.ctrip.sqllin.driver.DatabasePath
import com.ctrip.sqllin.dsl.DSLDBConfiguration
import com.ctrip.sqllin.dsl.Database
import com.ctrip.sqllin.dsl.sql.X
import com.ctrip.sqllin.dsl.sql.clause.*
Expand All @@ -41,9 +41,6 @@ class CommonBasicTest(private val path: DatabasePath) {

companion object {
const val DATABASE_NAME = "BookStore.db"
const val SQL_CREATE_BOOK = "create table book (id integer primary key autoincrement, name text, author text, pages integer, price real)"
const val SQL_CREATE_CATEGORY = "create table category (id integer primary key autoincrement, name text, code integer)"
const val SQL_CREATE_NULL_TESTER = "create table NullTester (id integer primary key autoincrement, paramInt integer, paramString text, paramDouble real)"
}

private inline fun Database.databaseAutoClose(block: (Database) -> Unit) = try {
Expand Down Expand Up @@ -429,12 +426,12 @@ class CommonBasicTest(private val path: DatabasePath) {
}

fun testNullValue() {
val config = DatabaseConfiguration(
val config = DSLDBConfiguration(
name = DATABASE_NAME,
path = path,
version = 1,
create = {
it.execSQL(SQL_CREATE_NULL_TESTER)
CREATE(NullTesterTable)
}
)
Database(config, true).databaseAutoClose { database ->
Expand Down Expand Up @@ -493,14 +490,14 @@ class CommonBasicTest(private val path: DatabasePath) {
}
}

private fun getDefaultDBConfig(): DatabaseConfiguration =
DatabaseConfiguration(
private fun getDefaultDBConfig(): DSLDBConfiguration =
DSLDBConfiguration (
name = DATABASE_NAME,
path = path,
version = 1,
create = {
it.execSQL(SQL_CREATE_BOOK)
it.execSQL(SQL_CREATE_CATEGORY)
CREATE(BookTable)
CREATE(CategoryTable)
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2025 Ctrip.com.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.ctrip.sqllin.dsl

import com.ctrip.sqllin.driver.DatabaseConfiguration
import com.ctrip.sqllin.driver.DatabasePath
import com.ctrip.sqllin.driver.JournalMode
import com.ctrip.sqllin.driver.SynchronousMode

/**
* DSL database configuration
* @author Yuang Qiao
*/

public data class DSLDBConfiguration(
val name: String,
val path: DatabasePath,
val version: Int,
val isReadOnly: Boolean = false,
val inMemory: Boolean = false,
val journalMode: JournalMode = JournalMode.WAL,
val synchronousMode: SynchronousMode = SynchronousMode.NORMAL,
val busyTimeout: Int = 5000,
val lookasideSlotSize: Int = 0,
val lookasideSlotCount: Int = 0,
val create: DatabaseScope.() -> Unit = {},
val upgrade: DatabaseScope.(oldVersion: Int, newVersion: Int) -> Unit = { _, _ -> },
) {
internal infix fun convertToDatabaseConfiguration(enableSimpleSQLLog: Boolean): DatabaseConfiguration = DatabaseConfiguration(
name,
path,
version,
isReadOnly,
inMemory,
journalMode,
synchronousMode,
busyTimeout,
lookasideSlotSize,
lookasideSlotCount,
create = {
val database = Database(it, enableSimpleSQLLog)
database {
create()
}
},
upgrade = { databaseConnection, oldVersion, newVersion ->
val database = Database(databaseConnection, enableSimpleSQLLog)
database {
upgrade(oldVersion, newVersion)
}
}
)
}
26 changes: 4 additions & 22 deletions sqllin-dsl/src/commonMain/kotlin/com/ctrip/sqllin/dsl/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,20 @@

package com.ctrip.sqllin.dsl

import com.ctrip.sqllin.driver.DatabaseConfiguration
import com.ctrip.sqllin.driver.DatabasePath
import com.ctrip.sqllin.driver.openDatabase
import com.ctrip.sqllin.driver.DatabaseConnection
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock

/**
* Database object
* @author yaqiao
* @author Yuang Qiao
*/

public class Database(
configuration: DatabaseConfiguration,
public class Database internal constructor(
private val databaseConnection: DatabaseConnection,
private val enableSimpleSQLLog: Boolean = false,
) {

public constructor(
name: String,
path: DatabasePath,
version: Int,
enableSimpleSQLLog: Boolean = false,
) : this(
DatabaseConfiguration(
name = name,
path = path,
version = version,
),
enableSimpleSQLLog,
)

private val databaseConnection = openDatabase(configuration)

/**
* Close the database connection.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2025 Ctrip.com.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.ctrip.sqllin.dsl

import com.ctrip.sqllin.driver.DatabaseConfiguration
import com.ctrip.sqllin.driver.DatabasePath
import com.ctrip.sqllin.driver.openDatabase

/**
* Factory functions for Database
* @author Yuang Qiao
*/

public fun Database(
configuration: DatabaseConfiguration,
enableSimpleSQLLog: Boolean = false,
): Database = Database(openDatabase(configuration), enableSimpleSQLLog)

public fun Database(
name: String,
path: DatabasePath,
version: Int,
enableSimpleSQLLog: Boolean = false,
): Database = Database(
DatabaseConfiguration(
name = name,
path = path,
version = version,
),
enableSimpleSQLLog
)

public fun Database(
dsldbConfiguration: DSLDBConfiguration,
enableSimpleSQLLog: Boolean = false,
): Database = Database(
configuration = dsldbConfiguration convertToDatabaseConfiguration enableSimpleSQLLog,
enableSimpleSQLLog = enableSimpleSQLLog,
)
Loading
Loading