Code Monkey home page Code Monkey logo

schema's People

Contributors

amcgregor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

schema's Issues

Expose descriptor object annotation hints to containing classes.

Trivial example:

from marrow.mongo import Document
from marrow.mongo.field import String

class Sample(Document):
	name:str = String()

This should stand out, glaringly, as a DRY failure. We are assigning a data descriptor object explicitly to handle strings, why must we declare, then, that instances contain strings within this attribute? The trivial example hides the scope of the majesty of this problem. A better example:

from bson import ObjectId as OID
from datetime import datetime, timedelta
from collections.abc import MutableMapping

from marrow.mongo import Document
from marrow.mongo.field import ObjectId

class Sample(Document):
	name:Union[OID,datetime,timedelta,MutableMapping,str,bytes] = ObjectId()

Ruh-roh! Requiring developers using Marrow Mongo to declare such a Union on every ObjectId field (even if abbreviated, e.g. through assignment of that Union to a variable) is a very bad idea. The descriptor itself knows what values it can handle, and what it will hand out. (Additionally, until lazy evaluation of annotations is more widespread, it'd be nice to not force those extra imports on people.)

Introduced in c2a4554 and patched in 98a0f5d to permit preservation of explicit annotations, remaining are tests and documentation.

The Attribute subclasses implementing fields may then declare an annotation attribute, which will be hoisted up into the containing class' __annotations__.

MCVE. Demonstration of intent.

Define a basic typecasting API.

To assist with the generic implementation of ORM (or widget) style data access attributes some form of automatic to/from typecasting will be needed.

To reduce code duplication these casters should be external to the attribute classes themselves and merely referenced as a class attribute on the same.

Basically transfer that bit from marrow.tags and expand to cover similar transformations as MongoEngine.

Schema migration tools.

From #python:

<ssbr_at_work> IDK. These days when I look at schemas, the core question I want to have answered is, "how do I keep forward and backward compatibility?"
<ssbr_at_work> File formats need to answer that question, universally, don't they? Why don't the schema formats help?
<ssbr_at_work> GothAlice: IMO you should borrow extensively from cap'n proto / protocol buffers

<ssbr_at_work> GothAlice: So you write a serialization protocol that has a lot of freedom for forward/backward compatibility reasons, and then for a specific version you write a validator that ignores things it doesn't know about.
<ssbr_at_work> GothAlice: so IMO the only thing marrow should remember from the lessons learned by protobuf/cap'n proto is not to reject unknown values
<sproingie> ssbr_at_work: i think it's that protocol compatibility is much more complicated than locking it down to a particular version number or required fields, so it punts and leaves it up to the application layer to decide unless you avail yourself of explicitly marking things required
<ssbr_at_work> sproingie: marking things as required is an antipattern in protocol buffer land, to the extent that it's forbidden in cap'n proto
<ssbr_at_work> GothAlice: protocol buffers have a few ways they deal with unknown values that might be interesting to you as alternate options (or defaults)
<ssbr_at_work> GothAlice: in particular, unknown fields are totally ignored, unknown values for known fields are read as a "default" known value

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.