Comments (7)
I solved it by just writing a wrapper dataprovider around it .
from refine-sqlite.
Hello there!
Sorry about that, could you please provide a code snippet showing how you're importing and calling the dataProvider()
function?
from refine-sqlite.
`
<Refine
dataProvider={customDataProvider}
dataProvider.tsx:
import { DataProvider } from "@refinedev/core";
import { dataProvider as sqliteDataProvider } from "refine-sqlite";
import dataProvider from "@refinedev/simple-rest";
const customDataProvider: DataProvider = {
getList: async ({ resource, pagination, sorters, filters, meta }) => {
if (resource === "MessageTemplates") {
const { data, total } = sqliteDataProvider("database.db").getList({
resource,
pagination,
sorters,
filters,
});
return Promise.resolve({ data: data as any[], total });
}
return dataProvider("https://api.example.com").getList({
resource,
pagination,
sorters,
filters,
meta: meta as any,
});
},
getMany: async ({ resource, ids, meta }) => {
if (resource === "MessageTemplates") {
const { data } = sqliteDataProvider("database.db").getMany({
resource,
ids,
});
return Promise.resolve({ data: data as any[] });
}
return dataProvider("https://api.example.com").getMany({
resource,
ids,
meta: meta as any,
});
},
create: async ({ resource, variables, meta }) => {
if (resource === "MessageTemplates") {
const { data } = sqliteDataProvider("database.db").create({
resource,
variables: variables as any,
});
return Promise.resolve({ data: data as any });
}
return dataProvider("https://api.example.com").create({
resource,
variables: variables as any,
meta: meta as any,
});
},
update: async ({ resource, id, variables, meta }) => {
if (resource === "MessageTemplates") {
const { data } = sqliteDataProvider("database.db").update({
resource,
id,
variables: variables as any,
});
return Promise.resolve({ data: data as any });
}
return dataProvider("https://api.example.com").update({
resource,
id,
variables: variables as any,
meta: meta as any,
});
},
deleteOne: async ({ resource, id, meta }) => {
if (resource === "MessageTemplates") {
const { data } = sqliteDataProvider("database.db").getList({
resource,
filters: [{ field: "id", operator: "eq", value: id }],
pagination: { current: 1, pageSize: 1 },
});
sqliteDataProvider("database.db").deleteOne({ resource, id });
return Promise.resolve({ data: data[0] as any });
}
return dataProvider("https://api.example.com").deleteOne({
resource,
id,
meta: meta as any,
});
},
getOne: async ({ resource, id, meta }) => {
if (resource === "MessageTemplates") {
const { data } = sqliteDataProvider("database.db").getList({
resource,
filters: [{ field: "id", operator: "eq", value: id }],
pagination: { current: 1, pageSize: 1 },
});
return Promise.resolve({ data: data[0] as any });
}
return dataProvider("https://api.example.com").getOne({
resource,
id,
meta: meta as any,
});
},
getApiUrl: () => {
return dataProvider("https://api.example.com").getApiUrl();
},
custom: async ({ url, method, filters, sorters, payload, query, headers, meta }) => {
return dataProvider("https://api.example.com").custom({
url,
method,
filters,
sorters,
payload,
query,
headers,
meta: meta as any,
});
},
};
export default customDataProvider;
from refine-sqlite.
I see, the support for client side apps was dropped prior the release of version 1.0
If you're running a plain React template with Vite that could be the cause, I haven't tested yet but I think you could use this provider in React Server Components.
from refine-sqlite.
I see, the support for client side apps was dropped prior the release of version 1.0 If you're running a plain React template with Vite that could be the cause, I haven't tested yet but I think you could use this provider in React Server Components.
Thank you alot !!
from refine-sqlite.
Im using nextjs and i cant add it as an dataprovider . Can you add an example ?
from refine-sqlite.
Im using nextjs and i cant add it as an dataprovider . Can you add an example ?
Sure, I've created a new nextjs project with npm create next-app@latest
then I installed the data provider package, downloaded the test.db database and placed on the root of the project.
It worked on a server component from next-app and should work on refine as well, as long as you run it server-side.
code
import { dataProvider } from "refine-sqlite";
export default function Home() {
const response = dataProvider("test.db")
.getList({ resource: "posts" });
const { data } = response
return (
<div className="p-4">
<table>
<thead>
<tr>
<th>ID</th>
<th>TITLE</th>
<th>CATEGORY ID</th>
</tr>
</thead>
<tbody>
{data.map((entry) => (
<tr key={entry.id}>
<td>{entry.id}</td>
<td>{entry.title}</td>
<td>{entry.category_id}</td>
</tr>
))}
</tbody>
</table>
</div>
);
}
from refine-sqlite.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from refine-sqlite.