Created
July 4, 2017 18:37
-
-
Save ozouai/486bb88feda02e4f612105d9b96566bc to your computer and use it in GitHub Desktop.
ModelType Example
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
--- | |
Name: ModelType Test | |
Heads: | |
Java: | | |
// This is the head for the java file | |
package com.modeltype.Test; | |
MongooseTS: | | |
// This is the head for the mongoose file | |
import * as crypto from "crypto"; | |
Models: | |
User: | |
Schema: | |
Name: | |
First: string | |
Last: string | |
Created: date | |
LastLogin: date | |
Email: string | |
Password: string | |
Store: | |
Schema: | |
Name: string | |
Address: string |
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
//#GeneratedOn:2017-07-02T17:32:58.943Z | |
//#ETAG:33bcaab97e022742b408cbc92e24720d | |
// This is the head for the java file | |
package com.modeltype.Test; | |
import org.bson.types.ObjectId; | |
import org.bson.Document; | |
import java.util.Date; | |
import com.mongodb.BasicDBObject; | |
public class Models { | |
private static Models Models_Singleton; | |
abstract class ModelType_JavaClass { | |
protected Document doc; | |
protected BasicDBObject update; | |
protected void keyUpdated(String key, Object val) { | |
this.update.append(key, val); | |
} | |
public ModelType_JavaClass(Document doc) { | |
this.doc = doc; | |
this.update = new BasicDBObject(); | |
} | |
} | |
abstract class SubDoc { | |
protected ModelType_JavaClass parentDoc; | |
protected SubDoc parentSubDoc; | |
protected Document doc; | |
protected String name; | |
public SubDoc(ModelType_JavaClass parent, String name, Document doc) { | |
this.doc = doc; | |
this.parentDoc = parent; | |
this.name = name; | |
} | |
public SubDoc(SubDoc parent, String name, Document doc) { | |
this.doc = doc; | |
this.parentSubDoc = parent; | |
this.name = name; | |
} | |
protected void keyUpdated(String key, Object val) { | |
if(this.parentDoc != null) { | |
this.parentDoc.keyUpdated(name + "." + key, val); | |
} | |
if(this.parentSubDoc != null) { | |
this.parentSubDoc.keyUpdated(name +"."+key, val); | |
} | |
} | |
}public class User extends ModelType_JavaClass { | |
public User(Document mongodbDocument) { | |
super(mongodbDocument); | |
} | |
public BasicDBObject update() { | |
return new BasicDBObject().append("$set", this.update); | |
} | |
public SubDoc_Name getName() { | |
if(this.Instance_SubDoc_Name == null) { | |
this.Instance_SubDoc_Name = new SubDoc_Name(this, "Name", (Document) this.doc.get("Name")); | |
} | |
return this.Instance_SubDoc_Name; | |
} | |
public void setName(SubDoc_Name obj) { } | |
public class SubDoc_Name extends SubDoc{ | |
SubDoc_Name(ModelType_JavaClass parent, String name, Document doc) { | |
super(parent, name, doc); | |
} | |
SubDoc_Name(SubDoc parent, String name, Document doc) { | |
super(parent, name, doc); | |
} | |
public String getFirst() { return (String) this.doc.get("First"); } | |
public void setFirst(String obj) { | |
this.doc.put("First", (Object) obj); | |
this.keyUpdated("First", (Object) obj); | |
} | |
public String getLast() { return (String) this.doc.get("Last"); } | |
public void setLast(String obj) { | |
this.doc.put("Last", (Object) obj); | |
this.keyUpdated("Last", (Object) obj); | |
} | |
} | |
protected SubDoc_Name Instance_SubDoc_Name; | |
public Date getCreated() { return (Date) this.doc.get("Created"); } | |
public void setCreated(Date obj) { | |
this.doc.put("Created", (Object) obj); | |
this.keyUpdated("Created", (Object) obj); | |
} | |
public Date getLastLogin() { return (Date) this.doc.get("LastLogin"); } | |
public void setLastLogin(Date obj) { | |
this.doc.put("LastLogin", (Object) obj); | |
this.keyUpdated("LastLogin", (Object) obj); | |
} | |
public String getEmail() { return (String) this.doc.get("Email"); } | |
public void setEmail(String obj) { | |
this.doc.put("Email", (Object) obj); | |
this.keyUpdated("Email", (Object) obj); | |
} | |
public String getPassword() { return (String) this.doc.get("Password"); } | |
public void setPassword(String obj) { | |
this.doc.put("Password", (Object) obj); | |
this.keyUpdated("Password", (Object) obj); | |
} | |
} | |
public static User castUser(Document doc) { | |
if(Models_Singleton == null) Models_Singleton = new Models(); | |
return Models_Singleton.new User(doc); | |
} | |
public class Store extends ModelType_JavaClass { | |
public Store(Document mongodbDocument) { | |
super(mongodbDocument); | |
} | |
public BasicDBObject update() { | |
return new BasicDBObject().append("$set", this.update); | |
} | |
public String getName() { return (String) this.doc.get("Name"); } | |
public void setName(String obj) { | |
this.doc.put("Name", (Object) obj); | |
this.keyUpdated("Name", (Object) obj); | |
} | |
public String getAddress() { return (String) this.doc.get("Address"); } | |
public void setAddress(String obj) { | |
this.doc.put("Address", (Object) obj); | |
this.keyUpdated("Address", (Object) obj); | |
} | |
} | |
public static Store castStore(Document doc) { | |
if(Models_Singleton == null) Models_Singleton = new Models(); | |
return Models_Singleton.new Store(doc); | |
} | |
} |
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
//#GeneratedOn:2017-07-02T17:32:58.948Z | |
//#ETAG:33bcaab97e022742b408cbc92e24720d | |
import * as mongoose from "mongoose"; | |
// This is the head for the mongoose file | |
import * as crypto from "crypto"; | |
export namespace _Data { export interface User {Name:{First:string,Last:string},Created:Date,LastLogin:Date,Email:string,Password:string}} | |
export namespace _Model { export interface User extends _Data.User, mongoose.Document {}} | |
var UserSchema = new mongoose.Schema({Name:{First:String,Last:String},Created:Date,LastLogin:Date,Email:String,Password:String}); | |
export namespace _Static { export interface User { Static?:{}}} | |
export const User : mongoose.Model<_Model.User> & _Static.User = mongoose.model<_Model.User>("User", UserSchema); | |
User.Static = {} | |
export namespace _Data { export interface Store {Name:string,Address:string}} | |
export namespace _Model { export interface Store extends _Data.Store, mongoose.Document {}} | |
var StoreSchema = new mongoose.Schema({Name:String,Address:String}); | |
export namespace _Static { export interface Store { Static?:{}}} | |
export const Store : mongoose.Model<_Model.Store> & _Static.Store = mongoose.model<_Model.Store>("Store", StoreSchema); | |
Store.Static = {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment