openkitten / meow Goto Github PK
View Code? Open in Web Editor NEWMongoDB object persistence for Swift
License: MIT License
MongoDB object persistence for Swift
License: MIT License
A partial update for a document so that can be used with the PATCH request. It is also more bandwidth friendly if MongoDB is hosted externally.
I'm trying to figure out how to use Meow 2.0.2. By now I figured out how to save but I'm totally lost regarding the Queries.
class Test: Model {
var _id = IdObject()
var symbol: Symbol
}
class Symbol: Codable {
var name: String
var number: Int
}
With this setup I'm trying to find documents by name or number (or even both).
let context = manager?.makeContext()
let query: Query = "symbol.name" == "Test"
let result = try? context?.findOne(Test.self, where: query).wait()
Or trying to have name
on toplevel:
class Test: Model {
var _id = IdObject()
var name: String
}
let context = manager?.makeContext()
let query: Query = "name" == "Test"
let result = try? context?.findOne(Test.self, where: query).wait()
All of these result in nil
. I've also tried to create the corresponding syntax:
[
"name" : [
"$eq" :
"Test"
]
]
Which also didn't work. So I'm wondering... what is the correct way to query for documents in Meow 2.0?
I would be willing to help and write some docs, but I'd need to know how to use Meow first :D
This issue will serve as a central discussion point for the scope of the next major (breaking) version of Meow.
Things to review:
_id
'sModel.updated(with document: Document)
APIThese would be part of the transaction middleware and on query level instead of model level
This ensures keeping data that hasn't been migrated yet intact.
This also opens up an opportunity for partial models/perspectives.
Custom algorithms?
When properties are optional I get this error:
error: Templates/MeowVapor.ejs: TypeError: MeowVapor.ejs:10
8| import ExtendedJSON
9|
>> 10| <% include('Meow') -%>
11|
12| <%
13| // helpers
Meow:22
20| %>
21| <%- include('lib/Serializable', {serializable}) %>
>> 22| <%- window.execute(window.serializableGenerators, serializable) %>
23| <%
24| }
25|
undefined is not an object (evaluating 'serializable.based["Model"]')
The class is:
import Meow
import MongoKitten
import Foundation
final class User: Model {
var createdAt: Date?
var updatedAt: Date?
var deletedAt: Date?
var active: Bool = true
// sourcery:inline:auto:User.Meow
// sourcery:end
}
Some of the documentation I've seen shows an Embeddable
protocol that seems not to exist anymore. Is it possible to embed classes or can only Reference
be used now?
I want to generate this simple user:
import Meow
import MongoKitten
import Foundation
final class User: Model {
var active: Bool = true
// sourcery:inline:auto:User.Meow
// sourcery:end
}
Ande I get this error
error: Templates/MeowVapor.ejs: ReferenceError: MeowVapor.ejs:160
158|
159| <%_ } -%>
>> 160| <%-group%>.get("<%-plural(model.name.toLowerCase())%>", <%-model.name%>.init) { request, subject in
161| return try AuthenticationMiddleware.default.respond(to: request, route: MeowRoutes.<%-model.name%>_get(subject)) { request in
162| return try AuthorizationMiddleware.default.respond(to: request, route: MeowRoutes.<%-model.name%>_get(subject)) { request in
163| return subject
Can't find variable: plural
In my project i have multiple services and each service has its own separate database and collections for security reasons. So i would love to still be able to use Meow when models have separated databases not just collections :)
I'm not sure if it's feasible or already on the roadmap or whatever, but support for optional properties in models would be nice. Otherwise it looks really good
Currently, many functions require an array or other specific collection type where it's not necessary.
An example: public static func validateDatabaseIntegrity(problemLimit limit: Int = Int.max, types: [_Model.Type]) throws -> [DatabaseProblem]
where types
could easily be a Set
, AnySequence
or any other sequence of _Model.Type
.
In addition to this, _Model.Type...
might make the API more easy, too
It is not always necessary that an object need an id. So is it possible to make an object without id?
See a user example below. The location dont need an id:
{
"name": "Mr. Awesome",
"location": {
"lat": 10.0,
"lng": 50.0
}
}
try Meow.init("mongodb://localhost/meow")
let user = User()
try user.save()
let temp = try User.findOne()
print(temp?.name)
I am running this code in Mac works fine but when I trying to connect remote MongoDB which is running in Ubuntu it prints nil, it means save not works.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.