-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26c57bb
commit 25cb251
Showing
6 changed files
with
86 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import BSON | ||
import MongoQL | ||
|
||
struct Article:Equatable, Hashable, | ||
BSONDocumentDecodable, | ||
BSONDocumentEncodable, | ||
Mongo.MasterCodingModel | ||
{ | ||
let id:BSON.Identifier | ||
let author:String | ||
let title:String | ||
let views:Int | ||
let tags:[String] | ||
|
||
init(id:BSON.Identifier, | ||
author:String, | ||
title:String, | ||
views:Int, | ||
tags:[String]) | ||
{ | ||
self.id = id | ||
self.author = author | ||
self.title = title | ||
self.views = views | ||
self.tags = tags | ||
} | ||
|
||
enum CodingKey:String, Sendable | ||
{ | ||
case id = "_id" | ||
case author | ||
case title | ||
case views | ||
case tags | ||
} | ||
|
||
init(bson:BSON.DocumentDecoder<CodingKey>) throws | ||
{ | ||
self.init(id: try bson[.id].decode(), | ||
author: try bson[.author].decode(), | ||
title: try bson[.title].decode(), | ||
views: try bson[.views].decode(), | ||
tags: try bson[.tags].decode()) | ||
} | ||
|
||
func encode(to bson:inout BSON.DocumentEncoder<CodingKey>) | ||
{ | ||
bson[.id] = self.id | ||
bson[.author] = self.author | ||
bson[.title] = self.title | ||
bson[.views] = self.views | ||
bson[.tags] = self.tags | ||
} | ||
} |