Giter Club home page Giter Club logo

Comments (8)

raschan avatar raschan commented on June 20, 2024 3

Hi @JiawenKor,
I have a similar request. I understand, that I can use any string to describe datatype. Is there any way to define the object shape of such datatype, similarly to Enum?
If not, is it planned?

from dbml.

raschan avatar raschan commented on June 20, 2024 3

Hi @nvquanghuy, certainly.

In our use case, we store a few JSON object in our db, as they can go a few levels deep, and they are mostly configurations, and they are a lot easier to manage as objects.

For example one of the configs:

{
    "timeFrame": { "stop": "11:00", "start": "00:00" },
    "amplifications": [
      {
        "to": 49.6,
        "from": 49.5,
        "coefficient": { "additionValue": 123 },
        "socThreshold": { "maximum": 33, "minimum": 22 }
      },
      {
        "to": 50.5,
        "from": 49.7,
        "coefficient": { "additionValue": 321 },
        "socThreshold": { "maximum": 33, "minimum": 22 }
      }
    ],
    "batteryAdjustment": {
      "deltaStop": 11,
      "deltaStart": 11,
      "socPowerScale": 11
    },
    "unavailabilityMode": { "type": "backcharge", "lower": 40, "upper": 50 }
  }

What I would like to use to describe the shape of the object is something like this:

JSON period_config {
  "timeFrame" time_frame
  "amplifications" amplification [array]
  "batteryAdjustment" battery_adjustment
  "unavailabilityMode" unavailability_mode
}

JSON time_frame { 
  "stop" string [note: 'format: HH:mm']
  "start" string [note: 'format: HH:mm']
}

JSON amplification {
  "to" double
  "from" double
  "coefficient" coefficient
  "socThreshold" soc_threshold
}

JSON coefficient {...}
JSON soc_threshold {...}
JSON battery_adjustment {...}
JSON unavailability_mode {...}

from dbml.

JiawenKor avatar JiawenKor commented on June 20, 2024

Hi @duckontheweb, thanks for your post! You may define any data type, just as long as it is is a single word (remove all spaces in the data type). For instance, geography, JSON, decimal(1,2), custom_1, etc. The data type will still be reflected in your dbdiagram.io column definitions.

image

Just curious, what caused you to have the impression that the data type was unsupported? Are there other ways you were expecting it to be supported?

from dbml.

nvquanghuy avatar nvquanghuy commented on June 20, 2024

Hi @JiawenKor,
I have a similar request. I understand, that I can use any string to describe datatype. Is there any way to define the object shape of such datatype, similarly to Enum?
If not, is it planned?

Hi Raschan I'm not sure what you mean by defining object shape of such data type. Can you elaborate more pls?

from dbml.

mkaatman avatar mkaatman commented on June 20, 2024

@raschan at first look I like your idea, but what's the end result. Is this just for easier definition within the tool? The export is the same right? As far as I know, most databases don't allow you to define the JSON structure beyond saying that the column is JSON data.

from dbml.

PWrzeszczSTH avatar PWrzeszczSTH commented on June 20, 2024

@mkaatman you can define JSON structure in your application DB models. The end result for custom type describing JSON fields would be a schema readability.

Is there any info about this feature?

from dbml.

dan-wu-open avatar dan-wu-open commented on June 20, 2024

Would also like this feature for our NoSQL database

from dbml.

abyrd avatar abyrd commented on June 20, 2024

Hi, thanks for all your work on this project. I love having a simple language to express entity relationships and generate diagrams and documents.

I did notice and appreciate that DBML accepts arbitrary type names. I think the detail that people are missing is that you can't attach notes or other characteristics to the types and reuse them succinctly in many places. If you've got a table like this:

Table stops {
  stop_id id [pk]
  stop_name string [null]
  stop_lat float [not null, note: 'range -90 to 90']
  stop_lon float [not null, note: 'range -180 to 180']
}

We could instead write:

Type id [note: 'alphanumeric, underscores allowed but no other characters']
Type latitude [note: 'floating point, range -90 to 90']
Type longitude [note: 'floating point, range -180 to 180']

Table stops {
  stop_id id [pk]
  stop_name string [null]
  stop_lat latitude [not null]
  stop_lon longitude [not null]
}

or even

Type id [note: 'alphanumeric, underscores allowed but no other characters']
Type latitude [note: 'floating point, range -90 to 90']
Type longitude [note: 'floating point, range -180 to 180']
Type lat_lon {
  lat latitude
  lon longitude
}
Table stops {
  stop_id id [pk]
  stop_name string [null]
  stop_lat_lon lat_lon [not null]
}

This serves no purpose when there's only one reference to the custom type, but if you have 10 tables that all contain latitudes and longitudes and IDs following certain rules, this could factor out tons of notes describing ranges and constraints or structures.

from dbml.

Related Issues (20)

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.