Trong ORM - build reactive interfaces on top of SQLite #55
quolpr
started this conversation in
Show and tell
Replies: 1 comment
-
Here is the quick example: import {
desc,
like$,
select,
} from "@trong-orm/query-builder";
import {
makeId,
sql,
useQuery,
useRunQuery,
} from "@trong-orm/react";
import { useState } from "react";
const notesTable = sql.table("notes");
export const List = () => {
const [textToSearch, setTextToSearch] = useState<string>("");
const { data: recordsData } = useQuery<{
id: string;
title: string;
content: string;
createdAt: number;
}>(
select()
.from(notesTable)
.where(
textToSearch ? { content: like$("%" + textToSearch + "%") } : sql.empty
)
.orderBy(desc("createdAt"))
);
return (
<>
<input
value={textToSearch}
onChange={(e) => {
setTextToSearch(e.target.value);
}}
placeholder="Search content"
/>
<br />
{recordsData.map(({ title, content, id, createdAt }) => (
<div key={id}>
<h1>{title}</h1>
<div>Created at: {new Date(createdAt).toISOString()}</div>
<br />
<div>Content: {content}</div>
</div>
))}
</>
);
}; Any changes made to Also, you can play at sandbox: https://codesandbox.io/s/react-trong-example-q0e9iu |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I hope it's ok that I promote my lib 😅
When I was using absurd-sql I was missing a lib, that bring reactivity, gives support on any platform and has a decent query builder. And I decided to build a lib on top of the absurd-sql — https://github.com/trong-orm/trong-orm .
Right now it already supports Tauri, web, expo(react-native) and electron. It also has React hooks integration, and I plan to add Vue, AngularJS support in the future.
I hope you will like it 🙂
Beta Was this translation helpful? Give feedback.
All reactions