Add

Adding a row.

Adding a row to a table is a two-step process.

Steps

1. Creating a new instance of a database model

new_instance = MyModel(value1, value2, ...)

2. Passing that instance into the db.add() method.

db.add(new_instance)

Example

&basic
db_model Note:
    id = db.col(db.int, db.pk)
    title = db.col(db.str)
    text = db.col(db.str)


@post('/note'):
    if require_keys(['title', 'text'], body):
        status('Please provide all required parameters', 400)
    
    # Creates a new instance of "Note"
    new_note = Note(boy['title'], body['text'])
    db.add(new_note)
    
    respond(new_note.s())

Last updated