4.2.0 • Published 3 years ago

@jolocom/sdk-storage-typeorm v4.2.0

Weekly downloads
78
License
MIT
Repository
github
Last release
3 years ago

npm package @jolocom/sdk-storage-typeorm chat on gitter

@jolocom/sdk-storage-typeorm

A Typeorm storage backend for jolocom-sdk

Usage

In your ormconfig.ts you need to add the jolocom-sdk entities to your entities config option. Here's a full example typeorm config file:

export default {
  type: 'sqlite',
  database: './db.sqlite3',
  logging: ['error', 'warn', 'schema'],
  entities: [ 'node_modules/@jolocom/sdk-storage-typeorm/js/src/entities/*.js' ],
  /** or if you list entity classes, then simply add the SDK entities
  entities: [
    // your entities here
    // then
    ...require('@jolocom/sdk-storage-typeorm').entityList
  ],
  */

  // migrations are recommended!
  migrations: ['./migrations/*.ts'],
  migrationsRun: true,
  synchronize: false,
  cli: {
    migrationsDir: './migrations',
  },
}

Then you need to generate migrations, for example using

yarn run typeorm migration:generate -n JolocomSDK

If you have { migrationsRun: true } in your ormconfig.ts as in the above example, then the migration will automatically be run when you start the app next. Otherwise you have to run it manually

Next, in your application, instantiate the storage module with a typeorm connection, then pass it to the JolocomSDK constrcutor

Full app example:

const typeorm = require('typeorm')
const { JolocomTypeormStorage } = require('@jolocom/sdk-storage-typeorm')
const { JolocomSDK } = require('jolocom-sdk')
const typeormConfig = require('./ormconfig')

async function init() {
  const typeormConnection = await typeorm.createConnection(typeormConfig)
  const storage = new JolocomTypeormStorage(typeormConnection)

  console.log('about to create SDK instance')
  const sdk = new JolocomSDK({ storage })

  // Running sdk.init() with no arguments will:
  // - create an identity if it doesn't exist
  // - load the identity from storage
  const identityWallet = await sdk.init()
  console.log('Agent identity', identityWallet.identity)
}

init()
5.0.0-rc0

3 years ago

4.3.0-rc0

3 years ago

4.2.0

3 years ago

4.1.0

3 years ago

4.1.0-rc0

3 years ago

4.0.0

3 years ago

4.0.0-rc2

4 years ago

4.0.0-rc1

4 years ago

3.0.0

4 years ago

2.0.11

4 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago