0.1.0 • Published 11 months ago

eagle-breeze v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

MySQL Breeze

备注

  • mysql 关键字: '\$maxvalue', or '\$minvalue'

函数说明

table(tableName, fields, options)

创建表

参数

  • tableName (string):表名
  • fields (BreezeFields): 字段描述
  • options (Options): 配置参数

返回值

(Table) :表对象

例子

(async () => {
  const table = await breeze.table('your_table_name', {
    a: 'INT',
    b: { type: 'VARCHAR(14)'}
  })
  cosnt doc = await table.find({
    condition: {
      a: {
        $gte: 10
      },
      b: 'foo'
    }
  })
})()

partition(table, key, content, options)

创建表分区

参数

  • table (breeze.Table): 表对象
  • key (string|string[]): 分区字段
  • content (*): 分区内容

BreezeFields

type

MYSQL的字段类型,例如:

{
  name: {type: 'VARCHAR(10)'},
  age: 'INT',
  birthday: 'DATETIME'
}

default

默认值, autoIncrement=true 时 default 无效

{
  name: {type: 'VARCHAR(10)'},
  age: 'INT',
  birthday: { 
    type: 'DATETIME',
    default: '2000-01-01 00:00:00',
  }
}

notNull

是否不能为NULL, 默认false

{
  name: {
    type: 'VARCHAR(10)',
    notNull: true
  },
  age: 'INT',
  birthday: { 
    type: 'DATETIME',
    default: '2000-01-01 00:00:00',
  }
}

unique

是否唯一, 默认false

{
  ID: {
    type: 'varchar(18)',
    unique: true
  }
  name: {
    type: 'VARCHAR(10)',
    notNull: true
  },
  age: 'INT',
  birthday: { 
    type: 'DATETIME',
    default: '2000-01-01 00:00:00',
  }
}

primaryKey

主键, 默认false

{
  id: {
    type: 'INT',
    primaryKey: true,
    autoIncrement: true
  }
  name: {
    type: 'VARCHAR(10)',
    notNull: true
  },
  age: 'INT',
  birthday: { 
    type: 'DATETIME',
    default: '2000-01-01 00:00:00',
  }
}

Options

database

指定数据库, 默认为连接MySQL时指定的数据库

{
  database: 'fy4b'
}

engine

指定存储引擎选项, 默认为数据库的默认存储引擎

{
  engine: 'MyISAM' // 'InnoDB' or 'MEMORY' or 'ARCHIVE' ...
}

charset

指定表的默认字符集, 如果没有显式指定字符集,默认情况下会使用数据库的默认字符集

{
  charset: 'utf8mb3' // 'utf8mb4'
}

rowFormat

指定表的行格式, 5.7版本后默认情况下将使用DYNAMIC行格式

{
  rowFormat: 'DYNAMIC'
}

DYNAMIC 种动态行格式,它根据行的实际需要来灵活地存储数据,以节省磁盘空间

autoIncrement

指定该表的自增列的起始值, 默认0

{
  autoIncrement: 10
}

Table

0.1.0

11 months ago