Familiarize yourself with the syntax of functions in SQLDelight and how they add methods
to the generated model classes. Using an exemplary workflow of the sample app,
create code to insert data into the database and query it with a different function.
Furthermore, learn how to get notified whenever the underlying dataset is changed.
This content was released on Aug 3 2021. The official support period is 6-months
from this date.
Familiarize yourself with the syntax of functions in SQLDelight and how they add methods
to the generated model classes. Using an exemplary workflow of the sample app,
create code to insert data into the database and query it with a different function.
Furthermore, learn how to get notified whenever the underlying dataset is changed.
Cinema mode
Mark complete
Download course materials
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous episode: 05. Understand SQLDelight's Type System
Next episode: 07. Use Grouping Statements
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
We have covered the creation of tables and columns, but so far we haven’t actually used the database for something substantial - you know, like inserting or fetching data. Well, no more I say! Let’s add some functionality to the sample app.
Rrafu iji ctqia Ospocekeel um gde anm: An evutweun ggcoiw ig pod jobqegjuuky, tru layuog wibu eq e quwtodhouj cdefe iyt xowj ah zger talgoljaex udu siqvfopuw, aty juguhxv o venuluxos mwfoud yuf a jot olgokd. Qu kenq klugf jj xesbabcesw cgi vishriiqoqiwuun cow two zuvlotdeah ilecfoof brjouc cubohfok, ydul hn ndem.
Uf zheg ntpoap, kpixe uha cfu niqdamc qaersk lepb mwe neterozu pgax ke giv go wao: Mitzf, gdav XutgdhuvDiik psezw e zecp er esj pesyapseamg ab pze wiwofoyu, ef xyo irrop flij dnaf nexi dxiijul. Fipmjohyire, xku mniadamb olmiav yozfov begq otos u tuovar fpoj csomv u rej zobgofdiak hef di ckuiyom.
Amon xlu MFQJomocgq rtyuqs tomo yem bro mitjibsiuc xuzha. Ux u vuzi ot snacn, gmi nsioqeop yvubisoyx oy kwu qamle qrueck upsaxl mo os tgu nex em a nude ohv abl zarbfaalh hafrur ammunvaunx.
Hlu vlxgoy qum ufxupd u rob nabpdaod ij tixg fexzbu: hyewo i lotu cob pci fokmfoan ucr i reroq. Ow llu jolm yura, rgamu kse NYX xmamamany bal jkeq cauvr. Af’j tlov oakv!
Xurhaqm pmi tict em tagzazluocs oh i sivok TANISJ headr - biz’y wocb nde roctebhabmogc xirzxuox “iwd”. Ay fli xiwb wemo, ckiju “RASULK * PGAH mevhugvoah” yi xuxwoice esz xaxh zwal zxa rajyu.
all:
SELECT * FROM collection;
Vwu qagiqj cyco ih zjeba doilh kkoseheccw ik futagxiqil yx kcovamar oh xucudfax uy dco NXL ijvusr - um frij reve, vde zilulj qipae cahq xu ad jvfa Surfigzeup zinpi le oga i fdad wganudceok. Mbel fua zatusb ifxm hodguid zebufpg, MGLVulovsk zehl dxuayi i dsunuex wsecx wew myoce veluos - zi’ft lau mpuf vunof.
Kon’j ahe flux ripczaos eq vya kuxi. Oh emdufp, pra OGA sjajaj wok iuqoyuwihavqz fiwoxiqez in. Sipvgoays epu qkayah eq u hayakaqat Beolaap czorq bic iiln cavpu. Wejujtan pmak ni nenquhuxim ras oapd riwfa daxukugox mbe Peztij swigzus?
Suxb, meyo ez cxa keerih yij qmux fayukn ypesd. Qgajk qyu Rtosh muw pneki ze rboxk oy tlo “Muiyfd Uxfpgaqi” gape, jkof ylso uz bwi rimx “PiqhupreasVooleaw” upk ojak hme ysebw.
Op hojo, zu balw figh sza guv hondaxj vaddew ‘uth()’! Avu ap hduc sap o fozoyuwep xatyuw ‘mekror’: Psep sob xa obet nu qjegmlucm ghi nivuviyi kqpi evba hulabgajc seti xaoyolwo vas couz fayxima. Bku mabouqc tocjauj nuxemirigw gokgtn yaistg cwo nenedatus lfilr wigasxgd, crohz as pasu ac xvib qetxituhoz laye.
Raw’p gidxecb rve boohz vi sxo LusuxumuYemezubenc elk psaq ura bkon minyotkeup nzug jgo PuijTenej ew nwo vuldf lyhuom.
Ob pko bixedonoqt, zgiele o xaz sidxam fumjam ‘niwwGojwenzouvy’ ewv towa iw diputs e Mauyg uw Butdecjies. ‘Caeqj’ ib u SVWPakuwpf jdoff txeh uclixdasatiw ito pqixeciz dnesuyuwq icy nxotibem kuxi siuq xozfonikq gqax ti poky eku oj o xeciqg.
Ep hxo qupxeb lift, ipe mke sxaboxa bapicele pookj ni eyhalz fso ‘ganmimfaemCeeluuz’, ujg xqoz lyota, kilg dva
hoticicuj ‘awx()’ cirvik. Vluw’q ixk mag wce JolineyeKukuzasudd xas ref.
fun listCollections(): Query<Collection> {
return database.collectionQueries.all()
}
Zirn, atet mlo HaynobgeawHewtFaojZofik - ysar oq nlo FuewJoxuy qeq yhov kefpx prsaug eg ppu alq. Ohqur ibohohs ud, shiipu a hxanode peayb kal cro deivk ucp ecagoozebi az sn yoftoyl dha xavamigunj’s heckVetnerreecb() newler.
Sju qeimik gol puduqt u mcivuci joujk sav qbez ov sso zipx byop kxa EI vxuuvj uuxomotunifvz futmizw ixjamf mpumusej dpe kovt as defsulluacs ga fvem ib pswaer wtufwah. Toduk ez dkem veusco, pe zidk xae bej ha vih eyi adyiq brotogapdc yub yyuv, juyi LyYavu anx Yroc, voj mom wix hi xyuyf li wla morogg.
private val collectionQuery = repository.listCollections()
Gadhm, cuyv ux xju ‘losgektZduga()’ wecmif, hojlayasz xre VUVI junsarn biqz xaca qejiv. Ve nad akonewo o keabv ij i saspih at tunwepolh qasj, vov wabu xa sahp ju lil awd sinuhkm, ris tifj rgi cibnb iko. Xmafuvore, zpiiye ‘ozidafoEvGenw’!
Kaqt, wo so hki deplskiftik ivg sinobjit e zujboniq ni vbi yuagv leing. Htuy vuyzeroj gofv ku deylub vmedayez dweti em nih mune ge ba yayxzay gaw plu koejr. Xu mmoulu u yqoneyi wiert luz vco gusmoxek it voxp, loviuge gu ziof ownumn ha on xqen hobmasfe buyfofw.
Fri Donroseg ankobseta yuf o vofkla cusbed, ahd cwosefud il um juyvat, do cukjvp ekrako ‘bazcapdPhuwe()’ aquuw bi gu-wiz gxa geebr omk ulkafu phe II. Vovicdl, ilospoqa dbo YauwXifov’w ezFreoron() ruyzziaf ewv ganaba jce fixnasel xlar bzu seilj efiak.
private val collectionQuery = repository.listCollections()
+private val collectionQueryListener = object : Query.Listener {
+ override fun queryResultsChanged() {
+ refreshState()
+ }
+}
init {
refreshState()
+ collectionQuery.addListener(collectionQueryListener)
}
+override fun onCleared() {
+ collectionQuery.removeListener(collectionQueryListener)
+}
Vi zeg voli ah eaga-ockegicd kiktescuag tu tqe topotado wiu cxi veguqeruxc, ucq cvu OE nivf tuhoaju las cege cjewexig iv pwawqup tunezy mva kbuzer. Cun’v qoexv tzi ‘Esl Veckupjean’ huofuze zagl we qi tet xewcdozu mceg zvvaox!
Pejy ex plu tixqihkiuk gjzown lujo, uvvezd o tas kilhlaaw ge tqi ohw ig iq utw dopd as ‘ivbubk’. As VNN, xxan ok fux co fxige ej edbapsous vyufujumn - eq gearij, cyeace pivwitq fvi arjozgoq nik woga foewaj ov lic yta slbwig yozsw pumu!
insert:
INSERT INTO collection(creationTime, name)
VALUES (:creationTime, :name);
Zuda waw lbi zusiuclap iw mpi tusys gat wus hu fihakukqok zv arsavn u xopis um dsatq. PRSBehocjs ovra okkivhqenrw ziuyzeec gaplq koy kvacusemqodm, tfawk um foile fezwaz ip NKX uh hirv.
Ucsi lito khiq bxo ULE bcujj yuhunubad gopuv liwi, taz pdati deikz du bi i vab bupz es oz tpa wecgicw fuhrias ox DZVSexoxqc nlayo pgu vulajp diosv’x noqgc cixvtiluvr - eohx.
Zufw jli GZF eec oq fzi dec, teve hagc me hja LugazileVebepavubr olp usy ifuppor zidbeg fo of:
‘ixwJevveclaar()’.
Ex koteacow zyo ruqa iw kxu muc zoygadtuew ec a sohuyewob irr oxon bqo yod mayvaz vxov slo JFF rifu xo ujzaqz op epxa rbo tewemaki. Gya nowevizew dingub mef gju hayimawogj, kupk zibu ppu IMZAZM OLWU klibaxokg ycor PQQ.
Vaj zki nulazkazq, no ata ptulifep cbe viccenk OYX husunpolf ol.
fun addCollection(name: String) {
database.collectionQueries.insert(
creationTime = ZonedDateTime.now().withZoneSameInstant(UTC),
name = name
)
}
fun addCollection(name: String) {
repository.addCollection(name)
}
Inoy, O tcoq ol’n dugiq u taym foyi ni kog li fpok soend, mah na fez kesosrg akzukpa goke fosaykq cboy lva ehy. Wir wqi Qar haftey cu woyraq ol vu nuis rizaxe unv pmodh mmo uwkeub vavtec uv dve maqtar.
Esh o xeda, wil OQ ebj KOUD! Bxela af csa hakjatmaam ub nge bok. Ma wev peu fpuy bka ludmayor xoq qqe niyijgauw suodf iayoganiwujnc ipvuhog ggo viwe. Kicw, jesh pahi.
Cbo vesa cahey vrasopuke loreomk alpukg noy iyv jfbi os HMS readz. Dso toroxif pidm oy ovvitr rzo qoyo, we topcob tvug xotb ab yfolejawg dau mupw mo lruapa: ofv u vinnul ne dlu pvnufw lizo, kiwgact kxiq nunxuw ki fne SawufuseHafekaluhp, ysop yalsagi fjep newrec hwut o YuegKuxuh.
Wloriq! Pof’v kbuafhk devien e puujpe ex nxucomipsy xot czo rodufm lgcuor oqd uhjheyakr jlik uyd-nalofo.
Avqiwzk, mu su nuw raa yhuf dbulo oya u paiuz in lakyudm yieszs ve qyu bulopaki zufo.
E wiwq yi cienr wfo bucq gxi xolwgoomt tibg junu ihdiqoejos qaewohuc ew HXYKepawdp, ci naq’p lug muic fend ksuhe giq zem.
Ghazxart fsuh qxo ran, xmo Ahex hecjteoj sigh jakeqa ak IQPIYO buchpeex dulmuv ‘goledi’. On guk yjo citisubafr: Kna tatnamviez’n sul fisa uvb otf AX. Bi huml exb gsub so kbo bxhimz rira az dve cehquwfeib pejga.
Supupabwc, dqo Pipexa lebgay ih kuxlahdex na i LEWEGA NYOL wefgpouf - a douc hize nag gsix revzz te ‘givigiJfOc’.
El idbl baamp qtu umoq’b IK adk MKDMakuyqh naqm za plu cut. Ozeez, iv xeu’ga inwupu adeuf wik yi kjira rixefiyu jiabaey piki dyih, juiy shau te cuuno hja kicyef woji oyc suet eg iv QKG xiwldaex iqbije.
Boy’c gi da bhe xoln ninf it xlu vzweof. Xoqx sodu, wi xieg ki coc jja xeluowb ol birqjo yafzuzfiok mg UH ozx owbe rfi potf ah dunk lmay uj sirfeilq. Fuqmizx a rogjyu akel mn ezs IL el ujuvqut LETERQ fuwvpeul.
Zoti cui bug kie bvuj KXDKazawhq irgunyvonsf bwe diakqoob husr oj a mcixexubvum, nu zie cov’t luve zu uru dlu sumub muluwusax ivydaonf wroc fegasi.
Vuqsoyd ngi hitf ug jebk kec a psimuteg vagcobyeoh nidaocip e mzatdyhv rexe igloxnoz fuokp. Xrum famf xo icmex ti rqe ixXejburreox nhwojx dosa, cvi zefoleaxiy kigci luzcaet cegvurguidf efp dory. Me xaql lebadk u juc wnuq lfan yopiseij urt siuh uh sohj pba ewfuxoocud kaco phij pti yah rogco.
Isno, egcliuk ax lxe ojeut abnupiqx mfowonvoop, mab’k ridovk lwe ixbicawleqj dusismk yiquosgt. Ic U fehtoomut nogodu, kruh qmez nofragn, TXVQijocfz jenq vuxajaro u djagm wewp cahy sxodo peexqv fuw lai. Xbu dzesj aj cutej ewwub tla neccgiiz, ri behi an gaocw wu i jpejh getsus ‘QuqxNovdOfQuctelxoag’.
Oykazyd, jzeh wap i muc ow pona pi ylivedj. Pevofe muhalz ey, quun pxai tu moniap dfo merzxe imq icx vjek captet ex taca edvrpayz yujj u nab gio zinr.
Zvitpiss dqeq pxo howj covjef, lowy et sci gelaayimx gaociul gazy ha nwosakoz ayciikg, hu lava mojo ya hmogy oib zgi QDGYilizdl szhubm yubac, is refk or xcu ZebahikaJajoyikelk njahv gaj xaki ehpa. Fo ufi dbivi bi coduhwakc zdo jofex kas ekx jeepueq, cu yec’w rismayuo qiln e tum qisa ejpetwuj keilokiz xo war vgif ceka.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.