npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongoose2pojo

v0.1.3

Published

Mongoose schema to POJO convertor

Downloads

5

Readme

mongoose2pojo

Converts MongooseJS schemas to POJO (Plain Old Java Object)

Example usage

my@comp:~$ mkdir schemas && cd schemas
# COPY SCHEMA FILES TO THE ~/schemas DIRECTORY
my@comp:~/schemas$ npm install mongoose
my@comp:~/schemas$ sudo npm install mongoose2pojo -g
my@comp:~/schemas$ mongoose2pojo *.js

mongoose2pojo expects that your schema files are nodejs modules exposing Schema object to module.exports.

Using as command line executable

my@comp:~/code/schemas$ mongoose2pojo image-schema.js
Created POJO file. Size: 1797	 /home/my/schemas/ImagePojo.java

File image-schema.js.

var Schema = require("mongoose").Schema;

module.exports = new Schema({
  ref:  { type: Schema.ObjectId, ref: 'Asset', index: true },
  time: { type: Date, index: true },
  type: String
}, { collection: 'myimage' });

File ImagePojo.java gets created:

import java.util.Date;
import java.util.UUID;
import java.util.Map;

public class Myimage{
	private UUID ref;
	private Date time;
	private String type;
	private UUID id;

	public UUID getRef() {
		return this.ref;
	}
	public void setRef(UUID ref) {
		this.ref = ref;
	}
	public Date getTime() {
		return this.time;
	}
	public void setTime(Date time) {
		this.time = time;
	}
	public String getType() {
		return this.type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public UUID getId() {
		return this.id;
	}
	public void setId(UUID id) {
		this.id = id;
	}
}

Using as library

var Schema = require("mongoose").Schema;
var m2p = require("mongoose2pojo");
var converter = m2p({
  className: "User"
});
var javaCodeString = converter.parse({
  name: String,
  login: { type: String, required: true },
  registeredBy: { type: Schema.ObjectId, ref: 'User', index: true }
});

The resulting javaCodeString is:

import java.util.Date;
import java.util.UUID;
import java.util.Map;

public class User{
	private String name;
	private String login;
	private UUID registeredBy;
	private UUID id;

	public String getName() {
		return this.name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getLogin() {
		return this.login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public UUID getRegisteredBy() {
		return this.registeredBy;
	}
	public void setRegisteredBy(UUID registeredBy) {
		this.registeredBy = registeredBy;
	}
	public UUID getId() {
		return this.id;
	}
	public void setId(UUID id) {
		this.id = id;
	}
}

Alternatively you can generate POJO text from js schema file. No files will be created.

var contents = m2p().parseFile(fileName);

Or you can generate POJO file from js schema file. A file ImagePojo.java will be created right next to the existing schema file.

m2p.convertFile("image-schema.js");