LoginSignup
44
42

More than 5 years have passed since last update.

SQLをFirebaseで書き換えるためのチート集

Last updated at Posted at 2017-02-15

RDSのデータ構造

スクリーンショット 2017-02-15 23.13.32.png

Firebaseのデータ構造

スクリーンショット 2017-02-15 23.13.44.png

//rootRef points every single piece of data in the database.
const rootRef = firebase.database().ref();

no1.sql
select * from Users where UID = 1;
conts oneRef = rootRef.child('users').child('1');
no1.sql
select * from Users where Email = 'david@hoge.com';
cont twoRef = rootRef.child('users').orderByChild('email').equalTo('alice@email.com');
no2.sql
select * from Users LIMIT 10;
const threeRef = rootRef.child('users').limitTofirst(10);
no3.sql
select * from Users where Name LIKE 'D%';
const fourRef = rootRef.child('users').orderByChild('name').startAt('D').endAt('D\ut8ff');
no4.sql
select * from Users where age < 50;
const fiveRef = rootRef.child('users').orderByChild('age').endAt(49);
no5.sql
select * from Users where age > 50;
const sixRef = rootRef.child('users').orderByChild('age').startAt(51);
no6.sql
select * from Users where age >= 20 $$ age <= 100;
const sevenRef = rootRef.child('users').orderByChild('age').startAt(20).endAt(100);
no7.sql
select * from Users where age = 28 && location = 'Tokyo'
This is NG!!
const eightRef = rootRef.child('users').orderByChild('age').equalTo(28)
                                       .orderByChild('location').equalTo('Berlin');
You should change Data structure of Object..When you use two conditions
const eightRef = rootRef.child('users').orderByChild('age_locatoin').equalTo('28_Tokyo');

参考はこちら

44
42
2

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
44
42