Skip to content

dataType in define for create DDL #10

@jmc420

Description

@jmc420

I'm trying to generate SQL create DDL from a SQL define using this code:

const post = this.sql.define<{ id: number; title: string; body: string }>({
           name: 'post',
           columns: ['id', 'title', 'body']
       });

       try {
           let query = post.create().toQuery();

           console.log("Create Query " + query.text)

           return query;
       }
       catch (e) {
           console.log("ERROR " + e.message + " STACK " + e.stack)
       }

This generates an error: ERROR dataType missing for column id (CREATE TABLE and ADD COLUMN statements require a dataType).

I can get the define to work by changing the columns in the define to:

columns: [{name: 'id', dataType: "number"}, {name:'title', dataType: "string"}, {name:'body', dataType: "string"}]

This will generate the create DDL: "CREATE TABLE post (id number, title string, body string)"

What are the valid values for dataType and is there a way that they can be converted to the correct type for the database (e.g. string might be varchar(255)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions