微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Kotlin公开版中实现表继承?

如何解决如何在Kotlin公开版中实现表继承?

示例:

我有一个名为Pet的基表,其中包含BirthDateName列。

我从该表派生了另外两个表,一个表名为NumberOfTeeth的称为PetDog表,另一个表为BeakColor的另一个名为PetBird表。

如何使用Kotlin Exposed实现此功能https://github.com/JetBrains/Exposed

或者对此有任何文档吗?

解决方法

您打算使用哪种数据库和架构?它如何支持表继承?正如评论中已经提到的Михаил Нафталь一样,关系数据库的一种常见方法是要么使用一个包含所有列的表,要么使用两个表(petdog,并通过某种方式进行链接在两个表中的记录彼此)。

具有两个表的简单示例:

create table pet (id int auto_increment primary key,birthdate varchar(10) not null,"name" varchar(50) not null)
create table dog (id int auto_increment primary key,pet_id int null,number_of_teeth int not null,constraint fk_dog_pet_id_id foreign key (pet_id) references pet(id) on delete restrict on update restrict)

您公开的表定义代码可能看起来像这样:

object Pet : IntIdTable() {
    val birthdate = varchar("birthdate",10)
    val name = varchar("name",50)
}

object Dog : IntIdTable() {
    val petId = reference("pet_id",Pet).nullable()
    val numberOfTeeth = integer("number_of_teeth")
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。