Tag: sql

Spring JPA查询总是使用序列扫描而不是索引扫描

我有一个简单的查询 @Query(value = “select * from some_table where consumer_id=:consumerId and store_id=:storeId and cancelled_at is null”, nativeQuery = true) fun checkIfNewConsumer(consumerId: BigInteger, storeId: BigInteger): List 当我运行查询时,直接对超过3000万行的表进行解释 Index Scan using select_index on some_table (cost=0.56..8.59 rows=1 width=86) (actual time=0.015..0.015 rows=0 loops=1) Index Cond: ((consumer_id = 1234) AND (store_id = 4) AND (cancelled_at IS NULL)) Planning time: 0.130 ms […]

面向对象的小型到中型SQL数据库设计

作为一个个人项目,我想在Kotlin做一个“预算管理”应用程序,用户可以在其中输入价格和数量等各种项目和描述符。 我想将数据存储在H2数据库中,然后使用预定义的函数进行过滤和查看数据。 例如,如果用户想要知道他们在两个日期之间花了多少钱,或者他们的总支出在两个日期之间增加或减少了多少百分比,或者他们在用户定义的目标(例如储蓄账户)上的进展如何。 这是我的Github项目。 我正在使用SQL“Kotlin Exposed”API。 例如,这是我的“基本”表: package tables import org.jetbrains.exposed.sql.Column import org.jetbrains.exposed.sql.Table object Essential : Table() { val id: Column = Essential.integer(“id”).autoIncrement().primaryKey() val name: Column = Essential.varchar(“name”, length = 25) val desc: Column = Essential.varchar(“description”, length = 50) val price: Column = Essential.varchar(“price”, length = 9) val quant: Column = Essential.varchar(“quantity”, length = 25) […]

我怎样才能在房间持久库中动态的列名构造SQL查询

这是行不通的,我不知道我是否错了,或者是Android的房间的限制 @Query("SELECT * FROM foobar WHERE :column IN (:values)") fun getByFieldName(column: String, vararg values: String): Flowable<List<FooBar>>

从表中选择匹配的行,其中两列中的任何一列包含值列表中的任何值

你能帮我一个SQL查询的Microsoft SQL Server 2012数据库? 我有一个像这样的表结构: User ———————- Id int UserName nvarchar Likeable ——————— Id int Name nvarchar UserLike ———————- Id int UserId int LikeableId int Book ———————– Id int Name nvarchar Author nvarchar Description nvarchar AmazonUrl nvarchar 所以,为了得到用户喜欢的东西的名字,我使用这个查询: SELECT Name FROM [User] u JOIN UserLike ul ON u.Id = ul.UserId JOIN Likeable l ON l.Id […]

LINQ超过功能方法链的好处

在Kotlin Slack上讨论了添加代码树来支持像C#LINQ之类的可能性。 在C#中,LINQ有许多应用程序,但是我只想关注其中的一个(因为其他人已经可能被Kotlin语法覆盖):将SQL查询组合到远程数据库。 先决条件: 我们有一个SQL数据库的数据模式以某种方式表示在代码中,以便静态工具(或类型系统)可以检查SQL查询的正确性(至少是命名) 我们必须以字符串形式生成查询 我们想要一个接近SQL或Java流的语法 问题 :表达式树增加了哪些对于手头任务至关重要的语法? 没有它们,SQL构建器可以有多好?

如何使用eBean和Kotlin来表示带有额外字段的连接表?

我正在从规范作者/ book多对多关系示例向book_author表添加字段“角色”: create table author ( id bigint auto_increment not null, name varchar(255), constraint pk_author primary key (id) ); create table book ( id bigint auto_increment not null, title varchar(255), constraint pk_book primary key (id) ); create table book_author ( book_id bigint not null, author_id bigint not null, role varchar(255), constraint pk_book_author primary key (book_id,author_id) […]

Kotlin数据库错误CursorIndexOutOfBoundsException

这是错误的,它说索引超出界限,但我不能如何解决它,有一些土耳其语的话,但他们并不重要,我认为: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.burhanozen.nothesaplama, PID: 26919 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.burhanozen.nothesaplama/com.example.burhanozen.nothesaplama.MainActivity}: android.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) at …….. 我试图存储某种学生信息。 我有这些错误,我在下面分享代码。 这是我的MainActivity: override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val toolbar = findViewById(R.id.toolbar) as Toolbar setSupportActionBar(toolbar) val fab = findViewById(R.id.fab) as FloatingActionButton fab.setOnClickListener { […]

无法在Kotlin中运行“Where In”查询

我试图让这种查询(我正在与postgres)工作: select * from users where user_id in [1,2,3] 唯一的问题是查询不能用这种[1,2,3]的列表工作,只能使用这种类型(1,2,3)。 我试图将列表[1,2,3]转换为列表(1,2,3),但在Kotlin它并没有让我这样做.. 我会喜欢一些帮助。