tablelandnetwork / react-ts-tableland-template

3 stars 1 forks source link

Non issue, question for inserting rows #1

Closed lsbyerley closed 3 months ago

lsbyerley commented 3 months ago

I already have a table deployed and would like to use this ui to insert rows into the table. I am curious how to add more fields to the insert statement. Does bind() combine the values into a string in the db insert function?

const { meta: write } = await db
          .prepare(`INSERT INTO ${tableName} (name, short_name, conference) VALUES (?);`)
          .bind(writeData)
          .run();
linear[bot] commented 3 months ago

DOC-104 Non issue, question for inserting rows

dtbuchholz commented 3 months ago

@lsbyerley great question, yes, that's correct! these docs should help: here. there are a few different ways to use parameter binding, but the simplest example is ordered binding—e.g., for each ? in your statement, the binded values will replace the ? in order:

const { meta: write } = await db
  .prepare(`INSERT INTO ${tableName} (name, short_name, conference) VALUES (?,?,?);`)
  .bind("data1", "data2", "data3")
  .run();