GithubHelp home page GithubHelp logo

d-mawl / vscode-easycode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zzh-gavin/vscode-extension-gyctools

0.0 0.0 0.0 171 KB

This is a tool for generate your code from database table definition.Currently we only support MySQL. from : https://github.com/zzh-gavin/vscode-extension-gyctools

License: MIT License

TypeScript 87.74% Nunjucks 12.26%

vscode-easycode's Introduction

Patella (GycTools was renamed Patella)

This is a tool for Generate Your Code(all programming languages or maybatis map-files and so on, up to you) from database table definition. Befor using it, you need know how work it is. So please read this document and config this tool for your own projects by ".vscode/gyctools.config.json".

And if you like this tool,please give us a like.thanks.

Usage

Open Your Project First

  • Patella will copy the default templates into ".vscode/gyc_templates" when you open the project if it doesn't exists.
  • And Patella copy a particular config file "gyctools.config.json",you must edit it for your project folder construction.

Code Generator Entry

Usage

Generate Database Specification Entry

  • It's on the database itemview when you right click, named "Generate DB Specification".
  • And you can edit the specification.njk in the ".vscode" folder.

Features

1:generate all language from db table by Nunjucks template

2:generate database document by a default Nujucks template

How To Use

Every you named database can setting itself template info or other customs attributes

Every template can define is's own language interpreter

  • Template can define is's own language interpreter by the attribute named "language'.
  • If template not define language attribute gyc will auto catch it's value with 'outFileType'. But this only working with '.java','.ts' or '.cs' or not gyc will use default interpreter "xxSql to java".

Two kind instance take part in the Nunjucks template.CodeEntity and CodeProperty

1: CodeEntity is db table info, the properties can used in your template like this

{{dbType}}
{{tableName}}
{{className}}
{{primaryKey}}
...

Here is features for CodeEntity

  //database type , currently we only support MySQL.this fiedl value samed with SQLTools driver name.
  dbType: String;
  //original table name from db
  tableName: string;
  //conversion from tableName
  className: string;
  //table's primary key 
  primaryKey?: string;
  //table's auto increment column name
  autoIncrementKey?: string;
  //conversion from table columns 
  properties: Array<CodeProperty>;    
  //conversion from table columns 
  primarykeyProperties: Array<CodeProperty>;
  //if the column conversion need import code, see TypeInterpreter Config
  importArray: Array<string> = new Array<string>();
  //custom attributes from config file
  customsAttributes: any;   
  //table name prefix from config file
  tableNamePrefix: string;
   //total count of primary key
  primaryKeyCount:number = 0;
   //table's all primary key
  primarykeyArray: Array<string>;
  //table's all primary key translated to property
  primaryKeyPropertyArray: Array<string>;

2: CodeProperty is table columns info, the properties can used in your template by {{properties}}:**

  {% for property in properties %}
      {% if property.isInBaseModel==false and property.columnName != primaryKey %}
  private {{ property.propertyType }} {{ property.propertyName }};
      {% endif %}
  {% endfor %}

Here is features for CodeProperty

  //table's column name
  columnName: string;
  //data type
  dataType: string;
  //data allowed null
  isNullable: boolean;
  //column is index and auto sequences
  isAutoIncrement: boolean;
  //column's comment info
  comment: string;
  //column is pk
  isPrimaryKey: boolean = false;
  //code(entity\pojo\object) field name translate from dataType 
  propertyName: string;
  //code field type
  propertyType?: string;
  //code field methodName for java's get set function
  methodName: string;
  //code field need import/requir thirdparty class/object
  importTypeName?: string;
  //field is defined in base object
  isInBaseModel: boolean = false;

Holding your self code in target files.

All codes were generated by templates , So self codes will be coverd by template result.Patella suport use commentary tag for retain you own codes.

    // Add manual codes in patella holding range , they will be reserved when anthour generation.
    //patella:holding codes name=myCodes
    {{ holdingCode.myCodes }}
    //patella:end holding codes

Extension Dependencies

If want use this tools,you must install SQLTools. It's a very popular extension for database manage.

Database Type supported

MySQL

Install SQLTools and SQLTools MySQL/MariaDB driver is necessarily.And the connection setting mast use 'Server and Port' and the password need select 'Save password' if not this tool can't connect to db server.

  • Here is SQLtoos connection config sample
"sqltools.connections": [
        {
            "previewLimit": 50,
            "server":"127.0.0.1",
            "port": 3306,
            "driver": "MySQL",
            "name": "GYSTools",
            "group": "GYSTools",
            "database": "gyc_tools",
            "username": "gyctools",
            "password": "gyctools"
        },
        {
            "mssqlOptions": {
                "appName": "SQLTools",
                "useUTC": true,
                "encrypt": false
            },
            "previewLimit": 500,
            "server": "127.0.0.1",
            "port": 1433,
            "driver": "MSSQL",
            "name": "GYSTools",
            "database": "GYSTools",
            "username": "gyctools",
            "password": "gyctools"
        }
]

So EasyProducer-GYC need the username and password to connect the target databse.It's important use dev db not product to protect your information.

MsSQL

Install SQLTools and SQLTools MicrosoftSQL Server/Azure driver is necessarily. And the connection setting mast use 'Server and Port' and the password need select 'Save password' if not this tool can't connect to db server.

Config File gyctools.config.json

  • Gyc config file is initialized in .vscode dictionary,file name is 'gyctools.config.json'. This means every project(root folder) has it's own settings.
  • Befor use patella ,must fit the config file into your project.Such as 'outPath','customsAttributes' or 'customsTypeInterpreterConfig'

Code Template Info

Tools has a bundle of templates in extension installation directory "template-sqg-spring",it's a java-spring and a private template demo you to edit them for youself style. Alternatively,you can contact us help you for your own templates. And then you can set the template folder in gyctools.config by "dataBaseList.item.templatePath".

Language Type Interpreter

Gyc tool has tow type interpreter provided: If that is not what your want,then can define a 'customsTypeInterpreterConfig' in 'gyctools.config.json' like the 'gyctools.config.json Demo'.

  • MySqlToJavaTypeInterpreter

     static dbTypeToJavaTypeInterpreterConfig: any = {
          'int': { 'result': 'Integer' },
          'tinyint': { 'result': 'Integer' },
          'smallint': { 'result': 'Integer' },
          'datetime': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
          'timestamp': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
          'date': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
          'time': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
          'decimal': { 'result': 'BigDecimal', 'importTypeName': 'java.math.BigDecimal' },
          'bit': { 'result': 'Boolean' },
          'bigint': { 'result': 'Long' },
          'default': { 'result': 'String' }
      };
  • MsSqlToJavaTypeInterpreter

     static dbTypeToJavaTypeInterpreterConfig: any = {
          'int': { 'result': 'Integer' },
          'tinyint': { 'result': 'Integer' },
          'smallint': { 'result': 'Integer' },     
          'datetime': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
          'smalldatetime': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
          'timestamp': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
          'date': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
          'time': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
          'decimal': { 'result': 'BigDecimal', 'importTypeName': 'java.math.BigDecimal' },
          'numeric': { 'result': 'BigDecimal', 'importTypeName': 'java.math.BigDecimal' },
          'money': { 'result': 'BigDecimal', 'importTypeName': 'java.math.BigDecimal' },
          'bit': { 'result': 'Boolean' },
          'bigint': { 'result': 'Long' },
          'default': { 'result': 'String' }
      };

Contact

vscode-easycode's People

Contributors

zzh-gavin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.