1- import { Converter } from "../src/converter" ;
2- import { test , expect } from "@jest/globals" ;
3- import { complex_ast } from './ast' ;
4- import { cross_join_ast } from './crossjoin' ;
5-
1+ const { Converter} = require ( '../src/converter' ) ;
2+ const { test, expect} = require ( '@jest/globals' ) ;
3+ const { complex_ast} = require ( './ast' ) ;
4+ const { cross_join_ast} = require ( './crossjoin' ) ;
65
76function getQueryBuilder ( ast ) {
87 return ( new Converter ( ast [ 0 ] . Query ) . run ( ) ) ;
@@ -14,12 +13,12 @@ test('complex sql', () => {
1413->leftJoin('comments','comments.post_id','=','posts.id')
1514->rightJoin('users','user.id','=','posts.user_id')
1615->leftJoin(DB::raw("DB::table('address')
17- \t ->select('*')") as a), function($join) {
18- \t $join->on('user.aid','=','a.id');
16+ ->select('*')") as a), function($join) {
17+ $join->on('user.aid','=','a.id');
1918}
2019->where(function ($query) {
21- \t $query->where('a.name','=','bejing')
22- \t\t ->where('a.id','<',10);
20+ $query->where('a.name','=','bejing')
21+ ->where('a.id','<',10);
2322})
2423->where('comments.conent','=','abc')
2524->orderBy('comments.created_at','asc')
@@ -30,9 +29,9 @@ test('complex sql', () => {
3029test ( 'cross join' , ( ) => {
3130 expect ( getQueryBuilder ( cross_join_ast ) ) . toBe ( `DB::table('posts')
3231->crossJoinSub(function ($query) {
33- \t $query->from('posts')
34- \t\t ->select('count', DB::raw("'max'(created_date) as created_date"))
35- \t\t ->groupBy('count');
32+ $query->from('posts')
33+ ->select('count', DB::raw("'max'(created_date) as created_date"))
34+ ->groupBy('count');
3635},'max_counts')
3736->select('posts.*')
3837->where('posts.count','=',DB::raw('max_counts.count'))
0 commit comments