Skip to content

Usage in Grasshopper

James Ramsden edited this page Dec 8, 2021 · 2 revisions

Below is a few examples of usage in Grasshopper. This list is far from complete - feel free to add your own!

Firstly, you will need to install SQL Server and Management Tool - see the installation tab.

Then you will need to set up your own database and tables from within the Management Tool - this is not currently possible directly with the SQL toolkit.

General setup

You will usually require two components:

  1. The SqlAdaptor (BH.Adapter.SQL.SqlAdapter.SqlAdapter). The server will usually be set to localhost. The database is the name of the database you created in the Management Tool.
  2. The Execute. This is the general execute method that can be found under BH.Adapter.Execute.

To actually interact with the database, we then need to insert an additional method into the command parameter.

Upsert with custom objects

BHoM components needed:

  1. BH.oM.Adapters.SQL.UpsertCommand
  2. BH.oM.CreateCustom (or your own choice in creating a BHoM CustomObject)
  3. System.Type, then right-click to select the type of your primary key (usually System.int32)

image

Points to note:

  • The keys in the CustomObject items should map to the column names of your database table
  • Avoid column names of id in your database as this can create clashes within CustomObject creation.
Clone this wiki locally