https://github.com/alenap93/kysely-hash
Hash plugin for Kysely
https://github.com/alenap93/kysely-hash
Last synced: 7 months ago
JSON representation
Hash plugin for Kysely
- Host: GitHub
- URL: https://github.com/alenap93/kysely-hash
- Owner: alenap93
- License: mit
- Created: 2025-02-03T10:09:22.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-04-05T06:42:01.000Z (7 months ago)
- Last Synced: 2025-04-05T07:27:33.667Z (7 months ago)
- Language: TypeScript
- Size: 270 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-kysely - kysely-hash - Hash plugin for [Kysely](https://kysely.dev).   (Plugins)
README
# kysely-hash
[](https://github.com/alenap93/kysely-hash/actions/workflows/test.yml)
[](https://www.npmjs.com/package/kysely-hash)
[](https://www.npmjs.com/package/kysely-hash)
[](https://prettier.io/)
Hash plugin for kysely fully typed, developed for Node.js but also runs on Deno and Bun; with this plugin you can hash fields using crypto-js library.
## Install
```
npm i kysely kysely-hash
```
## Usage
**Options**
* fieldsToDecrypt: *field to hash during insert and update, or in '=' and '!=' where condition (use alias if it is used)*
* hashAlgorithm: *hash algorithm*
**How to use**
***WARNING: fields must be of string types***
const kyselyInstance = new Kysely({
dialect: new SqliteDialect({
database: new Database(':memory:'),
}),
})
await kyselyInstance.schema
.createTable('person')
.ifNotExists()
.addColumn('id', 'integer', (col) => col.primaryKey())
.addColumn('first_name', 'varchar(255)')
.addColumn('last_name', 'varchar(255)')
.addColumn('gender', 'varchar(255)')
.execute()
await kyselyInstance
.insertInto('person')
.values([
{
first_name: 'Max',
last_name: 'Jack',
gender: 'man',
},
{
first_name: 'George',
last_name: 'Rossi',
gender: 'man',
},
])
.withPlugin(
new KyselyHashPlugin({
fieldsToHash: ['last_name'],
hashAlgorithm: 'SHA256',
}),
)
.execute()
## License
Licensed under [MIT](./LICENSE).