node.js: postgreSQL16 sequelize6 es6 ORM in webstorm 2023.1 and vscode

其實就是下載的包不一樣和數據庫配置連接不一樣,代碼基本是一樣,可以再架代碼可以改配置操作選擇數據庫配置,就可以少改動代碼,變換任一個主流數據庫。其實也是学习包的代碼架構方式,也可以讓代碼重復利用,初學都是一步一步學習,後再如何讓代碼如何架構設計的更有靈活性可易讀性等。

postgreSQL  script

-- Database: geovindu

-- DROP DATABASE IF EXISTS geovindu;

CREATE DATABASE geovindu
    WITH
    OWNER = postgres
    ENCODING = 'UTF8'
    LC_COLLATE = 'Chinese (Simplified)_China.936'
    LC_CTYPE = 'Chinese (Simplified)_China.936'
    LOCALE_PROVIDER = 'libc'
    TABLESPACE = pg_default
    CONNECTION LIMIT = -1
    IS_TEMPLATE = False;

COMMENT ON DATABASE geovindu
    IS 'default administrative connection database';

SELECT version();



SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'userInfos';

SELECT * FROM pg_tables where schemaname = 'public';



select * from userInfos;

select * from public."userInfos";




insert into public."userInfos"("userName","userReal","userPassword","userIsOk","userMail","userMobile","createdAt","updatedAt") 
values('geovindu','涂聚文','geovindu',true,'geovindu@163.com','13824350518','2025-07-09','2025-09-01');



--创建表
create table BookKindList
(
    BookKindID SERIAL PRIMARY KEY,
    BookKindName varchar(500) not null,
    BookKindCode varchar(100) null,
    BookKindParent int null
);
 
--查询
select * from BookKindList;
--添加
insert into BookKindList(BookKindName,BookKindParent) values('六福书目录',0);
 
insert into BookKindList(BookKindName,BookKindParent) values('文学',1);
insert into BookKindList(BookKindName,BookKindParent) values('设计艺术',1);
insert into BookKindList(BookKindName,BookKindParent) values('自然科学',1);
 
insert into BookKindList(BookKindName,BookKindParent) values('小说',2);
insert into BookKindList(BookKindName,BookKindParent) values('诗词散曲',2);
 
select * from BookKindList where BookKindID=1;
--返回增加的ID
select lastval();


/*
Executing (default): SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'tutorials'
Executing (default): CREATE TABLE IF NOT EXISTS "tutorials" ("id"   SERIAL , "title" VARCHAR(255), "description" VARCHAR(255), "published" BOOLEAN, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id"));
Executing (default): SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid
 = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'tutorials' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;
Executing (default): SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'userInfos'
Executing (default): CREATE TABLE IF NOT EXISTS "userInfos" ("id"   SERIAL , "userName" VARCHAR(255), "userReal" VARCHAR(255), "userPassword" VARCHAR(255), "userIsOk" BOOLEAN, "userMail" VARCHAR(255), "userMobile" VARCHAR(255), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE 
NOT NULL, PRIMARY KEY ("id"));
Executing (default): SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid
 = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'userInfos' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;
*/


	
/**
 @description WebStorm
 @author Geovin Du,涂聚文,塗聚文  geovindu
 @project vuejsproject
 @package npm install express sequelize pg pg-hstore cors --save
 @file dbConfig.js
 @ide webstorm 2023.1
 @database mysql 8.0 sql server 2019 postgresSQL 16
 @dev node 20 vue.js 3.0
 @date Created in 8:11 2024/08/18
 @edate eddit in
 */

/**
 *
 * @type {
  {dialect: string, PASSWORD: string, pool: {min: number, max: number, idle: number, acquire: number}, HOST: string, USER: string, DB: string}}
 */
module.exports = {
    HOST: "geovindu",
    USER: "postgres",
    PASSWORD: "geovindu",
    DB: "geovindu",
    dialect: "postgres",
    pool: {
        max: 5,
        min: 0,
        acquire: 30000,
        idle: 10000
    }
};


/**
 @description WebStorm
 @author Geovin Du,涂聚文,塗聚文  geovindu
 @project vuejsproject
 @package npm install express sequelize pg pg-hstore cors --save
 @file userinfo.model.js
 @ide webstorm 2023.1
 @database mysql 8.0 sql server 2019 postgresSQL 16
 @dev node 20 vue.js 3.0
 @date Created in 8:28 2024/08/18
 @edate eddit in
 */


/**
 * userInfo 实体类
 * @param sequelize
 * @param Sequelize
 * @returns {*}
 */
module.exports = (sequelize, Sequelize) => {
    const UserInfo = sequelize.define("userInfo", {
        userName: {
            type: Sequelize.STRING
        },
        userReal:{
            type:Sequelize.STRING
        },
        userPassword: {
            type: Sequelize.STRING
        },
        userIsOk: {
            type: Sequelize.BOOLEAN
        },
        userMail:
            {
                type:Sequelize.STRING
            },
        userMobile:
            {

                type:Sequelize.STRING

            }
    });

    return UserInfo;
};

/**
 @description WebStorm
 @author Geovin Du,涂聚文,塗聚文  geovindu
 @project vuejsproject
 @package  npm install express sequelize pg pg-hstore cors --save
 @file index.js
 @ide webstorm 2023.1
 @database mysql 8.0 sql server 2019 postgresSQL 16
 @dev node 20 vue.js 3.0
 @date Created in 8:19 2024/08/18
 @edate eddit in
 */

/**
 *
 * @type {
  {dialect: string, PASSWORD: string, pool: {min: number, max: number, idle: number, acquire: number}, HOST: string, USER: string, DB: string}|{HOST?: string, USER?: string, PASSWORD?: string, DB?: string, dialect?: string, pool?: {min: number, max: number, idle: number, acquire: number}}}
 */
const dbConfig = require("../config/dbconfig.js");

/**
 *
 * @type {
  {Optional: Omit<T, K> & Partial<Pick<T, K>>, TableHints: TableHints, Error: BaseError, DataTypes: {RealDataTypeConstructor: RealDataTypeConstructor, AbstractDataType: AbstractDataType, EnumDataTypeOptions: EnumDataTypeOptions, IntegerDataTypeOptions: IntegerDataTypeOptions, RangeDataTypeConstructor: RangeDataTypeConstructor, ARRAY: ArrayDataTypeConstructor, SMALLINT: SmallIntegerDataTypeConstructor, TextDataTypeConstructor: TextDataTypeConstructor, TIME: AbstractDataTypeConstructor, JSON: AbstractDataTypeConstructor, BIGINT: BigIntDataTypeConstructor, SmallIntegerDataTypeConstructor: SmallIntegerDataTypeConstructor, HSTORE: AbstractDataTypeConstructor, EnumDataTypeConstructor: EnumDataTypeConstructor, ENUM: EnumDataTypeConstructor, FLOAT: FloatDataTypeConstructor, NUMBER: NumberDataTypeConstructor, BlobDataTypeOptions: BlobDataTypeOptions, StringDataTypeOptions: StringDataTypeOptions, DecimalDataTypeOptions: DecimalDataTypeOptions, GEOMETRY: GeometryDataTypeConstructor, ArrayDataTypeOptions: ArrayDataTypeOptions, DOUBLE: DoubleDataTypeConstructor, NumberDataTypeOptions: NumberDataTypeOptions, DoubleDataType: DoubleDataType, NumberDataTypeConstructor: NumberDataTypeConstructor, RANGE: RangeDataTypeConstructor, GeometryDataTypeOptions: GeometryDataTypeOptions, RangeableDataType: IntegerDataTypeConstructor | IntegerDataType | BigIntDataTypeConstructor | BigIntDataType | DecimalDataTypeConstructor | DecimalDataType | DateOnlyDataTypeConstructor | DateOnlyDataType | DateDataTypeConstructor | DateDataType, DecimalDataType: DecimalDataType, ArrayDataTypeConstructor: ArrayDataTypeConstructor, IntegerDataTypeConstructor: IntegerDataTypeConstructor, VirtualDataTypeConstructor: VirtualDataTypeConstructor, GeographyDataTypeOptions: GeographyDataTypeOptions, DataTypeAbstract: AbstractDataTypeConstructor, DateOnlyDataType: DateOnlyDataType, RealDataTypeOptions: RealDataTypeOptions, INET: AbstractDataTypeConstructor, STRING: StringDataTypeConstructor, TinyIntegerDataTypeConstructor: TinyIntegerDataTypeConstructor, NOW: AbstractDataTypeConstructor, GeographyDataType: GeographyDataType, DoubleDataTypeConstructor: DoubleDataTypeConstructor, TextDataTypeOptions: TextDataTypeOptions, CharDataTypeConstructor: CharDataTypeConstructor, BLOB: BlobDataTypeConstructor, DATEONLY: DateOnlyDataTypeConstructor, CharDataTypeOptions: CharDataTypeOptions, BigIntDataType: BigIntDataType, GeometryDataType: GeometryDataType, DateOnlyDataTypeConstructor: DateOnlyDataTypeConstructor, BigIntDataTypeConstructor: BigIntDataTypeConstructor, TEXT: TextDataTypeConstructor, GEOGRAPHY: GeographyDataTypeConstructor, RangeDataType: RangeDataType, StringDataTypeConstructor: StringDataTypeConstructor, VIRTUAL: VirtualDataTypeConstructor, UUIDV4: AbstractDataTypeConstructor, AbstractDataTypeConstructor: AbstractDataTypeConstructor, CITEXT: AbstractDataTypeConstructor, FloatDataTypeOptions: FloatDataTypeOptions, NumberDataType: NumberDataType, CIDR: AbstractDataTypeConstructor, MediumIntegerDataType: MediumIntegerDataType, RealDataType: RealDataType, VirtualDataType: VirtualDataType, DECIMAL: DecimalDataTypeConstructor, DateDataType: DateDataType, DateDataTypeOptions: DateDataTypeOptions, FloatDataTypeConstructor: FloatDataTypeConstructor, TINYINT: TinyIntegerDataTypeConstructor, BOOLEAN: AbstractDataTypeConstructor, DataType: string | AbstractDataTypeConstructor | AbstractDataType, UUID: AbstractDataTypeConstructor, DATE: DateDataTypeConstructor, DecimalDataTypeConstructor: DecimalDataTypeConstructor, INTEGER: IntegerDataTypeConstructor, SmallIntegerDataType: SmallIntegerDataType, BlobDataType: BlobDataType, GeometryDataTypeConstructor: GeometryDataTypeConstructor, MediumIntegerDataTypeConstructor: MediumIntegerDataTypeConstructor, ArrayDataType: ArrayDataType, DoubleDataTypeOptions: DoubleDataTypeOptions, StringDataType: StringDataType, GeographyDataTypeConstructor: GeographyDataTypeConstructor, BlobDataTypeConstructor: BlobDataTypeConstructor, BlobSize: "tiny" | "medium" | "long", TinyIntegerDataType: TinyIntegerDataType, UUIDV1: AbstractDataTypeConstructor, JSONB: AbstractDataTypeConstructor, DateDataTypeConstructor: DateDataTypeConstructor, REAL: RealDataTypeConstructor, RangeDataTypeOptions: RangeDataTypeOptions, IntegerDataType: IntegerDataType, TSVECTOR: AbstractDataTypeConstructor, MACADDR: AbstractDataTypeConstructor, CharDataType: CharDataType, CHAR: CharDataTypeConstructor, ABSTRACT: AbstractDataTypeConstructor, TextLength: "tiny" | "medium" | "long", TextDataType: TextDataType, EnumDataType: EnumDataType, FloatDataType: FloatDataType, MEDIUMINT: MediumIntegerDataTypeConstructor}, Validator: Validator, useInflection: (inflection: Inflector) => void, Utils: {Fn: Fn, TICK_CHAR: string, spliceStr(str: string, index: number, count: number, add: string): string, stack(): NodeJS.CallSite[], camelize(str: string): string, cloneDeep<T>(obj: T, fn?: (el: unknown) => unknown): T, Primitive: "string" | "number" | "boolean", Json: Json, Col: Col, SequelizeMethod: SequelizeMethod, removeTicks(s: string, tickChar?: string): string, camelizeIf(string: string, condition?: boolean): string, isPrimitive(val: unknown): val is Primitive, classToInvokable<T extends {new(...args: any[]): any}>(ctor: T): (T & {(...args: ConstructorParameters<T>): T}), OptionsForMapping: OptionsForMapping, NullishPropertiesOf: {[P in keyof T]-?: undefined extends T[P] ? P : (null extends T[P] ? P : never)}[keyof T], combineTableNames(tableName1: string, tableName2: string): string, DeepWriteable: DeepWriteable, underscoredIf(string: string, condition?: boolean): string, format(arr: string[], dialect: string): string, singularize(s: string): string, Inflector: Inflector, mapValueFieldNames(dataValues: object, fields: string[], model: ModelType): object, defaultValueSchemable(hash: DataType): boolean, mapWhereFieldNames(attributes: object, model: ModelType): object, formatNamedParameters(sql: string, parameters: {[p: string]: string | number | boolean}, dialect: string): string, addTicks(s: string, tickChar?: string): string, MakeNullishOptional: T extends any ? Optional<T, NullishPropertiesOf<T>> : never, pluralize(s: string): string, isColString(value: string): boolean, useInflection(inflection: Inflector): void, mergeDefaults<T>(a: T, b: Partial<T>): T, Where: Where, now(dialect: string): Date, Literal: Literal, Cast: Cast, toDefaultValue<T>(value: unknown): unknown, canTreatArrayAsAnd(arr: unknown[]): boolean, mapOptionFieldNames<M extends Model, T extends OptionsForMapping<Attributes<M>>>(options: T, model: ModelCtor<M>): T, AnyFunction: (...args: any[]) => any, mapFinderOptions<M extends Model, T extends OptionsForMapping<Attributes<M>>>(options: T, model: ModelCtor<M>): T}, IndexHints: IndexHints, Deferrable: {SET_DEFERRED: SetDeferredDeferrableStatic, INITIALLY_DEFERRED: InitiallyDeferredDeferrableStatic, InitiallyDeferredDeferrableStatic: InitiallyDeferredDeferrableStatic, SetDeferredDeferrableStatic: SetDeferredDeferrableStatic, SetImmediateDeferrableStatic: SetImmediateDeferrableStatic, AbstractDeferrableStatic: AbstractDeferrableStatic, InitiallyDeferredDeferrable: InitiallyDeferredDeferrable, SET_IMMEDIATE: SetImmediateDeferrableStatic, InitiallyImmediateDeferrableStatic: InitiallyImmediateDeferrableStatic, Deferrable: Deferrable, NOT: NotDeferra
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值