Skip to content

SpaceInvaderTech/typeorm-mui-query

Repository files navigation

MUI TypeORM querybuilder

If you use TypeORM and MUI Data Grid server-side filter or server-side sorting this project can be helpful.

Install

npm install typeorm-mui-query

Example

Frontend

const [queryOptions, setQueryOptions] = useState({
  filterModel: {
    items: [],
  },
  sortModel: [],
})

const handleSortModelChange: DataGridProProps['onSortModelChange'] = useCallback((sortModel) => {
  setQueryOptions((currentState) => ({ ...currentState, sortModel }))
}, [])

const handleFilterModelChange: DataGridProProps['onFilterModelChange'] = useCallback(
  (filterModel) => {
    setQueryOptions((currentState) => ({ ...currentState, filterModel }))
  },
  []
)

const query = new URLSearchParams({
  ...queryOptions,
  sortModel: JSON.stringify(queryOptions.sortModel),
  filterModel: JSON.stringify(queryOptions.filterModel),
})
const results = await API.get('default', `/example?${query.toString()}`, {})

Backend

import { handleQuery } from 'typeorm-mui-query'

handleQuery({ qb, queryStringParameters })
const results = await qb.getMany()