暴露是Kotlin語言JDBC驅動程序頂部的輕量級SQL庫。暴露有兩個數據庫訪問的口味:Typesafe SQL包裝DSL和輕型數據訪問對象(DAO)。
曝光後,您有兩個數據庫訪問的選項:包裝DSL和一個輕巧的DAO。我們的官方吉祥物是墨西哥魚,它以其出色的模仿能力而聞名,它使其能夠無縫地融合到任何環境中。與我們的吉祥物類似,暴露的可用於模仿各種數據庫引擎,這可以幫助您構建應用程序而無需對任何特定數據庫引擎的依賴性,並在幾乎沒有更改或沒有更改的情況下切換它們。
H2(版本2.x; 1.x版本已棄用,並將在以後的版本中刪除)
(也是使用PGJDBC-NG JDBC驅動程序的PostgreSQL)
Maven Central存儲庫可用暴露的釋放。您可以在構建腳本中聲明此存儲庫,如下所示:
警告:您可能需要將Kotlin JVM目標設置為8,並且在使用Spring到17時,才能正常工作:
存儲庫{//在0.30.1 // 0.30.1之前的版本不可用的nowmavencentral() }
Maven中央存儲庫默認是針對Maven用戶啟用的。
Exposed
由以下模塊組成:
裸露核 - 基本模塊,其中包含兩個DSL API以及映射
裸露的克里普特 - 提供其他列類型,以將加密數據存儲在DB中,並在客戶端編碼/解碼
裸露的dao -dao api
基於Java8 Time API
暴露-JDBC-基於Java JDBC API的運輸級別實現
暴露 - 院士 - 基於Jodatime庫的日期時間擴展
暴露 - JSON -JSON和JSONB數據類型擴展
曝光 - kotlin-datetime-基於kotlinx-datetime的日期時間擴展
暴露金錢 - 從“ Javax.money:Money-api”支持Monetaryamount的擴展名
裸露的 - 彈簧啟動器 - 彈簧靴的起動器,可將暴露為ORM而不是冬眠
<依賴項> <依賴項> <groupId> org.jetbrains.parped </groupId> <Artifactid>暴露核心</artifactid> <版本> 0.56.0 </version> </dependency> <依賴項> <groupId> org.jetbrains.parped </groupId> <Artifactid>暴露於crypt </artifactid> <版本> 0.56.0 </version> </dependency> <依賴項> <groupId> org.jetbrains.parped </groupId> <Artifactid>暴露於dao </artifactid> <版本> 0.56.0 </version> </dependency> <依賴項> <groupId> org.jetbrains.parped </groupId> <Artifactid>暴露於java time </artifactid> <版本> 0.56.0 </version> </dependency> <依賴項> <groupId> org.jetbrains.parped </groupId> <Artifactid>暴露-JDBC </artifactid> <版本> 0.56.0 </version> </dependency> <依賴項> <groupId> org.jetbrains.parped </groupId> <Artifactid>暴露於Jodatime </artifactid> <版本> 0.56.0 </version> </dependency> <依賴項> <groupId> org.jetbrains.parped </groupId> <Artifactid>暴露 - json </artifactid> <版本> 0.56.0 </version> </dependency> <依賴項> <groupId> org.jetbrains.parped </groupId> <Artifactid>暴露於kotlin-datetime </artifactid> <版本> 0.56.0 </version> </dependency> <依賴項> <groupId> org.jetbrains.parped </groupId> <Artifactid>暴露貨幣</artifactid> <版本> 0.56.0 </version> </dependency> <依賴項> <groupId> org.jetbrains.parped </groupId> <Artifactid>暴露於spring-boot-starter </artifactid> <版本> 0.56.0 </version> </dependency> </依賴項>
依賴項{ 實施'org.jetbrains.exposed:expaped-core:0.56.0'implementation'org.jetbrains.exped:expaped-crypt:0.56.0.56.0'impletation'org.jetbrains.jetbrains.exposed:exposed-exped-dao: 0.56.0'implementation'implementation'''implementation'''' org.jetbrains.exposed:exped-jdbc:0.56.0' 實施'org.jetbrains.exped:exped-jodatime:0.56.0'///orimplementation'org.jetbrains.exposed:Exposed-java time:0.56.0'//orimplementation'org.jetbrains'org.jetbrains.exposed: Expaped-kotsosed-kotlin--kotlin--kotlin--kotlin--日期:0.56.0' 實現'org.jetbrains.exposed:exped-json:0.56.0'implementation'org.jetbrains.exposed:Expausped-money:0.56.0'implementation'org.jetbrains.jetbrains.exposed:Spart-Spart-Spring-boot- boot-Starter:0.56。 0'}
在build.gradle.kts
中:
val暴露:串聯項目的字符串 依賴項{ 實現(“ org.jetbrains.exped:公開核: 實現(“ org.jetbrains.exped:公開crypt:brypt:bressposedversion”) 實現(“ org.jetbrains.exped:exped-dao:qublexposedversion”) 實現(“ org.jetbrains.exped:expaped-jdbc:jdbc:qublexposedversion”) 實現(“ org.jetbrains.exped:expaped-jodatime:$ exposedversion”)// orimplementation(“ org.jetbrains.exposed:exposed-java time:$ exposedversion'')// orimplementation(org.jetbrains.jetbrains.exposed: exposed:expposed -kotlin-datetime:$ exposedversion”) 實現(“ org.jetbrains.exped:expaused-json:json:qublesposedversion”) 實現(“ org.jetbrains.exped:公開 - 貨幣: 實現(“ org.jetbrains.exped:expaped-spring-boot-starter:qublexposedversion”) }
和gradle.properties
exposedVersion=0.56.0
查看樣品以快速啟動。
目前,可用於Maven/Gradle構建。檢查Maven Central並開始閱讀,以了解設置暴露的洞察力。
有關更多信息,請訪問以下鏈接:
文檔和示例和文檔
有助於暴露
遷移指南
破壞變化和任何遷移細節
鬆弛頻道
問題跟踪器
請注意,我們正在遠離GitHub問題,以報告錯誤和功能。請記錄YouTrack上的任何新請求。您必須登錄以查看和日誌問題,否則您將獲得404。
你有疑問嗎?請隨時請求邀請Kotlinlang Slack,並在我們的#POCT頻道加入項目對話。
我們積極歡迎您的拉力請求。但是,將您的工作與現有問題聯繫起來是首選。
分叉存儲庫,並從Main創建您的分支。
將您的分支命名為描述您正在做的工作的東西。 IE添加了新的東西。
如果您添加了應該測試的代碼,請添加測試並確保測試套件通過。
確保您解決任何棉絨警告。
如果您使現有代碼更好,請在您的公關描述中告訴我們。
有關更多詳細信息,請參見貢獻指南。
導入org.jetbrains.spard.sql。 id“,10)val名稱:列<string> = varchar(“名稱”,長度= 50)Val CityId:列<int?> =(integer(integer(“ city_id”)參考cities.id).nullable(nullable() primarykey = primarykey(id,name =“ pk_user_id”)//名稱是可選的} object cities:table(){val ID:column <int> = integer(“ id ”)。 > = varchar(“名稱”,50)Override val primarykey = primarykey(id,name =“ pk_cities_id”) } fun main(){database.connect(“ jdbc:h2:mem:test”,driver =“ org.h2.driver”,用戶=“ root”,password =“”) 交易 { addlogger(stdoutsqllogger)schemautils.create(城市,用戶)val saintpetersburgid = cities.insert { 它[name] =“聖彼得堡”}獲取城市。 it [name] =“慕尼黑”}獲取城市。 it.update(name,stringLiteral(“ prague”).trim()。子字符串(1,2)) } [cities.id] val praguename = cities.Selectall()。其中{cities.id eq pragueid} .single()[cities .oname] println(“ pragueName = $ pragueName = $ pragueName”)userer.insert. insert { it [id] =“ andrey” it [name] =“ andrey” it [users.cityid] = saintpetersburgid } users.insert { it [id] =“ sergey” it [name] =“ Sergey” it [users.cityid] = MunichId } users.insert { it [id] =“ eugene” it [name] =“ eugene” it [users.cityid] =慕尼黑 } users.insert { it [id] =“ Alex” it [name] =“ Alex” it [users.cityid] = null} users.insert { it [id] =“ smth” it [name] =“ shotse” it [users.cityid] = null} users.update({users.id eq'alex'}){ IT [name] =“ Alexey”} users.deletewhere {users.name suke like“%thing'} println(“所有城市:”)(cities in cities in cities in corit.Selectall()){println(“ $ { $ {city [city [cities cities。 id]}:$ {city [cities.name]}”) } println(“手動加入:”) (用戶Innerjoin Cities) .SELECT(users.name,cities.name) 。在哪裡 { (users.id.eq(“ andrey”)或users.name.eq(“ sergey”)andusers.id.eq(“ sergey”)和users.cityid.eq(cities.id) } .foreach {println(“ $ {it [users.name]}}生活在$ {it [cities.name]}”) } println(“加入外鍵:”) (用戶Innerjoin Cities) .SELECT(users.name,users.cityid,cities.name) 。 。 } else {println(“ $ {it [users.name]} } } println(“功能和組:”) ((城市Innerjoins用戶) 選擇(cities.name,users.id.count()) .groupby(cities.name) 。 ) } else {println(“沒有人生活在$ cityname中”) } } schemautils.drop(用戶,城市) } }
生成的SQL:
SQL:創建表(如果不存在)(ID int auto_increment,name varchar(50)而不是null,約束pk_cities_id primary鍵(id)) SQL:創建表如果不存在(ID VARCHAR(10),name varChar(50)不是null,city_id int null,約束pk_user_id primary鍵(id),約束FK_USERS_CITY_CITY_ID_ID_ID foreferial efirter(city_id)在更新限制中) SQL:插入城市(名稱)價值觀('St. Petersburg') SQL:插入城市(名稱)值('慕尼黑') SQL:插入城市(名稱)值(substring(trim('rague'),1,2)) sql:select cities.id,cities.name。來自cities.id = 3praguename = pr的城市 SQL:插入用戶(id,name,city_id)值('andrey','andrey',1) SQL:插入用戶(id,name,city_id)值('Sergey','Sergey',2) SQL:插入用戶(id,name,city_id)值('eugene','eugene',2) SQL:插入用戶(id,name,city_id)values('Alex','Alex',null) SQL:插入用戶(id,name,city_id)values('smth','sosings',null) sql:更新用戶設置名稱='lexey'where users.id ='alex'sql:從用戶中刪除用戶。 SQL:Select Cities.ID,城市。來自城市的名稱1:St. Petersburg2:Munich3:PR 手冊加入: sql:select users.name,cities.name來自用戶內在cities.id = user.city_id where((users.id ='andrey'))或(users.name ='sergey'))和(users.id.id ='Sergey')和(user.city_id = cities.id) Sergey用外國鑰匙居住在慕尼黑: sql:選擇user.name,user.city_id,cities.name。來自用戶內在的城市上的城市。 安德烈住在聖彼得堡 功能和組: SQL:Select Cities.Name,Count(user.ID)來自Cities Inner in cities.id = users.city_id group by cities.name1 user(s)live(s) )在慕尼黑 SQL:如果存在用戶,則DROV表 SQL:如果存在城市
導入org.jetbrains.exposed.dao。 .transactions.transactionObject用戶:intidtable(){val name = varchar(“ name”,50).index()val City =參考(“ city”,“ city”,cities)val age = integer = integer(“ age”) }對象城市:intidtable(){val name = varchar(“名稱”,50) } class用戶(id:entityId <int>):意向(id){companion object:intentityClass <user>(用戶)用戶var name by User.namevar City by city city referendeon用戶。用戶cityvar age.age.age。 } class City(ID:ENTITYID <int>):意圖(ID){companion object:intentityClass <City>(城市)var by cities.nameval用戶用戶推薦用戶users.nameval用戶。 } fun main(){database.connect(“ jdbc:h2:mem:test”,driver =“ org.h2.driver”,用戶=“ root”,password =“”) 交易 { addlogger(stdoutsqllogger)schemautils.create(城市,用戶)val stpete = city.new { name =“聖彼得堡”}瓦爾·慕尼黑=城市。 name =“慕尼黑”} user.new { name =“ a” a = stpete 年齡= 5} user.new { name =“ b” city = stpete 年齡= 27} user.new { 名稱=“ C”城市=慕尼黑 age = 42} println(“ coities:$ {city.all()。introsostring {it.name}}”)println(“ $ {stpete.name}中的用戶:$ {stpete.users.jointostring {it.name } }”)println(“成人:$ {user.find {user.age greateq 18} .jointostring {it.name}}”) } }
生成的SQL:
SQL:創建表格(如果不存在)(ID int auto_increment主鍵,name varchar(50)不是null) SQL:創建表如果不存在(ID int auto_increment primary鍵,name varchar(50)不是null,city int int int int not null,age int not null,限制fk_users_city__id forefertion foreferions forefrence foreference coreforences coreforess cories(id)delete delete限制更新的限制限制) SQL:在用戶(名稱)上創建index user_name SQL:插入城市(名稱)價值觀('St. Petersburg') SQL:插入城市(名稱)值('慕尼黑') SQL:選擇Cities.ID,城市。 城市:慕尼黑聖彼得堡 SQL:插入用戶(名稱,城市,年齡)值('a',1,5) SQL:插入用戶(名稱,城市,年齡)值('B',1,27) SQL:插入用戶(名稱,城市,年齡)值('C',2,42) sql:選擇用戶。 sql:select users.id,user.name,user.city,users。從用戶中的用戶。
請在貢獻前查看貢獻指南。
通過為裸露的項目做出貢獻,您同意您的貢獻將獲得Apache許可證版本2.0的許可。