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

theorm

v0.2.13

Published

Nodejs MySQL ORM

Downloads

14

Readme

theorm

Javascript Object-Relational Mapper (This is still a work in progress)

Primitive Model Property Types

type.bool

This will store a boolean true/false value to the database. Unless configured otherwise, the value will default to false.

field: {db_field_type} (default to property name)
index: {db_column_index} (default false)
data_type: {db_column_type} (default "tinyint(3) unsigned")
default_value: {db_default_value} (default 0)
allow_null: {db_allow_null} (default false)
search: {search_enable} (default false)
search_mapping: {search_mapping_type} (default { type: 'boolean' })

type.bool_true

default_value: true

type.bool_false

default_value: false

type.int

This will store an integer number to the database. The default is to store a 4-byte signed integer.

field: {db_field_type} (default to property name)
index: {db_column_index} (default false)
data_type: {db_column_type} (default "int(11)")
default_value: {db_default_value} (default 0)
auto_increment: {db_auto_increment} (default false)
primary_key: {db_primary_key} (default false)
allow_null: {db_allow_null} (default false)
search: {search_enable} (default false)
search_mapping: {search_mapping_type} (default { type: 'integer' })

type.uint : extends type.int

data_type: 'int(10) unsigned'
search_mapping: { type: 'integer' }

type.tiny_int : extends type.int

data_type: 'tinying(4)
search_mapping: { type: 'byte' }

type.tiny_uint : extends type.int

data_type: 'tinyint(3) unsigned'
search_mapping: { type: 'byte' }

type.small_int : extends type.int

data_type: 'smallint(6)'
search_mapping: { type: 'short' }

type.small_uint : extends type.int

data_type: 'smallint(5) unsigned'
search_mapping: { type: 'short' }

type.medium_int : extends type.int

data_type: 'mediumint(9)
search_mapping: { type: 'integer' }

type.medium_int : extends type.int

data_type: 'mediumint(8) unsigned'
search_mapping: { type: 'integer' }

type.big_int : extends type.int

data_type: 'bigint(20)'
search_mapping: { type: 'long' }

type.big_uint : extends type.int

data_type: 'bigint(19) unsigned'
search_mapping: { type: 'long' }

type.int_key : extends type.int

index: true

type.tiny_key : extends type.int

index: true

type.small_key : extends type.int

index: true

type.medium_key : extends type.int

index: true

type.big_key : extends type.int

index: true

type.primary_key : extends type.uint

auto_increment: true
primary_key: true

type.tiny_primary_key : extends type.uint

auto_increment: true
primary_key: true

type.small_primary_key : extends type.small_uint

auto_increment: true
primary_key: true

type.medium_primary_key : extends type.medium_uint

auto_increment: true
primary_key: true

type.big_primary_key : extends type.big_uint

auto_increment: true
primary_key: true

type.char

This will store a short character string to the database. Unless the size option is set, it will default to a one byte character.

size: {db_column_type_size} (default 1)
field: {db_field_type} (default to property name)
index: {db_column_index} (default false)
data_type: {db_column_type} (default "char(<size>)")
primary_key: {db_primary_key} (default false)
string_key: {model_string_key} (default false)
default_value: {db_default_value} (default '')
allow_null: {db_allow_null} (default false)
search: {search_enable} (default false)
search_mapping: {search_mapping_type} (default { type: 'string' })

type.varchar : extends type.char

size: 255
data_type: 'varchar(size)'

type.binary : extends type.char

size: 255
data_type: 'binary(size)'

type.varbinary : extends type.char

size: 255
data_type: 'varbinary(size)'

type.blob : extends type.char

data_type: 'blobl'

type.blob_tiny : extends type.char

data_type: 'tinyblob'

type.blob_medium : extends type.char

data_type: 'mediumblob'

type.blob_long : extends type.char

data_type: 'tinyblob'

type.text : extends type.char

data_type: 'text'

type.text_tiny : extends type.char

data_type: 'tinytext'

type.text_medium : extends type.char

data_type: 'mediumtet'

type.text_long : extends type.char

data_type: 'longtext'

type.varchar_key : extends type.varchar

index: 16

type.string_key : extends type.varchar

string_key: 8

type.date

This will store a date to the database. By changing the format and data_type, it can easily be adapted to store a datetime.

format: {db_field_format} (default to "YYYY-MM-DD")
field: {db_field_type} (default to property name)
index: {db_column_index} (default false)
data_type: {db_column_type} (default "date")
primary_key: {db_primary_key} (default false)
default_value: {db_default_value} (default '0000-00-00')
allow_null: {db_allow_null} (default false)
search: {search_enable} (default false)
search_mapping: {search_mapping_type} (default { type: 'date', format: 'YYYY-MM-dd HH:mm:ss' })

type.date_time : extends type.date

data_type: 'datetime'
format: 'YYYY-MM-DD HH:mm:ss'
default_value: '0000-00-00 00:00:00'

type.create_time : extends type.date_time

update: 2 (Never update, only create)

type.update_time : extends type.date_time

update: 1 (Always update, including create)

type.timestamp : extends type.date_time

data_type: 'timestamp'
default_value: 'CURRENT_TIMESTAMP'
update_timestamp: 'on update CURRENT_TIMESTAMP'

type.date_time_key : extends type.date_time

index: true

type.create_time_key : extends type.create_time

index: true

type.update_time_key : extends type.update_time

index: true

type.timestamp_key : extends type.timestamp

index: true

type.json

This will store a javascript object to the database as a json string. By default, it uses a text blob for storage, so can store up to 64K of serialized json.

field: {db_field_type} (default to property name)
index: {db_column_index} (default false)
data_type: {db_column_type} (default "text")
default_value: {db_default_value} (default '')
allow_null: {db_allow_null} (default false)
search: {search_enable} (default false)
search_mapping: {search_mapping_type} (default { type: 'object' })

type.password

This will encrypt a password using bcrypt

field: {db_field_type} (default to property name)
index: {db_column_index} (default false)
data_type: {db_column_type} (default 'varchar(255)')
default_value: {db_default_value} (default '')
allow_null: {db_allow_null} (default false)

Relational Model Property Types

type.one_to_one

This will establish a one-to-one relationship bwetween this model and a target model

TODO

type.many_to_one

This will establish a many-to-one relationship between a property of this model and a target model

model: {target_model_name} (Defaults to name derived from poperty name)
field: {db_field_type} (Defaults name derived from target model & property name)
index: {db_column_index} (default false)
data_type: {db_field_type} (Defaults to type of foreign_model's primary key)
default_value: {db_default_value} (default '0')
allow_null: {db_allow_null} (default false)
primary_key: {db_primary_key} (default false)
search: {search_enable} (default false | can be 'field' or ['field1','field2'...])
search_mapping: {search_mapping_type} (default { type: <search_type> })
search_type: {search_type} (Specify as 'key' or ['field1','field2'...])

type.foreign_key : extends type.many_to_one

index: true

type.foreign_primary_key : extends type.many_to_one

primary_key: true

type.one_to_many

This will establish a one-to-many relationship with aother model

model: {target_model_name} (Defaults to name derived from poperty name)
key: {target_model_key} (Defaults to current model name singularized, with _id)

type.many_to_many

This will establish a many-to-many relationship between a linking model and a target model

map: {linking_model_name} (Defaults to current model name singularized + target model name)
model: {target_model_name} (Defaults to name derived from poperty name)
search: {search_enable} (default false | can be 'field' or ['field1','field2'...])
key: {target_model_key} (Defaults to current model name singularized, with _id)