Connector for backends created with SQLite.
With refine-sqlite you can quickly start creating your app as fast as possible by leveraging the easy-to-use methods powered by refine to interact with your SQLite database.
- Easy to use - Just import the data provider and use it in your code.
- Lightweight - The SQLite database is lightweight and can be used locally.
- Simple - You won't need to type SQL queries, just use the data provider methods. Except for the tables creation, which you can easily do with the DB Browser for SQLite.
npm install refine-sqlite
First, create a database file. You can use the DB Browser for SQLite to easily create the tables and insert some data, or you can also use the sqlite3 command line shell.
Then, import the data provider to use in an async function, and pass the database file path as a parameter.
Finally, use the methods to create, update, delete, and get data from your database, filtering and sorting as you wish.
Note
resource
is the name of the table in the database.
import { dataProvider } from "refine-sqlite";
async function getPosts() {
const response = await dataProvider("database.db")
.getList({
resource: "posts",
filters: [
{
field: "category_id",
operator: "eq",
value: ["2"],
},
],
sorters: [
{
field: "title",
order: "asc",
},
],
});
const { data } = response;
return data;
}
Using the test.db database file.
{
data: [
{ id: 6, title: 'Dolorem unde et officiis.', category_id: 2 },
{ id: 1, title: 'Soluta et est est.', category_id: 2 }
],
total: 2
}
Method | Description |
---|---|
create() |
Creates a new record. |
update() |
Updates a record. |
deleteOne() |
Deletes a record. |
getOne() |
Gets a single record. |
getList() |
Gets a list of records. |
getMany() |
Gets a list of records by their ids. |
Note Not all the methods have been implemented. See all here.
How to use the methods (Click to expand)
-
create()
create({ resource: "posts", variables: { title: "New post", body: "New post body" } });
-
update()
update({ resource: "posts", id: 1, variables: { title: "Updated post" } });
-
deleteOne()
deleteOne({ resource: "posts", id: 1 });
-
getOne()
getOne({ resource: "posts", id: 3 });
-
getList()
getList({ resource: "posts" });
-
getMany()
getMany({ resource: "posts", ids: [1, 2, 3] });
Filter | Description |
---|---|
eq |
Is equal to |
ne |
Is not equal to |
gte |
Greater than or equal to |
lte |
Less than or equal to |
contains |
Contains |
Note Not all the filters have been implemented. See all here.
How to use the filters (Click to expand)
eq
filters: [{ field: "id", operator: "eq", value: 1 }]
ne
filters: [{ field: "id", operator: "ne", value: 1 }]
gte
filters: [{ field: "id", operator: "gte", value: 1 }]
lte
filters: [{ field: "id", operator: "lte", value: 1 }]
contains
filters: [{ field: "title", operator: "contains", value: "Lorem" }]
Order | Description |
---|---|
asc |
Ascending order |
desc |
Descending order |
How to use the sorters (Click to expand)
asc
sorters: [{ field: "id", order: "asc" }]
desc
sorters: [{ field: "id", order: "desc" }]
Clone the repository
git clone https://github.com/mateusabelli/refine-sqlite.git
Install the dependencies
cd refine-sqlite
pnpm install
Build and test
pnpm run build
pnpm run test
Important Before the tests run, the database file
test.db
is deleted and recreated.
All contributions are welcome and appreciated! Please create an Issue or Pull Request if you encounter any problems or have suggestions for improvements.
If you want to say thank you or/and support active development of refine-sqlite
- Add a GitHub Star to the project.
- Tweet about the project on Twitter / X.
- Write interesting articles about the project on Dev.to, Medium or personal blog.
- Consider becoming a sponsor on GitHub.
refine-sqlite is free and open-source software licensed under the MIT License.
The feather icon is from Phosphor Icons licensed under the MIT License.