Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A modern database abstraction layer + runtime, batteries included [WIP].

License

NotificationsYou must be signed in to change notification settings

vmanot/SwiftDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Important

This package is under development and is being currently rewritten to fully leverage Swift 5.9.

A modern, type-safe database abstraction layer. SwiftDB aims to be an opinionated DBAL for relational and document-oriented databases.

Get Started

Define anEntity:

structFoo:Entity,Identifiable{@Attributevarbar:String="Untitled"varid:someHashable{        bar}}

Define aSchema:

structMySchema:Schema{varentities:Entities{Foo.self}}

Create aContentView for your application:

structContentView:View{@StateObjectvarcontainer=PersistentContainer(MySchema())varbody:someView{Text("Hello World")}}

Create a list view:

structListView:View{@EnvironmentObjectvarcontainer:PersistentContainer@QueryModels<Foo>()varmodelsvarbody:someView{NavigationView{List(models){ fooinNavigationLink(destination:EditView(foo: foo)){Text(foo.bar)}.contextMenu{Button{                        container.delete(foo)} label:{Text("Delete")}}}.navigationBarItems(                trailing:Button{                    container.create(Foo.self)} label:{Image(systemName:.plusCircleFill).imageScale(.large)}).navigationBarTitle("A List of Foo")}}structEditView:View{@EnvironmentObjectvarcontainer:PersistentContainerletfoo:Foovarbody:someView{VStack{Form{TextField("Enter a value", text: foo.$bar){                        container.save()}}}.navigationBarTitle("Edit Foo")}}}

Add it to ourContentView:

structContentView:View{@StateObjectvarcontainer=PersistentContainer(MySchema())varbody:someView{ListView().databaseContainer(container)}}

That's it.

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp