mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 12:56:46 +08:00
* Improved camo support and updated to v0.12.2 * Fixed issue with camo lacking Template Schema
42 lines
874 B
TypeScript
42 lines
874 B
TypeScript
import {
|
|
connect,
|
|
Document as CamoDocument,
|
|
DocumentSchema,
|
|
SchemaTypeExtended
|
|
} from "camo";
|
|
|
|
connect("mongodb://user:password@localhost:27017/database?authSource=admin").then(() => {
|
|
let document = new CamoDocument();
|
|
|
|
interface UserSchema extends DocumentSchema {
|
|
name: string;
|
|
password: string;
|
|
friends: string[];
|
|
dateCreated?: Date;
|
|
}
|
|
|
|
class User extends CamoDocument<UserSchema> {
|
|
private name: SchemaTypeExtended = String;
|
|
private password: SchemaTypeExtended = String;
|
|
private friends: SchemaTypeExtended = [String];
|
|
private dateCreated: SchemaTypeExtended = {
|
|
type: Date,
|
|
default: Date.now
|
|
};
|
|
static collectionName() {
|
|
return "users";
|
|
}
|
|
}
|
|
|
|
var newUser = User.create<UserSchema>({
|
|
name: "user-1",
|
|
password: "secret",
|
|
friends: ["user-2", "user-3"]
|
|
});
|
|
|
|
newUser.save().then(done => {
|
|
console.log(done._id);
|
|
});
|
|
|
|
});
|