Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WixのVeloでデータベースをいじる

Posted at

WixのVeloでデータベースをいじる

コレクション名 : people
フィールド : name, age

上記のようなコレクションの値を書き換えたい場合

import wixData from 'wix-data'; // wixDataをインポート

export function save(event) {   // 今回は保存ボタンが押されたらデータベースを更新する関数を作る
    wixData.query('people')     // コレクション名を指定してクエリを生成
        .find()                 // 探す
        .then(results => {      // 見つかった場合はresultsを受け取るので、処理する関数を書く
			let items = results.items;              // itemsは1行毎のデータを配列として持っている
			for (let i=0; i < items.length; i++) {  
				let item = items[i];                // 1行分のデータを取得
				item.name = 'tanaka';               // プロパティとして各フィールドにアクセスできる
				item.age = 20;
				wixData.update("people", item);     // wixData.update で内容を変更したitemを渡して反映させる
			}
        })
        .catch(error => {
            console.error(error);
        });
}

出典

Velo:Data API を使用する
https://support.wix.com/ja/article/velo%EF%BC%9Adata-api-%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?