Giter Site home page Giter Site logo

mateusabelli / refine-sqlite Goto Github PK

View Code? Open in Web Editor NEW
18.0 1.0 0.0 383 KB

Connector for backends created with SQLite.

Home Page: https://www.npmjs.com/package/refine-sqlite

License: MIT License

JavaScript 1.07% TypeScript 98.93%
data-provider refine sqlite typescript refine-framework npm connector

refine-sqlite's Introduction

refine-sqlite

Connector for backends created with SQLite.

npm version npm GitHub license Node.js CI


Getting Started

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.

Features

  • Well tested - All the methods are tested using Jest.
  • Fully featured - All CRUD operations are supported.
  • Synchronous - Everything works synchronously using better-sqlite3.
  • Type safe - Written in TypeScript with strict mode enabled.

Installation

npm install refine-sqlite

Usage

  1. 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.
  2. Import the dataProvider function in your file and pass the database file path as a string parameter.
  3. 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";

const response = dataProvider("database.db")
  .getList({
    resource: "posts",
    filters: [
      {
        field: "category_id",
        operator: "eq",
        value: ["2"],
      },
    ],
    sorters: [
      {
        field: "title",
        order: "asc",
      },
    ],
  });

console.log(response)

// {
//   data: [
//     { id: 6, title: 'Dolorem unde et officiis.', category_id: 2 },
//     { id: 1, title: 'Soluta et est est.', category_id: 2 }
//   ],
//   total: 2
// }

Documentation

Development

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.

Contributing

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

Special Thanks

refine

I'd like to thank refine, my first GitHub sponsor ❤️
For believing and supporting my projects!

License

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.

refine-sqlite's People

Contributors

mateusabelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

refine-sqlite's Issues

promisify is not a function

Uncaught TypeError: promisify is not a function
at node_modules/better-sqlite3/lib/methods/backup.js (refine-sqlite.js?v=e0b491c1:423:20)
at __require2 (chunk-AUZ3RYOM.js?v=47f26262:18:50)
at node_modules/better-sqlite3/lib/database.js (refine-sqlite.js?v=e0b491c1:842:33)
at __require2 (chunk-AUZ3RYOM.js?v=47f26262:18:50)
at node_modules/better-sqlite3/lib/index.js (refine-sqlite.js?v=e0b491c1:861:22)
at __require2 (chunk-AUZ3RYOM.js?v=47f26262:18:50)
at refine-sqlite.js?v=e0b491c1:867:37
When adding it as an dataprovider

Error when using the package

When I updated my data provider according to the README on a newly created refine app using Vite I received the following error

X [ERROR] Could not resolve "mock-aws-s3"

    node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:43:28:
      43 │     const AWSMock = require('mock-aws-s3');
         ╵                             ~~~~~~~~~~~~~

  You can mark the path "mock-aws-s3" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at 
run-time instead of bundle-time.

X [ERROR] Could not resolve "aws-sdk"

    node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:76:22:
      76 │   const AWS = require('aws-sdk');
         ╵                       ~~~~~~~~~

  You can mark the path "aws-sdk" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-
time instead of bundle-time.

X [ERROR] Could not resolve "nock"

    node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:112:23:
      112 │   const nock = require('nock');
          ╵                        ~~~~~~

  You can mark the path "nock" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-tim
e instead of bundle-time.

sqlite3 over better-sqlite3

Hello Mateus.

I think it's great that there is finally a way to connect refine and sqlite. Thank you very much for that. But i´ve got a question.
Why have you choosen sqlite3 instead of better-sqlite3?

What was your motivation for this?

Thx a lot
Thomas

Add examples

Include a folder with an example refine project using the refine-sqlite as a data provider

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.