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

@ghadeerahmad/larascript

v1.5.5

Published

open source framwork

Downloads

40

Readme

library for node js to deal with mysql

a library similar to laravel functionalties written in node js

Features

  • model for mysql tabels functionalties
  • migrations
  • query builder (create,update,delete and fetch data)
  • create new record with auto timestamps
  • eagerload for 1 to 1 relationship
  • eagerload for 1 to many relationship
  • insert many
  • upsert function

Usage

to create new migration file

const users = new Migration('users', {
    id: { type: ColumnType.bigint, primary: true, autoIncrement: true },
    name: { type: ColumnType.string },
    userName: { type: ColumnType.string, unique: true },
    password: { type: ColumnType.string }
})

// run migration
await users.run()

the migration constructor takes 2 arguments: the first is table name and the second is columns and thier properties

  • type: this is the column type supported types:
    • string
    • int
    • bigint
    • double
    • float
    • boolean
    • text
    • enum
  • length: spicify the length of the column
  • default: spicify default value for column
  • primary: set the column as primary key
  • autoIncrement: set the column as auto increment
  • nullable: set the column to accept null values
  • foreign: set constraints as foriegn key, this property accepts:
    • refrences: migration instance of refrenced table
    • refrence_key: the column refrenced in the refrenced table
    • onDelete: set what happened on delete, accepts: "NULL" or "DELETE"
  • choices: this option used when you set the column type as enum to set the allowed values. this argument accepts list of strings.

Model Usage

every model points to a table in the database.

to create new model:

export class User extends Model{
    constructor(){
        super()
        this.table = 'users'
    }
}
  • this.table property sets the target table in the database, By default this property takes the ploral name of the model with lower case letters, i,e:User => users
  • to perform query using model: i,e
// get single record
const user = await User.query().first()
// get multiple records
const users = await User.query().get()
// apply where statment
const users = await User.query().where('id',1).get()
const users = await User.query().where('id',1).first()

// to create new record
// this function returns created record
const user = await User.query().create({
name:'Jhon Doe',
username:'jgondoe',
password:'somepassword'
})
// perfrom update
// this function return true or false
const result = await User.query().where('id',1).update({name:'new name'})

you must call query() function when you perform any query to database

eager load

  • if you want to fetch data from a relationship you need to define relation in the model class,i.e:
export class User extends Model{
    addresses(){
        this.hadMany(Address)
    }
}
export class Address extends Model{
    user(){
        this.belongsTo(User)
    }
}

here is example of hasMay and belongsTo relationships and how you can define them.

  • to call data from relationship,i.e:
const users = await User.query().with('addresses').get()

more details will be inserted as soom as possible