Skip to content

Update by id

Structure

Update by id
let updateById = await g.sys.db.gen.updateByIdGen({
    instance: "INSTANCE_NAME",
    database: "DATABASE_NAME",
    collection: "COLLECTION_NAME",
    id: 1008,
    primaryKey: "id",
    updateData: {
        "first_name": "Tanmay",
        "last_name": "Samay"
    },
    returnOriginal: true,
    select: "COLUMN_NAMES",
    upsert: false
});

Simple updateById

Update By Id
1
2
3
4
5
6
7
8
9
let updateById = await g.sys.db.gen.updateByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: 1,
    updateData: {
        "first_name": "MALLORY"
    }
});

updateById primaryKey override

Update By Id primarykey override
let updateById = await g.sys.db.gen.updateByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: "Alice",
    primaryKey: "first_name",
    updateData: {
        "first_name": "MALLORY"
    }
});

updateById [select]

Update By Id with select
let updateById = await g.sys.db.gen.updateByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: "Alice",
    primaryKey: "first_name",
    updateData: {
        "first_name": "MALLORY"
    },
    select: "first_name,last_name"
});

updateById [headers]

Update By Id with select
let updateById = await g.sys.db.gen.updateByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: "Alice",
    primaryKey: "first_name",
    updateData: {
        "first_name": "MALLORY"
    },
    select: "first_name,last_name",
    headers: {
        "x-am-response-case": "capitalCase"
    }
});

updateById [upsert]

Update By Id with upsert
let updateById = await g.sys.db.gen.updateByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: "Alice",
    primaryKey: "first_name",
    updateData: {
        "first_name": "MALLORY"
    },
    select: "first_name,last_name",
    headers: {
        "x-am-response-case": "capitalCase"
    },
    upsert: true
});

updateById [returnDocument]

Update By Id with upsert
let updateById = await g.sys.db.gen.updateByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: "Alice",
    primaryKey: "first_name",
    updateData: {
        "first_name": "MALLORY"
    },
    select: "first_name,last_name",
    headers: {
        "x-am-response-case": "capitalCase"
    },
    returnDocument: true 
});