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

@icreate/ics-db-migrate

v0.0.4

Published

``` npm i @icreate/ics-db-migrate ```

Downloads

15

Readme

安装

npm i @icreate/ics-db-migrate

引用

  • DataType 数据类型。
  • DBType 数据库类型枚举。
import { createDBMigrate, DataType as type, DBType } from @icreate/ics-db-migrate

创建 DBMigrate

  • 现支持 mssql 及 Oracle 数据库
var sqlBuilder = createDBMigrate(DBType.mssql)

建表

  • createTable 入参:表名,列定义,表中文名
  • 列定义:
{
    name: string                    // 中文名
    primaryKey: boolean             // 主键
    notNull: boolean                // 不可为空
    autoIncrement: boolean          // 自增
    type: string                    // 数据类型
    length: number                  // 长度
    precision: number               // 精度
    comment: string                 // 说明
    defaultValue: string | number   // 默认值
    foreignKey: {                   // 外键
      name: string                  // 外键名
      table: string                 // 关联表
      mapping: string               // 关联列
    }
}
// 创建列定义

var colOptions = {
  ID: {
    name: '主键ID',
    primaryKey: true,
    notNull: true,
    type: type.VarChar,
    length: 50
  },
  NAME: {
    name: '名称',
    notNull: true,
    type: type.VarChar,
    length: 200
  },
  SEX: {
    name: '性别',
    notNull: true,
    type: type.VarChar,
    length: 20
  },
  AGE: {
    name: '年龄',
    notNull: true,
    type: type.Int
  }
}

sqlBuilder.createTable('TEST', colOptions, '测试表')

TRUNCATE 表

  • truncate 入参:表名
sqlBuilder.truncate('TEST')

创建视图

  • createView 入参:视图名,查询 SQL
sqlBuilder.createView('VIEW_TEST', `SELECT ID, NAME, AGE FROM TEST`)

创建函数

  • createView 入参:函数名,函数创建 SQL
// 函数SQL

const SQL =
`
create function FUNC_TEST
([p1,p2...pn])
return datatype
is|as
--声明部分
begin
--PL/SQL程序块
end
`

sqlBuilder.createFunction('FUNC_TEST', SQL)

创建存储过程

  • createProcedure 入参:存储过程名,存储过程创建 SQL
// 存储过程SQL

const SQL =
`
create procedure 存储过程名(param1 in type,param2 out type)
as
  变量1 类型(值范围);
  变量2 类型(值范围);
begin
  select count(*) into 变量1 from 表A where列名=param1;
  if (判断条件) then
  select 列名 into 变量2 from 表A where列名=param1;
  dbms_output.Put_line('打印信息');
  elsif (判断条件) then
  dbms_output.Put_line('打印信息');
  else
  raise 异常名(NO_DATA_FOUND);
  end if;
exception
  when others then
  rollback;
end;
`

sqlBuilder.createProcedure('PROC_TEST', SQL)

DROP 表

  • dropTable 入参:表名
sqlBuilder.dropTable('TEST')

DROP 视图

  • dropView 入参:视图名
sqlBuilder.dropView('VIEW_TEST')

DROP 函数

  • dropFunction 入参:函数名
sqlBuilder.dropFunction('FUNC_TEST')

DROP 存储过程

  • dropProcedure 入参:存储过程名
sqlBuilder.dropProcedure('PROC_TEST')

新增列

  • addColumn 入参:表名,列名,列定义(如上:建表列定义)
// 列定义

const option = {
  name: '备注',
  type: type.VarChar,
  length: 1000
}

sqlBuilder.addColumn('TEST', 'REMARK', option)

删除列

  • removeColumn 入参:表名,列名
sqlBuilder.removeColumn('TEST', 'REMARK')

修改列

  • changeColumn 入参:表名,列名,列定义(如上:建表列定义)
option.length = 2000

sqlBuilder.changeColumn('TEST', 'REMARK', option)

新增索引

  • addIndex 入参:表名,索引名,列集合,是否唯一索引
sqlBuilder.addIndex('TEST', 'IX_TEST_NAME', ['NAME'], false)

删除索引

  • removeIndex 入参:表名,索引名
sqlBuilder.removeIndex('TEST', 'IX_TEST_NAME')

insert

  • insert 入参:表名,数据对象或数组
var data = {
  ID: '123456789',
  NAME: '666666',
  SEX: '男',
  AGE: 19
}

sqlBuilder.insert('TEST', data)

update

  • update 入参:表名,数据对象,条件对象
var data = {
  SEX: '男',
  AGE: 19
}

var where = {
  ID: '123456789'
}

sqlBuilder.update('TEST', data, where)

remove

  • remove 入参:表名,条件对象
var where = {
  ID: '123456789'
}

sqlBuilder.remove('TEST', where)

新增外键

  • addForeignKey 入参:外键名称,表名,列名,外键表名,字段映射,约束规则
sqlBuilder.addForeignKey('fk_test','TEST','NAME','TEST2','NAME')

删除外键

  • removeForeignKey 入参:表名,外键名称
sqlBuilder.removeForeignKey('TEST','fk_test')

获取sql

  • text
var sqlText = sqlBuilder.text()